Javascript
Recipes
- Disallow awaiting non-promise values
- Disallow classes that only have static members
- Disallow comparing
undefinedusingtypeof - 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
awaitexpression - Disallow negated conditions
- Disallow nested ternary expressions
- Disallow
new Array() - Disallow number literals with zero fractions or dangling dots
- Disallow
parseInt()andNumber.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()inasyncfunctions or promise callbacks - Disallow shorthand type conversions
- Disallow ternary operators when simpler alternatives exist
- Disallow the use of
Math.powin favor of the ** operator - Disallow the use of the
nullliteral - 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 ofObject.hasOwn() - Disallow useless array
lengthcheck - Disallow useless fallback when spreading in object literals
- Disallow useless
undefined - Disallow using
Object.assignwith an object literal as the first argument and prefer the use of object spread instead - Disallow using the
thisargument in array methods - Do not use a
forloop that can be replaced with afor-ofloop - Do not use leading/trailing space between
console.logparameters - 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
Errorsubclassing - 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()andBuffer.alloc()instead of the deprecatednew 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
newfor all builtins, exceptString,Number,Boolean,Symbol, andBigInt - Enforce throwing
TypeErrorin 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 andString#charAt() - Prefer
.before()over.insertBefore(),.replaceWith()over.replaceChild(), prefer one of.before(),.after(),.append()or.prepend()overinsertAdjacentText()andinsertAdjacentElement() - Prefer
.find()and.findLast()over the first or last element from.filter() - Prefer
.flatMap()over.map().flat() - Prefer
.includes()over.indexOf()andArray#some()when checking for existence or non-existence - Prefer
.querySelector()over.getElementById(),.querySelectorAll()over.getElementsByClassName()and.getElementsByTagName() - Prefer
.some()over.filter().lengthcheck and.{find,findLast}() - Prefer
Array#flat()over legacy techniques to flatten arrays - Prefer
Array#{indexOf,lastIndexOf}()overArray#{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#keyoverKeyboardEvent#keyCode - Prefer
Node#append()overNode#appendChild() - Prefer
Numberstatic properties over global ones - Prefer
Reflect.apply()overFunction#apply() - Prefer
RegExp#test()overString#match()andRegExp#exec() - Prefer
Set#has()overArray#includes()when checking for existence or non-existence - Prefer
String#replaceAll()over regex searches with the global flag - Prefer
String#slice()overString#substr()andString#substring() - Prefer
String#startsWith()&String#endsWith()overRegExp#test() - Prefer
String#trimStart()/String#trimEnd()overString#trimLeft()/String#trimRight() - Prefer borrowing methods from the prototype instead of the instance
- Prefer
childNode.remove()overparentNode.removeChild(childNode) - Prefer default parameters over reassignment
- Prefer
export…fromwhen re-exporting - Prefer
for…ofover theforEachmethod - Prefer modern Math APIs over legacy patterns
- Prefer negative index over
.length - indexwhen possible - Prefer omitting the catch binding parameter
- Prefer reading a JSON file as a buffer
- Prefer
switchover multipleelse-if - Prefer ternary expressions over simple
if-elsestatements - Prefer the spread operator over
Array.from(),Array#concat(),Array#{slice,toSpliced}()andString#split('') - Prefer using
.dataseton DOM elements over calling attribute methods - Prefer using
Object.fromEntries()to transform a list of key-value pairs into an object - Prefer using
Set#sizeinstead ofArray#length - Prefer using
String,Number,BigInt,Boolean, andSymboldirectly - Prefer using the
node:protocol when importing Node.js builtin modules - Prevent abbreviations
- Require
Array.isArray()instead ofinstanceof 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
letorconstinstead ofvar - Require
newwhen 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