Enforce return
statements in callbacks of array methods
规则参考
ESLint 的规则按类型分组,以帮助你了解它们的目的。每条规则都有与之对应的表情符号:
The "extends": "eslint:recommended"
property in a configuration file enables this rule
Some problems reported by this rule are automatically fixable by the --fix
command line option
Some problems reported by this rule are manually fixable by editor suggestions
Possible Problems
These rules relate to possible logic errors in code:
Require `super()` calls in constructors
✅ Extends
Enforce "for" loop update clause moving the counter in the right direction
✅ Extends
Enforce `return` statements in getters
✅ Extends
Disallow using an async function as a Promise executor
✅ Extends
Disallow `await` inside of loops
Disallow reassigning class members
✅ Extends
Disallow comparing against -0
✅ Extends
Disallow assignment operators in conditional expressions
✅ Extends
Disallow reassigning `const` variables
✅ Extends
Disallow expressions where the operation doesn't affect the value
Disallow constant expressions in conditions
✅ Extends
Disallow returning value from constructor
Disallow control characters in regular expressions
✅ Extends
Disallow the use of `debugger`
✅ Extends
Disallow duplicate arguments in `function` definitions
✅ Extends
Disallow duplicate class members
✅ Extends
Disallow duplicate conditions in if-else-if chains
✅ Extends
Disallow duplicate keys in object literals
✅ Extends
Disallow duplicate case labels
✅ Extends
Disallow duplicate module imports
Disallow empty character classes in regular expressions
✅ Extends
Disallow empty destructuring patterns
✅ Extends
Disallow reassigning exceptions in `catch` clauses
✅ Extends
Disallow fallthrough of `case` statements
✅ Extends
Disallow reassigning `function` declarations
✅ Extends
Disallow assigning to imported bindings
✅ Extends
Disallow variable or `function` declarations in nested blocks
✅ Extends
Disallow invalid regular expression strings in `RegExp` constructors
✅ Extends
Disallow irregular whitespace
✅ Extends
Disallow literal numbers that lose precision
✅ Extends
Disallow characters which are made with multiple code points in character class syntax
✅ Extends
💡 Suggestions
Disallow `new` operators with global non-constructor functions
Disallow `new` operators with the `Symbol` object
✅ Extends
Disallow calling global object properties as functions
✅ Extends
Disallow returning values from Promise executor functions
💡 Suggestions
Disallow calling some `Object.prototype` methods directly on objects
✅ Extends
Disallow assignments where both sides are exactly the same
✅ Extends
Disallow comparisons where both sides are exactly the same
Disallow returning values from setters
✅ Extends
Disallow sparse arrays
✅ Extends
Disallow template literal placeholder syntax in regular strings
Disallow `this`/`super` before calling `super()` in constructors
✅ Extends
Disallow the use of undeclared variables unless mentioned in `/*global */` comments
✅ Extends
Disallow confusing multiline expressions
✅ Extends
Disallow unmodified loop conditions
Disallow unreachable code after `return`, `throw`, `continue`, and `break` statements
✅ Extends
Disallow loops with a body that allows only one iteration
Disallow control flow statements in `finally` blocks
✅ Extends
Disallow negating the left operand of relational operators
✅ Extends
💡 Suggestions
Disallow use of optional chaining in contexts where the `undefined` value is not allowed
✅ Extends
Disallow unused private class members
Disallow unused variables
✅ Extends
Disallow the use of variables before they are defined
Disallow useless backreferences in regular expressions
✅ Extends
Disallow assignments that can lead to race conditions due to usage of `await` or `yield`
Require calls to `isNaN()` when checking for `NaN`
✅ Extends
Enforce comparing `typeof` expressions against valid strings
✅ Extends
💡 Suggestions
Suggestions
These rules suggest alternate ways of doing things: Enforce getter and setter pairs in objects and classes
Require braces around arrow function bodies
🔧 Fix
Enforce the use of variables within the scope they are defined
Enforce camelcase naming convention
Enforce or disallow capitalization of the first letter of a comment
🔧 Fix
Enforce that class methods utilize `this`
Enforce a maximum cyclomatic complexity allowed in a program
Require `return` statements to either always or never specify values
Enforce consistent naming when capturing the current execution context
Enforce consistent brace style for all control statements
🔧 Fix
Require `default` cases in `switch` statements
Enforce default clauses in switch statements to be last
Enforce default parameters to be last
Enforce dot notation whenever possible
🔧 Fix
Require the use of `===` and `!==`
🔧 Fix
Require function names to match the name of the variable or property to which they are assigned
Require or disallow named `function` expressions
Enforce the consistent use of either `function` declarations or expressions
Require grouped accessor pairs in object literals and classes
Require `for-in` loops to include an `if` statement
Disallow specified identifiers
Enforce minimum and maximum identifier lengths
Require identifiers to match a specified regular expression
Require or disallow initialization in variable declarations
Require or disallow logical assignment operator shorthand
🔧 Fix
💡 Suggestions
Enforce a maximum number of classes per file
Enforce a maximum depth that blocks can be nested
Enforce a maximum number of lines per file
Enforce a maximum number of lines of code in a function
Enforce a maximum depth that callbacks can be nested
Enforce a maximum number of parameters in function definitions
Enforce a maximum number of statements allowed in function blocks
Enforce a particular style for multiline comments
🔧 Fix
Require constructor names to begin with a capital letter
Disallow the use of `alert`, `confirm`, and `prompt`
Disallow `Array` constructors
Disallow bitwise operators
Disallow the use of `arguments.caller` or `arguments.callee`
Disallow lexical declarations in case clauses
✅ Extends
Disallow arrow functions where they could be confused with comparisons
🔧 Fix
Disallow the use of `console`
Disallow `continue` statements
Disallow deleting variables
✅ Extends
Disallow equal signs explicitly at the beginning of regular expressions
🔧 Fix
Disallow `else` blocks after `return` statements in `if` statements
🔧 Fix
Disallow empty block statements
✅ Extends
💡 Suggestions
Disallow empty functions
Disallow empty static blocks
Disallow `null` comparisons without type-checking operators
Disallow the use of `eval()`
Disallow extending native types
Disallow unnecessary calls to `.bind()`
🔧 Fix
Disallow unnecessary boolean casts
✅ Extends
🔧 Fix
Disallow unnecessary labels
🔧 Fix
Disallow unnecessary semicolons
✅ Extends
🔧 Fix
Disallow leading or trailing decimal points in numeric literals
🔧 Fix
Disallow assignments to native objects or read-only global variables
✅ Extends
Disallow shorthand type conversions
🔧 Fix
Disallow declarations in the global scope
Disallow the use of `eval()`-like methods
Disallow inline comments after code
Disallow use of `this` in contexts where the value of `this` is `undefined`
Disallow the use of the `__iterator__` property
Disallow labels that share a name with a variable
Disallow labeled statements
Disallow unnecessary nested blocks
Disallow `if` statements as the only statement in `else` blocks
🔧 Fix
Disallow function declarations that contain unsafe references inside loop statements
Disallow magic numbers
Disallow mixed binary operators
Disallow use of chained assignment expressions
Disallow multiline strings
Disallow negated conditions
Disallow nested ternary expressions
Disallow `new` operators outside of assignments or comparisons
Disallow `new` operators with the `Function` object
Disallow `Object` constructors
Disallow `new` operators with the `String`, `Number`, and `Boolean` objects
Disallow `\8` and `\9` escape sequences in string literals
✅ Extends
💡 Suggestions
Disallow octal literals
✅ Extends
Disallow octal escape sequences in string literals
Disallow reassigning `function` parameters
Disallow the unary operators `++` and `--`
Disallow the use of the `__proto__` property
Disallow variable redeclaration
✅ Extends
Disallow multiple spaces in regular expressions
✅ Extends
🔧 Fix
Disallow specified names in exports
Disallow specified global variables
Disallow specified modules when loaded by `import`
Disallow certain properties on certain objects
Disallow specified syntax
Disallow assignment operators in `return` statements
Disallow `javascript:` urls
Disallow comma operators
Disallow variable declarations from shadowing variables declared in the outer scope
Disallow identifiers from shadowing restricted names
✅ Extends
Disallow ternary operators
Disallow throwing literals as exceptions
Disallow initializing variables to `undefined`
🔧 Fix
Disallow the use of `undefined` as an identifier
Disallow dangling underscores in identifiers
Disallow ternary operators when simpler alternatives exist
🔧 Fix
Disallow unused expressions
Disallow unused labels
✅ Extends
🔧 Fix
Disallow unnecessary calls to `.call()` and `.apply()`
Disallow unnecessary `catch` clauses
✅ Extends
Disallow unnecessary computed property keys in objects and classes
🔧 Fix
Disallow unnecessary concatenation of literals or template literals
Disallow unnecessary constructors
Disallow unnecessary escape characters
✅ Extends
💡 Suggestions
Disallow renaming import, export, and destructured assignments to the same name
🔧 Fix
Disallow redundant return statements
🔧 Fix
Require `let` or `const` instead of `var`
🔧 Fix
Disallow `void` operators
Disallow specified warning terms in comments
Disallow `with` statements
✅ Extends
Require or disallow method and property shorthand syntax for object literals
🔧 Fix
Enforce variables to be declared either together or separately in functions
🔧 Fix
Require or disallow newlines around variable declarations
🔧 Fix
Require or disallow assignment operator shorthand where possible
🔧 Fix
Require using arrow functions for callbacks
🔧 Fix
Require `const` declarations for variables that are never reassigned after declared
🔧 Fix
Require destructuring from arrays and/or objects
🔧 Fix
Disallow the use of `Math.pow` in favor of the `**` operator
🔧 Fix
Enforce using named capture group in regular expression
💡 Suggestions
Disallow `parseInt()` and `Number.parseInt()` in favor of binary, octal, and hexadecimal literals
🔧 Fix
Disallow use of `Object.prototype.hasOwnProperty.call()` and prefer use of `Object.hasOwn()`
🔧 Fix
Disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead
🔧 Fix
Require using Error objects as Promise rejection reasons
Disallow use of the `RegExp` constructor in favor of regular expression literals
💡 Suggestions
Require rest parameters instead of `arguments`
Require spread operators instead of `.apply()`
Require template literals instead of string concatenation
🔧 Fix
Require quotes around object literal property names
🔧 Fix
Enforce the consistent use of the radix argument when using `parseInt()`
💡 Suggestions
Disallow async functions which have no `await` expression
Enforce the use of `u` or `v` flag on RegExp
💡 Suggestions
Require generator functions to contain `yield`
✅ Extends
Enforce sorted import declarations within modules
🔧 Fix
Require object keys to be sorted
Require variables within the same declaration block to be sorted
🔧 Fix
Enforce consistent spacing after the `//` or `/*` in a comment
🔧 Fix
Require or disallow strict mode directives
🔧 Fix
Require symbol descriptions
Require `var` declarations be placed at the top of their containing scope
Require or disallow "Yoda" conditions
🔧 Fix
Layout & Formatting
These rules care about how the code looks rather than how it executes: Enforce linebreaks after opening and before closing array brackets
🔧 Fix
Enforce consistent spacing inside array brackets
🔧 Fix
Enforce line breaks after each array element
🔧 Fix
Require parentheses around arrow function arguments
🔧 Fix
Enforce consistent spacing before and after the arrow in arrow functions
🔧 Fix
Disallow or enforce spaces inside of blocks after opening block and before closing block
🔧 Fix
Enforce consistent brace style for blocks
🔧 Fix
Require or disallow trailing commas
🔧 Fix
Enforce consistent spacing before and after commas
🔧 Fix
Enforce consistent comma style
🔧 Fix
Enforce consistent spacing inside computed property brackets
🔧 Fix
Enforce consistent newlines before and after dots
🔧 Fix
Require or disallow newline at the end of files
🔧 Fix
Require or disallow spacing between function identifiers and their invocations
🔧 Fix
Enforce line breaks between arguments of a function call
🔧 Fix
Enforce consistent line breaks inside function parentheses
🔧 Fix
Enforce consistent spacing around `*` operators in generator functions
🔧 Fix
Enforce the location of arrow function bodies
🔧 Fix
Enforce consistent indentation
🔧 Fix
Enforce the consistent use of either double or single quotes in JSX attributes
🔧 Fix
Enforce consistent spacing between keys and values in object literal properties
🔧 Fix
Enforce consistent spacing before and after keywords
🔧 Fix
Enforce position of line comments
Enforce consistent linebreak style
🔧 Fix
Require empty lines around comments
🔧 Fix
Require or disallow an empty line between class members
🔧 Fix
Enforce a maximum line length
Enforce a maximum number of statements allowed per line
Enforce newlines between operands of ternary expressions
🔧 Fix
Enforce or disallow parentheses when invoking a constructor with no arguments
🔧 Fix
Require a newline after each call in a method chain
🔧 Fix
Disallow unnecessary parentheses
🔧 Fix
Disallow mixed spaces and tabs for indentation
✅ Extends
Disallow multiple spaces
🔧 Fix
Disallow multiple empty lines
🔧 Fix
Disallow all tabs
Disallow trailing whitespace at the end of lines
🔧 Fix
Disallow whitespace before properties
🔧 Fix
Enforce the location of single-line statements
🔧 Fix
Enforce consistent line breaks after opening and before closing braces
🔧 Fix
Enforce consistent spacing inside braces
🔧 Fix
Enforce placing object properties on separate lines
🔧 Fix
Enforce consistent linebreak style for operators
🔧 Fix
Require or disallow padding within blocks
🔧 Fix
Require or disallow padding lines between statements
🔧 Fix
Enforce the consistent use of either backticks, double, or single quotes
🔧 Fix
Enforce spacing between rest and spread operators and their expressions
🔧 Fix
Require or disallow semicolons instead of ASI
🔧 Fix
Enforce consistent spacing before and after semicolons
🔧 Fix
Enforce location of semicolons
🔧 Fix
Enforce consistent spacing before blocks
🔧 Fix
Enforce consistent spacing before `function` definition opening parenthesis
🔧 Fix
Enforce consistent spacing inside parentheses
🔧 Fix
Require spacing around infix operators
🔧 Fix
Enforce consistent spacing before or after unary operators
🔧 Fix
Enforce spacing around colons of switch statements
🔧 Fix
Require or disallow spacing around embedded expressions of template strings
🔧 Fix
Require or disallow spacing between template tags and their literals
🔧 Fix
Require or disallow Unicode byte order mark (BOM)
🔧 Fix
Require parentheses around immediate `function` invocations
🔧 Fix
Require parenthesis around regex literals
🔧 Fix
Require or disallow spacing around the `*` in `yield*` expressions
🔧 Fix
Deprecated
These rules have been deprecated in accordance with the deprecation policy, and replaced by newer rules:
callback-return
deprecated
❌
🔧 Fix
💡 Suggestions
global-require deprecated
❌
🔧 Fix
💡 Suggestions
handle-callback-err deprecated
❌
🔧 Fix
💡 Suggestions
id-blacklist deprecated
Replaced by id-denylist
❌
🔧 Fix
💡 Suggestions
indent-legacy deprecated
Replaced by indent
❌
🔧 Fix
💡 Suggestions
lines-around-directive deprecated
Replaced by padding-line-between-statements
❌
🔧 Fix
💡 Suggestions
newline-after-var deprecated
Replaced by padding-line-between-statements
❌
🔧 Fix
💡 Suggestions
newline-before-return deprecated
Replaced by padding-line-between-statements
❌
🔧 Fix
💡 Suggestions
no-buffer-constructor deprecated
❌
🔧 Fix
💡 Suggestions
no-catch-shadow deprecated
Replaced by no-shadow
❌
🔧 Fix
💡 Suggestions
no-mixed-requires deprecated
❌
🔧 Fix
💡 Suggestions
no-native-reassign deprecated
Replaced by no-global-assign
❌
🔧 Fix
💡 Suggestions
no-negated-in-lhs deprecated
Replaced by no-unsafe-negation
❌
🔧 Fix
💡 Suggestions
no-new-require deprecated
❌
🔧 Fix
💡 Suggestions
no-path-concat deprecated
❌
🔧 Fix
💡 Suggestions
no-process-env deprecated
❌
🔧 Fix
💡 Suggestions
no-process-exit deprecated
❌
🔧 Fix
💡 Suggestions
no-restricted-modules deprecated
❌
🔧 Fix
💡 Suggestions
no-return-await deprecated
❌
🔧 Fix
💡 Suggestions
no-spaced-func deprecated
Replaced by func-call-spacing
❌
🔧 Fix
💡 Suggestions
no-sync deprecated
❌
🔧 Fix
💡 Suggestions
prefer-reflect deprecated
❌
🔧 Fix
💡 Suggestions
require-jsdoc deprecated
❌
🔧 Fix
💡 Suggestions
valid-jsdoc deprecated
❌
🔧 Fix
💡 Suggestions
Removed
These rules from older versions of ESLint (before the deprecation policy existed) have been replaced by newer rules:
generator-star
removed
Replaced by ❌
🔧 Fix
💡 Suggestions
generator-star-spacing
global-strict removed
Replaced by strict
❌
🔧 Fix
💡 Suggestions
no-arrow-condition removed
Replaced by no-confusing-arrow
no-constant-condition
❌
🔧 Fix
💡 Suggestions
no-comma-dangle removed
Replaced by comma-dangle
❌
🔧 Fix
💡 Suggestions
no-empty-class removed
Replaced by no-empty-character-class
❌
🔧 Fix
💡 Suggestions
no-empty-label removed
Replaced by no-labels
❌
🔧 Fix
💡 Suggestions
no-extra-strict removed
Replaced by strict
❌
🔧 Fix
💡 Suggestions
no-reserved-keys removed
Replaced by quote-props
❌
🔧 Fix
💡 Suggestions
no-space-before-semi removed
Replaced by semi-spacing
❌
🔧 Fix
💡 Suggestions
no-wrap-func removed
Replaced by no-extra-parens
❌
🔧 Fix
💡 Suggestions
space-after-function-name removed
Replaced by space-before-function-paren
❌
🔧 Fix
💡 Suggestions
space-after-keywords removed
Replaced by keyword-spacing
❌
🔧 Fix
💡 Suggestions
space-before-function-parentheses removed
Replaced by space-before-function-paren
❌
🔧 Fix
💡 Suggestions
space-before-keywords removed
Replaced by keyword-spacing
❌
🔧 Fix
💡 Suggestions
space-in-brackets removed
Replaced by object-curly-spacing
array-bracket-spacing
❌
🔧 Fix
💡 Suggestions
space-return-throw-case removed
Replaced by keyword-spacing
❌
🔧 Fix
💡 Suggestions
space-unary-word-ops removed
Replaced by space-unary-ops
❌
🔧 Fix
💡 Suggestions
spaced-line-comment removed
Replaced by spaced-comment
❌
🔧 Fix
💡 Suggestions