eslint-config-airbnb-base/rules/best-practices
Equality and type safety
eqeqeq — require === and !==
eqeqeq — require === and !==
=== and !==) everywhere. The null case is excluded to allow value == null as a shorthand for value === null || value === undefined.no-self-compare — disallow comparing a value to itself
no-self-compare — disallow comparing a value to itself
Function and class patterns
no-param-reassign — disallow reassigning function parameters
no-param-reassign — disallow reassigning function parameters
acc/accumulator— reduce accumulatorse— event return valuesctx/context— Koa routingreq/request— Express requestsres/response— Express responses$scope— Angular 1 scopesstaticContext— ReactRouter context
class-methods-use-this — require class methods to use this
class-methods-use-this — require class methods to use this
this should be static methods or standalone functions.no-constructor-return — disallow returning a value in constructors
no-constructor-return — disallow returning a value in constructors
max-classes-per-file — limit one class per file
max-classes-per-file — limit one class per file
Dangerous and deprecated features
no-eval — disallow eval()
no-eval — disallow eval()
eval() executes arbitrary code, creates security vulnerabilities, and prevents engine optimizations.no-implied-eval — disallow eval()-like methods
no-implied-eval — disallow eval()-like methods
setTimeout, setInterval, and execScript, which behave like eval.no-new-func — disallow the Function constructor
no-new-func — disallow the Function constructor
new Function(string) is essentially eval and carries the same risks.no-proto — disallow __proto__
no-proto — disallow __proto__
__proto__ is a deprecated way to access an object’s prototype. Use Object.getPrototypeOf() instead.no-extend-native — disallow extending native prototypes
no-extend-native — disallow extending native prototypes
Array.prototype can break other code unexpectedly.no-script-url — disallow javascript: URLs
no-script-url — disallow javascript: URLs
javascript: URLs evaluate code in the page context, creating a cross-site scripting vector.Code structure
consistent-return — require return statements to always or never specify a value
consistent-return — require return statements to always or never specify a value
undefined). Inconsistent returns make code harder to reason about.default-case — require default in switch statements
default-case — require default in switch statements
default clause. Use a // no default comment to explicitly opt out.guard-for-in — require if in for-in loops
guard-for-in — require if in for-in loops
for...in loops iterate over the full prototype chain. An if check (hasOwnProperty) prevents processing inherited properties.no-else-return — disallow else after return
no-else-return — disallow else after return
return, an else block is unnecessary and adds indentation.no-lone-blocks — disallow unnecessary nested blocks
no-lone-blocks — disallow unnecessary nested blocks
vars-on-top — require var declarations at the top of scope
vars-on-top — require var declarations at the top of scope
var declarations are hoisted, declaring them at the top of their scope makes the hoisting behavior explicit.Expressions and statements
no-unused-expressions — disallow side-effect-free expressions
no-unused-expressions — disallow side-effect-free expressions
a && b without using the result) is most likely a bug. Short-circuit evaluation, ternaries, and tagged template literals are not allowed as statements.no-sequences — disallow the comma operator
no-sequences — disallow the comma operator
no-throw-literal — restrict what can be thrown
no-throw-literal — restrict what can be thrown
Error objects (or subclasses) should be thrown so that consumers can rely on stack traces and .message.no-return-assign — disallow assignment in return statements
no-return-assign — disallow assignment in return statements
return statement is almost always a typo for ===.no-return-await — disallow redundant return await
no-return-await — disallow redundant return await
return await promise in an async function is redundant because the outer function already awaits the returned promise. Removing await avoids an unnecessary microtask tick and simplifies stack traces.Restricted properties
The config bans several legacy or unsafe property accesses:| Access | Replacement |
|---|---|
arguments.callee | Deprecated; use named functions |
global.isFinite / window.isFinite | Number.isFinite |
global.isNaN / window.isNaN | Number.isNaN |
obj.__defineGetter__ | Object.defineProperty |
obj.__defineSetter__ | Object.defineProperty |
Math.pow | ** exponentiation operator |
Async patterns
prefer-promise-reject-errors — use Error objects for Promise rejections
prefer-promise-reject-errors — use Error objects for Promise rejections
Error instances so that consumers have access to stack traces. Empty rejections (Promise.reject()) are allowed.