Recipes
- Disallow awaiting non-promise values.
- Disallow classes that only have static members.
- Disallow comparing
undefined
using typeof
.
- Disallow else blocks after return statements in if statements
- Disallow equal signs explicitly at the beginning of regular expressions
- Disallow if statements as the only statement in else blocks
- Disallow initializing variables to undefined
- Disallow member access from
await
expression.
- Disallow negated conditions.
- Disallow nested ternary expressions.
- Disallow
new Array()
.
- Disallow number literals with zero fractions or dangling dots.
- Disallow
parseInt()
and Number.parseInt()
in favor of binary, octal, and hexadecimal literals
- Disallow redundant return statements
- Disallow renaming import, export, and destructured assignments to the same name
- Disallow returning/yielding
Promise.resolve()
/reject()
in async
functions or promise callbacks.
- Disallow shorthand type conversions
- Disallow ternary operators when simpler alternatives exist
- Disallow the use of
Math.pow
in favor of the ** operator
- Disallow the use of the
null
literal.
- Disallow unnecessary calls to
.bind()
- Disallow unnecessary computed property keys in objects and classes
- Disallow unnecessary labels
- Disallow unnecessary spread.
- Disallow unreadable array destructuring.
- Disallow use of
Object.prototype.hasOwnProperty.call()
and prefer use of Object.hasOwn(
)
- Disallow useless array
length
check.
- Disallow useless fallback when spreading in object literals.
- Disallow useless
undefined
.
- Disallow using
Object.assign
with an object literal as the first argument and prefer the use of object spread instead
- Disallow using the
this
argument in array methods.
- Do not use a
for
loop that can be replaced with a for-of
loop.
- Do not use leading/trailing space between
console.log
parameters.
- Enforce a convention in module import order
- Enforce a newline after import statements
- Enforce a particular style for multiline comments
- Enforce a specific parameter name in catch clauses.
- Enforce better string content.
- Enforce combining multiple
Array#push()
into one call.
- Enforce consistent brace style for all control statements
- Enforce consistent brace style for case clauses.
- Enforce consistent case for text encoding identifiers.
- Enforce consistent relative URL style.
- Enforce correct
Error
subclassing.
- Enforce dot notation whenever possible
- Enforce explicitly comparing the length or size property of a value.
- Enforce no spaces between braces.
- Enforce or ban the use of inline type-only markers for named imports
- Enforce or disallow capitalization of the first letter of a comment
- Enforce proper case for numeric literals.
- Enforce sorted import declarations within modules
- Enforce the style of numeric separators by correctly grouping digits.
- Enforce the use of
Buffer.from()
and Buffer.alloc()
instead of the deprecated new Buffer()
.
- Enforce the use of
Math.trunc()
instead of bitwise operators.
- Enforce the use of Unicode escapes instead of hexadecimal escapes.
- Enforce the use of
new
for all builtins, except String
, Number
, Boolean
, Symbol
, and BigInt
.
- Enforce throwing
TypeError
in type checking conditions.
- Enforce using the digits argument with
Number#toFixed()
.
- Enforce using the separator argument with
Array#join()
.
- Enforce variables to be declared either together or separately in functions
- Ensure all imports appear before other statements
- Fix whitespace-insensitive template indentation.
- Forbid empty named import
- Forbid import of modules using absolute paths
- Forbid import statements with CommonJS module.exports
- Forbid importing packages through relative paths
- Forbid namespace (a.k.a. "wildcard"
*
) imports.
- Forbid repeated import of the same module in multiple places
- Forbid unnecessary path segments in import and require statements
- Improve regexes by making them shorter, consistent, and safer.
- Prefer
.addEventListener()
and .removeEventListener()
over on-functions.
- Prefer
.at()
method for index access and String#charAt()
.
- Prefer
.before()
over .insertBefore()
, .replaceWith()
over .replaceChild()
, prefer one of .before()
, .after()
, .append()
or .prepend()
over insertAdjacentText()
and insertAdjacentElement()
.
- Prefer
.find()
and .findLast()
over the first or last element from .filter()
.
- Prefer
.flatMap()
over .map().flat()
.
- Prefer
.includes()
over .indexOf()
and Array#some()
when checking for existence or non-existence.
- Prefer
.querySelector()
over .getElementById()
, .querySelectorAll()
over .getElementsByClassName()
and .getElementsByTagName()
.
- Prefer
.some()
over .filter().length
check and .{find,findLast}()
.
- Prefer
Array#flat()
over legacy techniques to flatten arrays.
- Prefer
Array#{indexOf,lastIndexOf}()
over Array#{findIndex,findLastIndex}()
when looking for the index of an item.
- Prefer
Date.now()
to get the number of milliseconds since the Unix Epoch.
- Prefer JavaScript modules (ESM) over CommonJS.
- Prefer
KeyboardEvent#key
over KeyboardEvent#keyCode
.
- Prefer
Node#append()
over Node#appendChild()
.
- Prefer
Number
static properties over global ones.
- Prefer
Reflect.apply()
over Function#apply()
.
- Prefer
RegExp#test()
over String#match()
and RegExp#exec()
.
- Prefer
Set#has()
over Array#includes()
when checking for existence or non-existence.
- Prefer
String#replaceAll()
over regex searches with the global flag.
- Prefer
String#slice()
over String#substr()
and String#substring()
.
- Prefer
String#startsWith()
& String#endsWith()
over RegExp#test()
.
- Prefer
String#trimStart()
/ String#trimEnd()
over String#trimLeft()
/ String#trimRight()
.
- Prefer borrowing methods from the prototype instead of the instance.
- Prefer
childNode.remove()
over parentNode.removeChild(childNode)
.
- Prefer default parameters over reassignment.
- Prefer
export…from
when re-exporting.
- Prefer
for…of
over the forEach
method.
- Prefer modern Math APIs over legacy patterns.
- Prefer negative index over
.length - index
when possible.
- Prefer omitting the catch binding parameter.
- Prefer reading a JSON file as a buffer.
- Prefer
switch
over multiple else-if
.
- Prefer ternary expressions over simple
if-else
statements.
- Prefer the spread operator over
Array.from()
, Array#concat()
, Array#{slice,toSpliced}()
and String#split('')
.
- Prefer using
.dataset
on DOM elements over calling attribute methods.
- Prefer using
Object.fromEntries()
to transform a list of key-value pairs into an object.
- Prefer using
Set#size
instead of Array#length
.
- Prefer using
String
, Number
, BigInt
, Boolean
, and Symbol
directly.
- Prefer using the
node:
protocol when importing Node.js builtin modules.
- Prevent abbreviations.
- Require
Array.isArray()
instead of instanceof Array
.
- Require braces around arrow function bodies
- Require const declarations for variables that are never reassigned after declared
- Require destructuring from arrays and/or objects
- Require escape sequences to use uppercase values.
- Require
let
or const
instead of var
- Require
new
when throwing an error.
- Require or disallow "Yoda" conditions
- Require or disallow Unicode byte order mark (BOM)
- Require or disallow assignment operator shorthand where possible
- Require or disallow logical assignment operator shorthand
- Require or disallow method and property shorthand syntax for object literals
- Require or disallow strict mode directives
- Require template literals instead of string concatenation
- Require the use of
===
and !==
- Require using arrow functions for callbacks
- Require variables within the same declaration block to be sorted
- Use destructured variables over properties.