Skip to main content
The style rule file enforces consistent formatting and naming conventions across a codebase. These rules make code easier to read and review by eliminating stylistic variation. Source: eslint-config-airbnb-base/rules/style

Indentation and whitespace

Severity: error (2 spaces)All code must use 2-space indentation. switch case clauses are indented one level from the switch keyword. JSX nodes are excluded from this rule (handled separately by react/jsx-indent).
// Good
function greet(name) {
  if (name) {
    return `Hello, ${name}`;
  }
  return 'Hello';
}
Severity: errorTabs are not allowed anywhere in the source code. Use spaces only.
Severity: errorLines must not end with whitespace characters. This applies to blank lines and comment lines.
Severity: error (max: 1)At most one consecutive blank line is allowed within a file. No blank lines are allowed at the beginning or end of a file.
Severity: errorFiles must end with a newline character, following POSIX convention and avoiding noisy diffs.
Severity: errorOnly \n (LF) line endings are allowed. CRLF (\r\n) line endings are rejected. Configure your editor and Git to use LF on all platforms.

Quotes and semicolons

Severity: errorString literals must use single quotes. Double quotes are allowed when the string contains a single quote to avoid escaping.
// Good
const name = 'Alice';
const message = "It's fine to use double quotes here";
Severity: errorStatements must end with a semicolon. The rule relies on semi-style: last, so semicolons belong at the end of a line, not the beginning.
// Good
const x = 1;
doSomething();
Severity: off (base); error in React configJSX attribute values must use double quotes. This is enabled by the eslint-config-airbnb React rule set.
// Good
<Component className="foo" />

Naming conventions

Severity: errorVariable and function names must use camelCase. Object property names are exempt (properties: 'never'). Destructured variables are not required to be renamed.
// Bad
const my_variable = 1;

// Good
const myVariable = 1;
Severity: errorConstructor functions and classes called with new must start with a capital letter. Functions starting with a capital letter must be called with new. Exceptions: Immutable.Map, Immutable.Set, Immutable.List.
Severity: errorIdentifiers must not start or end with underscores. This convention suggests private members, which JavaScript now handles with #private fields.

Commas and object literals

Severity: error (always-multiline)Trailing commas are required in multiline arrays, objects, imports, exports, and function parameters. Single-line literals do not require trailing commas.
// Good
const obj = {
  a: 1,
  b: 2,
};

const arr = [
  'one',
  'two',
];
Severity: errorCommas must appear at the end of the line, not at the beginning.
// Bad
const obj = {
    a: 1
  , b: 2
};

// Good
const obj = {
  a: 1,
  b: 2,
};
Severity: error (always)Object literals and destructuring patterns must have spaces after { and before }.
// Bad
const {a, b} = obj;

// Good
const { a, b } = obj;
Severity: error (as-needed)Object property keys must not be quoted unless they are not valid identifiers (e.g., reserved words or hyphenated strings).
// Bad
const obj = { 'foo': 1 };

// Good
const obj = { foo: 1, 'kebab-case': 2 };

Line length and line breaks

Severity: error (100 characters, tab width: 2)Lines must not exceed 100 characters. URLs, regular expression literals, strings, and template literals are exempt from this limit. Comments are not exempt.
Severity: error (depth: 4)Method chains deeper than 4 must have each call on its own line.
// Good — chain depth ≤ 4
foo.bar().baz().qux();

// Good — chain depth > 4, broken across lines
foo
  .bar()
  .baz()
  .qux()
  .quux();
Severity: error (multiline-arguments)If any argument in a function call spans multiple lines, all arguments must each be on their own line.

Control flow and operators

Severity: errorNested ternaries are difficult to read. Extract them into variables or if statements.
// Bad
const result = a ? b ? c : d : e;

// Good
const inner = b ? c : d;
const result = a ? inner : e;
Severity: errorMixing operators of different precedence groups without parentheses makes evaluation order unclear. Use explicit parentheses.
// Bad
const x = a + b * c;

// Good
const x = a + (b * c);
Severity: errorThe ++ and -- unary operators interact with automatic semicolon insertion in non-obvious ways. Use += 1 and -= 1 instead.
Severity: errorThe following syntax forms are banned:
SyntaxReason
for...inIterates the prototype chain; use Object.keys/values/entries
for...ofRequires regenerator-runtime; prefer array iteration methods
Labeled statementsHard to maintain; essentially GOTO
with statementMakes code unpredictable; disallowed in strict mode
Severity: error
// Bad
Math.pow(2, 10);

// Good
2 ** 10;

Variable declarations

Severity: error (never)Each variable must be declared in its own statement rather than grouping multiple declarations with commas.
// Bad
let a, b, c;

// Good
let a;
let b;
let c;
Severity: error
// Bad
const merged = Object.assign({}, defaults, options);

// Good
const merged = { ...defaults, ...options };

Build docs developers (and LLMs) love