Logo
  • DB
  • About
  • Updates
eslint-plugin-unicorn

More than 100 powerful ESLint rules

❯ npm i --save-dev eslint-plugin-unicorn
RepositoryGitHub LogoGitHubnpm Logonpm
πŸ•΅οΈβ€β™‚οΈ Linter
  • 2 Configs
  • 126 Rules
GitHub LogoGitHub
  • JavaScript
  • 3.7K Stars
  • 24 Watchers
npm Logonpm
  • 1.2M Wkly Downloads
  • +33% WoW
  • 50.0.1 β€’ 657 kB
πŸ“‹ Requirements
  • Node: >=16
  • ESLint: >=8.56
πŸ—‚οΈ Keywords
  • eslint-rules
  • javascript
  • linting-rules
  • nodejs
  • unicorns
  • ...
ConfigurationRules
🌐 all109
βœ… recommended103 error β€’ 6 off
RuleDescriptionπŸ”§πŸ’‘πŸ’­πŸ—‚οΈβš™οΈβŒπŸŒβœ…
better-regex

Improve regexes by making them shorter, consistent, and safer.

πŸ”§πŸ“–βš™οΈπŸŒβœ…
catch-error-name

Enforce a specific parameter name in catch clauses.

πŸ”§πŸ“–βš™οΈπŸŒβœ…
consistent-destructuring

Use destructured variables over properties.

πŸ”§πŸ’‘πŸ“–πŸŒβœ…
consistent-function-scoping

Move function definitions to the highest possible scope.

πŸ“–βš™οΈπŸŒβœ…
custom-error-definition

Enforce correct Error subclassing.

πŸ”§β—πŸŒπŸš«
empty-brace-spaces

Enforce no spaces between braces.

πŸ”§πŸ“πŸŒβœ…
error-message

Enforce passing a message value when creating a built-in error.

β—πŸŒβœ…
escape-case

Require escape sequences to use uppercase values.

πŸ”§πŸ“–πŸŒβœ…
expiring-todo-comments

Add expiration conditions to TODO comments.

πŸ“–βš™οΈπŸŒβœ…
explicit-length-check

Enforce explicitly comparing the length or size property of a value.

πŸ”§πŸ’‘β—βš™οΈπŸŒβœ…
filename-case

Enforce a case style for filenames.

πŸ“–βš™οΈπŸŒβœ…
import-index❌
import-style

Enforce specific import styles per module.

β—βš™οΈπŸŒβœ…
new-for-builtins

Enforce the use of new for all builtins, except String, Number, Boolean, Symbol and BigInt.

πŸ”§πŸ“–πŸŒβœ…
no-abusive-eslint-disable

Enforce specifying rules to disable in eslint-disable comments.

πŸ“–πŸŒβœ…
no-array-callback-reference

Prevent passing a function reference directly to iterator methods.

πŸ’‘β—πŸŒβœ…
no-array-for-each

Prefer for…of over the forEach method.

πŸ”§πŸ’‘πŸ“–πŸŒβœ…
no-array-instanceof❌
no-array-method-this-argument

Disallow using the this argument in array methods.

πŸ”§πŸ’‘πŸ“–πŸŒβœ…
no-array-push-push

Enforce combining multiple Array#push() into one call.

πŸ”§πŸ’‘πŸ“–βš™οΈπŸŒβœ…
no-array-reduce

Disallow Array#reduce() and Array#reduceRight().

πŸ“–βš™οΈπŸŒβœ…
no-await-expression-member

Disallow member access from await expression.

πŸ”§πŸ“–πŸŒβœ…
no-console-spaces

Do not use leading/trailing space between console.log parameters.

πŸ”§πŸ“–πŸŒβœ…
no-document-cookie

Do not use document.cookie directly.

β—πŸŒβœ…
no-empty-file

Disallow empty files.

πŸ“–πŸŒβœ…
no-fn-reference-in-iterator❌
no-for-loop

Do not use a for loop that can be replaced with a for-of loop.

πŸ”§πŸ“–πŸŒβœ…
no-hex-escape

Enforce the use of Unicode escapes instead of hexadecimal escapes.

πŸ”§πŸ“–πŸŒβœ…
no-instanceof-array

Require Array.isArray() instead of instanceof Array.

πŸ”§πŸ“–πŸŒβœ…
no-invalid-remove-event-listener

Prevent calling EventTarget#removeEventListener() with the result of an expression.

β—πŸŒβœ…
no-keyword-prefix

Disallow identifiers starting with new or class.

πŸ“–βš™οΈπŸŒπŸš«
no-lonely-if

Disallow if statements as the only statement in if blocks without else.

πŸ”§πŸ“–πŸŒβœ…
no-negated-condition

Disallow negated conditions.

πŸ”§πŸ“–πŸŒβœ…
no-nested-ternary

Disallow nested ternary expressions.

πŸ”§πŸ“–πŸŒβœ…
no-new-array

Disallow new Array().

πŸ”§πŸ’‘πŸ“–πŸŒβœ…
no-new-buffer

Enforce the use of Buffer.from() and Buffer.alloc() instead of the deprecated new Buffer().

πŸ”§πŸ’‘β—πŸŒβœ…
no-null

Disallow the use of the null literal.

πŸ”§πŸ’‘πŸ“–βš™οΈπŸŒβœ…
no-object-as-default-parameter

Disallow the use of objects as default parameters.

β—πŸŒβœ…
no-process-exit

Disallow process.exit().

πŸ“–πŸŒβœ…
no-reduce❌
no-static-only-class

Disallow classes that only have static members.

πŸ”§πŸ“–πŸŒβœ…
no-thenable

Disallow then property.

β—πŸŒβœ…
no-this-assignment

Disallow assigning this to a variable.

πŸ“–πŸŒβœ…
no-typeof-undefined

Disallow comparing undefined using typeof.

πŸ”§πŸ’‘πŸ“–βš™οΈπŸŒβœ…
no-unnecessary-await

Disallow awaiting non-promise values.

πŸ”§πŸ“–πŸŒβœ…
no-unreadable-array-destructuring

Disallow unreadable array destructuring.

πŸ”§πŸ“–πŸŒβœ…
no-unreadable-iife

Disallow unreadable IIFEs.

πŸ“–πŸŒβœ…
no-unsafe-regex❌
no-unused-properties

Disallow unused object properties.

πŸ“–πŸŒπŸš«
no-useless-fallback-in-spread

Disallow useless fallback when spreading in object literals.

πŸ”§πŸ“–πŸŒβœ…
no-useless-length-check

Disallow useless array length check.

πŸ”§πŸ“–πŸŒβœ…
no-useless-promise-resolve-reject

Disallow returning/yielding Promise.resolve/reject() in async functions or promise callbacks

πŸ”§πŸ“–πŸŒβœ…
no-useless-spread

Disallow unnecessary spread.

πŸ”§πŸ“–πŸŒβœ…
no-useless-switch-case

Disallow useless case in switch statements.

πŸ’‘πŸ“–πŸŒβœ…
no-useless-undefined

Disallow useless undefined.

πŸ”§πŸ“–βš™οΈπŸŒβœ…
no-zero-fractions

Disallow number literals with zero fractions or dangling dots.

πŸ”§πŸ“–πŸŒβœ…
number-literal-case

Enforce proper case for numeric literals.

πŸ”§πŸ“–πŸŒβœ…
numeric-separators-style

Enforce the style of numeric separators by correctly grouping digits.

πŸ”§πŸ“–βš™οΈπŸŒβœ…
prefer-add-event-listener

Prefer .addEventListener() and .removeEventListener() over on-functions.

πŸ”§πŸ“–βš™οΈπŸŒβœ…
prefer-array-find

Prefer .find(…) and .findLast(…) over the first or last element from .filter(…).

πŸ”§πŸ’‘πŸ“–βš™οΈπŸŒβœ…
prefer-array-flat

Prefer Array#flat() over legacy techniques to flatten arrays.

πŸ”§πŸ“–βš™οΈπŸŒβœ…
prefer-array-flat-map

Prefer .flatMap(…) over .map(…).flat().

πŸ”§πŸ“–πŸŒβœ…
prefer-array-index-of

Prefer Array#{indexOf,lastIndexOf}() over Array#{findIndex,findLastIndex}() when looking for the index of an item.

πŸ”§πŸ’‘πŸ“–πŸŒβœ…
prefer-array-some

Prefer .some(…) over .filter(…).length check and .{find,findLast}(…).

πŸ”§πŸ’‘πŸ“–πŸŒβœ…
prefer-at

Prefer .at() method for index access and String#charAt().

πŸ”§πŸ’‘πŸ“–βš™οΈπŸŒβœ…
prefer-blob-reading-methods

Prefer Blob#arrayBuffer() over FileReader#readAsArrayBuffer(…) and Blob#text() over FileReader#readAsText(…).

πŸ“–πŸŒβœ…
prefer-code-point

Prefer String#codePointAt(…) over String#charCodeAt(…) and String.fromCodePoint(…) over String.fromCharCode(…).

πŸ’‘πŸ“–πŸŒβœ…
prefer-dataset❌
prefer-date-now

Prefer Date.now() to get the number of milliseconds since the Unix Epoch.

πŸ”§πŸ“–πŸŒβœ…
prefer-default-parameters

Prefer default parameters over reassignment.

πŸ”§πŸ’‘πŸ“–πŸŒβœ…
prefer-dom-node-append

Prefer Node#append() over Node#appendChild().

πŸ”§πŸ“–πŸŒβœ…
prefer-dom-node-dataset

Prefer using .dataset on DOM elements over calling attribute methods.

πŸ”§πŸ“–πŸŒβœ…
prefer-dom-node-remove

Prefer childNode.remove() over parentNode.removeChild(childNode).

πŸ”§πŸ’‘πŸ“–πŸŒβœ…
prefer-dom-node-text-content

Prefer .textContent over .innerText.

πŸ’‘πŸ“–πŸŒβœ…
prefer-event-key❌
prefer-event-target

Prefer EventTarget over EventEmitter.

πŸ“–πŸŒβœ…
prefer-exponentiation-operator❌
prefer-export-from

Prefer export…from when re-exporting.

πŸ”§πŸ’‘πŸ“–βš™οΈπŸŒβœ…
prefer-flat-map❌
prefer-includes

Prefer .includes() over .indexOf() and Array#some() when checking for existence or non-existence.

πŸ”§πŸ’‘πŸ“–πŸŒβœ…
prefer-json-parse-buffer

Prefer reading a JSON file as a buffer.

πŸ”§πŸ“–πŸŒπŸš«
prefer-keyboard-event-key

Prefer KeyboardEvent#key over KeyboardEvent#keyCode.

πŸ”§πŸ“–πŸŒβœ…
prefer-logical-operator-over-ternary

Prefer using a logical operator over a ternary.

πŸ’‘πŸ“–πŸŒβœ…
prefer-math-trunc

Enforce the use of Math.trunc instead of bitwise operators.

πŸ”§πŸ’‘πŸ“–πŸŒβœ…
prefer-modern-dom-apis

Prefer .before() over .insertBefore(), .replaceWith() over .replaceChild(), prefer one of .before(), .after(), .append() or .prepend() over insertAdjacentText() and insertAdjacentElement().

πŸ”§πŸ“–πŸŒβœ…
prefer-modern-math-apis

Prefer modern Math APIs over legacy patterns.

πŸ”§πŸ“–πŸŒβœ…
prefer-module

Prefer JavaScript modules (ESM) over CommonJS.

πŸ”§πŸ’‘πŸ“–πŸŒβœ…
prefer-native-coercion-functions

Prefer using String, Number, BigInt, Boolean, and Symbol directly.

πŸ”§πŸ“–πŸŒβœ…
prefer-negative-index

Prefer negative index over .length - index when possible.

πŸ”§πŸ“–πŸŒβœ…
prefer-node-append❌
prefer-node-protocol

Prefer using the node: protocol when importing Node.js builtin modules.

πŸ”§πŸ“–πŸŒβœ…
prefer-node-remove❌
prefer-number-properties

Prefer Number static properties over global ones.

πŸ”§πŸ’‘πŸ“–βš™οΈπŸŒβœ…
prefer-object-from-entries

Prefer using Object.fromEntries(…) to transform a list of key-value pairs into an object.

πŸ”§πŸ“–βš™οΈπŸŒβœ…
prefer-object-has-own❌
prefer-optional-catch-binding

Prefer omitting the catch binding parameter.

πŸ”§πŸ“–πŸŒβœ…
prefer-prototype-methods

Prefer borrowing methods from the prototype instead of the instance.

πŸ”§πŸ“–πŸŒβœ…
prefer-query-selector

Prefer .querySelector() over .getElementById(), .querySelectorAll() over .getElementsByClassName() and .getElementsByTagName().

πŸ”§πŸ“–πŸŒβœ…
prefer-reflect-apply

Prefer Reflect.apply() over Function#apply().

πŸ”§πŸ“–πŸŒβœ…
prefer-regexp-test

Prefer RegExp#test() over String#match() and RegExp#exec().

πŸ”§πŸ’‘πŸ“–πŸŒβœ…
prefer-replace-all❌
prefer-set-has

Prefer Set#has() over Array#includes() when checking for existence or non-existence.

πŸ”§πŸ’‘πŸ“–πŸŒβœ…
prefer-set-size

Prefer using Set#size instead of Array#length.

πŸ”§πŸ“–πŸŒβœ…
prefer-spread

Prefer the spread operator over Array.from(…), Array#concat(…), Array#{slice,toSpliced}() and String#split('').

πŸ”§πŸ’‘πŸ“–πŸŒβœ…
prefer-starts-ends-with❌
prefer-string-replace-all

Prefer String#replaceAll() over regex searches with the global flag.

πŸ”§πŸ“–πŸŒβœ…
prefer-string-slice

Prefer String#slice() over String#substr() and String#substring().

πŸ”§πŸ“–πŸŒβœ…
prefer-string-starts-ends-with

Prefer String#startsWith() & String#endsWith() over RegExp#test().

πŸ”§πŸ’‘πŸ“–πŸŒβœ…
prefer-string-trim-start-end

Prefer String#trimStart() / String#trimEnd() over String#trimLeft() / String#trimRight().

πŸ”§πŸ“–πŸŒβœ…
prefer-switch

Prefer switch over multiple else-if.

πŸ”§πŸ“–βš™οΈπŸŒβœ…
prefer-ternary

Prefer ternary expressions over simple if-else statements.

πŸ”§πŸ“–πŸŒβœ…
prefer-text-content❌
prefer-top-level-await

Prefer top-level await over top-level promises and async function calls.

πŸ’‘πŸ“–πŸŒβœ…
prefer-trim-start-end❌
prefer-type-error

Enforce throwing TypeError in type checking conditions.

πŸ”§πŸ“–πŸŒβœ…
prevent-abbreviations

Prevent abbreviations.

πŸ”§πŸ“–βš™οΈπŸŒβœ…
regex-shorthand❌
relative-url-style

Enforce consistent relative URL style.

πŸ”§πŸ’‘πŸ“–πŸŒβœ…
require-array-join-separator

Enforce using the separator argument with Array#join().

πŸ”§πŸ“–πŸŒβœ…
require-number-to-fixed-digits-argument

Enforce using the digits argument with Number#toFixed().

πŸ”§πŸ“–πŸŒβœ…
require-post-message-target-origin

Enforce using the targetOrigin argument with window.postMessage().

πŸ’‘β—πŸŒπŸš«
string-content

Enforce better string content.

πŸ”§πŸ’‘πŸ“–βš™οΈπŸŒπŸš«
switch-case-braces

Enforce consistent brace style for case clauses.

πŸ”§πŸ“πŸŒβœ…
template-indent

Fix whitespace-insensitive template indentation.

πŸ”§πŸ“–βš™οΈπŸŒβœ…
text-encoding-identifier-case

Enforce consistent case for text encoding identifiers.

πŸ”§πŸ’‘πŸ“–πŸŒβœ…
throw-new-error

Require new when throwing an error.

πŸ”§πŸ“–πŸŒβœ…
Β© 2024 Lintbase