Skip to content

Unicorn

223 rules eslint-plugin-unicorn@76.0.0

Complete effective rule inventory.

Docs

Rules

40 rules on this page · 223 total

  • unicorn/prefer-iterator-to-array-at-end

    Prefer moving .toArray() to the end of iterator helper chains.

    : error in All Unicorn contexts
    No autofix; suggestions available
  • unicorn/prefer-keyboard-event-key

    Prefer KeyboardEvent#key over deprecated keyboard event properties.

    : error in All Unicorn contexts
    Autofix available; suggestions available
  • unicorn/prefer-logical-operator-over-ternary

    Prefer using a logical operator over a ternary.

    : error in All Unicorn contexts
    Autofix available; suggestions available
  • unicorn/prefer-map-from-entries

    Prefer new Map() over Object.fromEntries() when using the result as a map.

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-math-abs

    Prefer Math.abs() over manual absolute value expressions and symmetric range checks.

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-math-constants

    Prefer Math constants over their approximate numeric values.

    : error in All Unicorn contexts
    No autofix; suggestions available
  • unicorn/prefer-math-min-max

    Prefer Math.min() and Math.max() over ternaries for simple comparisons.

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-math-trunc

    Prefer Math.trunc() for truncating numbers.

    : error in All Unicorn contexts
    Autofix available; suggestions available
  • unicorn/prefer-modern-math-apis

    Prefer modern Math APIs over legacy patterns.

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-module

    Prefer JavaScript modules (ESM) over CommonJS.

    : error in All Unicorn contexts
    Autofix available; suggestions available
  • unicorn/prefer-native-coercion-functions

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

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-negative-index

    Prefer negative index over .length - index when possible.

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-node-protocol

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

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-number-is-safe-integer

    Prefer Number.isSafeInteger() over integer checks.

    : error in All Unicorn contexts
    No autofix; suggestions available
  • unicorn/prefer-number-properties

    Prefer Number static methods over global functions and optionally static properties over global constants.

    : error in All Unicorn contexts
    Autofix available; suggestions available
  • unicorn/prefer-object-define-properties

    Prefer Object.defineProperties() over multiple Object.defineProperty() calls.

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-object-destructuring-defaults

    Prefer object destructuring defaults over default object literals with spread.

    : error in All Unicorn contexts
    No autofix; suggestions available
  • unicorn/prefer-object-from-entries

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

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-object-iterable-methods

    Prefer the most specific Object iterable method.

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-optional-catch-binding

    Prefer omitting the catch binding parameter.

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-promise-with-resolvers

    Prefer Promise.withResolvers() when extracting resolver functions from new Promise().

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-queue-microtask

    Prefer queueMicrotask() over process.nextTick(), setImmediate(), and setTimeout(…, 0).

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-regexp-test

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

    : error in All Unicorn contexts
    Autofix available; suggestions available
  • unicorn/prefer-response-static-json

    Prefer Response.json() over new Response(JSON.stringify()).

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-set-has

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

    : error in All Unicorn contexts
    Autofix available; suggestions available
  • unicorn/prefer-set-methods

    Prefer Set methods for Set operations.

    : error in All Unicorn contexts
    Autofix available; suggestions available
  • unicorn/prefer-set-size

    Prefer using Set#size instead of Array#length.

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-simple-sort-comparator

    Prefer a simple comparison function for Array#sort().

    : error in All Unicorn contexts
    No autofix; suggestions available
  • unicorn/prefer-simplified-conditions

    Prefer simplified conditions.

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-single-array-predicate

    Prefer a single Array#some() or Array#every() with a combined predicate.

    : error in All Unicorn contexts
    No autofix; suggestions available
  • unicorn/prefer-single-object-destructuring

    Prefer a single object destructuring declaration per local const source.

    : warning in All Unicorn contexts
    Autofix available
  • unicorn/prefer-single-replace

    Enforce combining multiple single-character replacements into a single String#replaceAll() with a regular expression.

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-split-limit

    Prefer String#split() with a limit.

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-spread

    Prefer the spread operator over Array.from(…), Array#concat(…), Array#{slice,toSpliced}(), and trivial for…of copies.

    : error in All Unicorn contexts
    Autofix available; suggestions available
  • unicorn/prefer-string-match-all

    Prefer String#matchAll() over RegExp#exec() loops.

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-string-pad-start-end

    Prefer String#padStart() and String#padEnd() over manual string padding.

    : error in All Unicorn contexts
    Autofix available; suggestions available
  • unicorn/prefer-string-raw

    Prefer using the String.raw tag to avoid escaping \.

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-string-repeat

    Prefer String#repeat() for repeated whitespace.

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-string-replace-all

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

    : error in All Unicorn contexts
    Autofix available
  • unicorn/prefer-string-slice

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

    : error in All Unicorn contexts
    Autofix available