ESLint configuration that matches Facebook's internal ESLint rules for JavaScript projects
npx @tessl/cli install tessl/npm-eslint-config-fbjs@4.0.0ESLint Config FBJS provides ESLint configuration rules that closely match Facebook's internal JavaScript coding standards. It offers comprehensive linting rules covering possible errors, best practices, stylistic issues, ECMAScript 6 features, React/JSX patterns, and accessibility checks for JavaScript and TypeScript projects.
npm install --save-dev eslint-config-fbjsnpm install --save-dev hermes-eslint@">=0.8.0" eslint@"^8.0.0" eslint-plugin-babel@"^5.3.1" eslint-plugin-ft-flow@"^2.0.1" eslint-plugin-jsx-a11y@"^6.6.0" eslint-plugin-react@"^7.30.1"The package is designed to be used primarily through ESLint's configuration system:
.eslintrc.json:
{
"extends": "fbjs"
}.eslintrc.js:
module.exports = {
extends: 'fbjs'
};For programmatic access:
const config = require('eslint-config-fbjs');Add the Facebook ESLint configuration to your project:
{
"extends": "fbjs"
}This provides the complete Facebook-style ESLint configuration with warnings for style issues and errors for critical problems.
For projects requiring all warnings to be treated as errors:
{
"extends": "fbjs/strict"
}This is useful in CI environments where warnings should cause build failures.
The primary ESLint configuration that matches Facebook's internal coding standards. The export is the result of merging a base configuration with open-source specific overrides.
/**
* Complete ESLint configuration object matching Facebook's internal standards
* Created by merging base configuration with extended configuration for open source
* Includes parser settings, plugins, rules, and environment configurations
*/
const config: ESLintConfig;
interface ESLintConfig {
parser: string;
parserOptions: ParserOptions;
plugins: string[];
rules: Rules;
env: Environment;
globals: Globals;
}
interface ParserOptions {
ecmaVersion: number;
sourceType: 'module' | 'script';
}
interface Rules {
[ruleName: string]: RuleConfig;
}
type RuleConfig = 0 | 1 | 2 | 'off' | 'warn' | 'error' | [0 | 1 | 2 | 'off' | 'warn' | 'error', ...any[]];
interface Environment {
browser?: boolean;
es6?: boolean;
node?: boolean;
jest?: boolean;
jasmine?: boolean;
}
interface Globals {
[globalName: string]: boolean;
}Usage:
// Direct import for programmatic use
const eslintConfig = require('eslint-config-fbjs');
// Standard ESLint configuration usage
module.exports = {
extends: 'fbjs'
};A strict version of the main configuration that converts all warnings to errors.
/**
* Strict ESLint configuration where all warnings become errors
* Built using the main configuration with modified error levels
*/
const strictConfig: ESLintConfig;Usage:
// Direct import for programmatic use
const strictConfig = require('eslint-config-fbjs/strict');
// ESLint configuration usage
module.exports = {
extends: 'fbjs/strict'
};Shared utilities and configurations used across different configuration files.
/**
* Shared configuration utilities and global definitions
* Actual export: { globals: globals, maxLenIgnorePattern: maxLenIgnorePattern }
*/
const shared: {
globals: Globals;
maxLenIgnorePattern: string;
};
interface Globals {
/** Facebook-specific development flag */
__DEV__: boolean;
/** Haste module system globals */
require: boolean;
requireDynamic: boolean;
requireLazy: boolean;
/** Flow React type definitions */
ReactComponent: boolean;
ReactClass: boolean;
ReactElement: boolean;
ReactPropsCheckType: boolean;
ReactPropsChainableTypeChecker: boolean;
ReactPropTypes: boolean;
SyntheticEvent: boolean;
SyntheticClipboardEvent: boolean;
SyntheticCompositionEvent: boolean;
SyntheticInputEvent: boolean;
SyntheticUIEvent: boolean;
SyntheticFocusEvent: boolean;
SyntheticKeyboardEvent: boolean;
SyntheticMouseEvent: boolean;
SyntheticDragEvent: boolean;
SyntheticWheelEvent: boolean;
SyntheticTouchEvent: boolean;
/** Flow utility types */
$Either: boolean;
$All: boolean;
$Tuple: boolean;
$Supertype: boolean;
$Subtype: boolean;
$Shape: boolean;
$Diff: boolean;
$Keys: boolean;
$Enum: boolean;
$Exports: boolean;
Class: boolean;
function: boolean;
Iterable: boolean;
/** Flow suppress types */
$FlowIssue: boolean;
$FlowFixMe: boolean;
$FixMe: boolean;
/** Flow core definitions */
Iterator: boolean;
IteratorResult: boolean;
$await: boolean;
ArrayBufferView: boolean;
/** Flow Facebook definitions */
FbtResult: boolean;
$jsx: boolean;
FBID: boolean;
AdAccountID: boolean;
UID: boolean;
ReactNode: boolean;
Fbt: boolean;
/** LiveRail definitions */
LRID: boolean;
/** PowerEditor definitions */
UkiAccount: boolean;
UkiAdgroup: boolean;
UkiCampaign: boolean;
UkiCampaignGroup: boolean;
/** WebRTC type definitions */
RTCConfiguration: boolean;
RTCIceServer: boolean;
RTCOfferOptions: boolean;
RTCStatsReport: boolean;
RTCStatsCallback: boolean;
RTCPeerConnection: boolean;
RTCPeerConnectionErrorCallback: boolean;
RTCSessionDescription: boolean;
RTCSessionDescriptionInit: boolean;
RTCSessionDescriptionCallback: boolean;
RTCIceCandidate: boolean;
RTCIceCandidateInit: boolean;
RTCPeerConnectionIceEvent: boolean;
RTCPeerConnectionIceEventInit: boolean;
RTCDataChannel: boolean;
RTCDataChannelInit: boolean;
RTCDataChannelEvent: boolean;
RTCDataChannelEventInit: boolean;
}Usage:
const shared = require('eslint-config-fbjs/shared');
// Access global definitions (object with boolean flags for each global)
const globals = shared.globals;
// Access max-length ignore pattern (regex string for require/import statements)
const maxLenPattern = shared.maxLenIgnorePattern;Utility function to modify error levels of ESLint rules in configuration objects.
/**
* Changes the error level of all enabled rules in an ESLint configuration
* Creates a deep clone of the config to avoid mutation
* Skips rules that are already 'off' (0 or 'off')
* Handles both array-format rules and simple value rules
* @param config - ESLint configuration object to modify
* @param level - New error level (0=off, 1=warning, 2=error)
* @returns Deep-cloned configuration with modified error levels
*/
function changeErrorLevel(config: ESLintConfig, level: 0 | 1 | 2): ESLintConfig;
/**
* Helper function to check if a rule is disabled
* @param rule - Rule value to check (can be number, string, or array)
* @returns true if rule is disabled (0 or 'off')
*/
function isOff(rule: RuleConfig): boolean;Usage:
const changeErrorLevel = require('eslint-config-fbjs/utils/change-error-level');
const baseConfig = require('eslint-config-fbjs');
// Convert all warnings to errors
const strictConfig = changeErrorLevel(baseConfig, 2);
// Convert all errors to warnings
const lenientConfig = changeErrorLevel(baseConfig, 1);The configuration includes support for these ESLint plugins:
The configuration includes over 550 ESLint rules across these categories:
The main configuration includes both base and extended environments:
Base Environments:
Extended Environments (for open source projects):
The implementation uses these internal constants:
const OFF = 0; // Rule disabled
const WARNING = 1; // Rule generates warnings
const ERROR = 2; // Rule generates errors
const INDENT_SIZE = 2; // Standard indentation sizeinterface ESLintConfig {
/** JavaScript parser to use (hermes-eslint) */
parser: string;
/** Parser configuration options */
parserOptions: {
ecmaVersion: number;
sourceType: 'module' | 'script';
};
/** ESLint plugins to load */
plugins: string[];
/** Linting rules configuration */
rules: {
[ruleName: string]: 0 | 1 | 2 | 'off' | 'warn' | 'error' | [0 | 1 | 2 | 'off' | 'warn' | 'error', ...any[]];
};
/** JavaScript environments to enable */
env: {
browser?: boolean;
es6?: boolean;
node?: boolean;
jest?: boolean;
jasmine?: boolean;
};
/** Global variables available in the code */
globals: {
[globalName: string]: boolean;
};
}