Enforce return statements in callbacks of array methods
π‘ Suggestions
Rules in ESLint are grouped by type to help you understand their purpose. Each rule has emojis denoting:
Using the recommended config from @eslint/js 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
These rules relate to possible logic errors in code: Enforce π‘ Suggestions Require β
Extends Enforce βforβ loop update clause moving the counter in the right direction β
Extends Enforce β
Extends Disallow using an async function as a Promise executor β
Extends Disallow Disallow reassigning class members β
Extends Disallow comparing against -0 β
Extends Disallow assignment operators in conditional expressions β
Extends Disallow reassigning β
Extends Disallow expressions where the operation doesnβt affect the value β
Extends Disallow constant expressions in conditions β
Extends Disallow returning value from constructor Disallow control characters in regular expressions β
Extends Disallow the use of β
Extends Disallow duplicate arguments in β
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 β
Extends Disallow fallthrough of β
Extends Disallow reassigning β
Extends Disallow assigning to imported bindings β
Extends Disallow variable or Disallow invalid regular expression strings in β
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 β
Extends Disallow calling global object properties as functions β
Extends Disallow returning values from Promise executor functions π‘ Suggestions Disallow calling some β
Extends π‘ Suggestions 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 β
Extends Disallow the use of undeclared variables unless mentioned in β
Extends Disallow confusing multiline expressions β
Extends Disallow unmodified loop conditions Disallow unreachable code after β
Extends Disallow loops with a body that allows only one iteration Disallow control flow statements in β
Extends Disallow negating the left operand of relational operators β
Extends π‘ Suggestions Disallow use of optional chaining in contexts where the β
Extends Disallow unused private class members β
Extends Disallow unused variables β
Extends Disallow the use of variables before they are defined Disallow variable assignments when the value is not used Disallow useless backreferences in regular expressions β
Extends Disallow assignments that can lead to race conditions due to usage of Require calls to β
Extends π‘ Suggestions Enforce comparing β
Extends π‘ Suggestions return statements in callbacks of array methodssuper() calls in constructorsreturn statements in gettersawait inside of loopsconst variablesdebuggerfunction definitionscatch clausescase statementsfunction declarationsfunction declarations in nested blocksRegExp constructorsnew operators with global non-constructor functionsObject.prototype methods directly on objectsthis/super before calling super() in constructors/*global */ commentsreturn, throw, continue, and break statementsfinally blocksundefined value is not allowedawait or yieldisNaN() when checking for NaNtypeof expressions against valid strings
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 Enforce a maximum cyclomatic complexity allowed in a program Require Enforce consistent naming when capturing the current execution context Enforce consistent brace style for all control statements π§ Fix Require 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 π§ Fix Require function names to match the name of the variable or property to which they are assigned Require or disallow named Enforce the consistent use of either Require grouped accessor pairs in object literals and classes Require 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 Require constructor names to begin with a capital letter Disallow the use of Disallow π‘ Suggestions Disallow bitwise operators Disallow the use of Disallow lexical declarations in case clauses β
Extends π‘ Suggestions Disallow the use of π‘ Suggestions Disallow Disallow deleting variables β
Extends Disallow equal signs explicitly at the beginning of regular expressions π§ Fix Disallow π§ Fix Disallow empty block statements β
Extends π‘ Suggestions Disallow empty functions Disallow empty static blocks β
Extends Disallow Disallow the use of Disallow extending native types Disallow unnecessary calls to π§ Fix Disallow unnecessary boolean casts β
Extends π§ Fix Disallow unnecessary labels π§ Fix Disallow assignments to native objects or read-only global variables β
Extends Disallow shorthand type conversions π§ Fix π‘ Suggestions Disallow declarations in the global scope Disallow the use of Disallow inline comments after code Disallow use of Disallow the use of the Disallow labels that share a name with a variable Disallow labeled statements Disallow unnecessary nested blocks Disallow π§ Fix Disallow function declarations that contain unsafe references inside loop statements Disallow magic numbers Disallow use of chained assignment expressions Disallow multiline strings Disallow negated conditions Disallow nested ternary expressions Disallow Disallow Disallow Disallow β
Extends π‘ Suggestions Disallow calls to the π‘ Suggestions Disallow octal literals β
Extends Disallow octal escape sequences in string literals Disallow reassigning Disallow the unary operators Disallow the use of the 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 Disallow certain properties on certain objects Disallow specified syntax Disallow assignment operators in Disallow 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 π§ Fix Disallow the use of 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 Disallow unnecessary β
Extends Disallow unnecessary computed property keys in objects and classes π§ Fix Disallow unnecessary concatenation of literals or template literals Disallow unnecessary constructors π‘ Suggestions Disallow unnecessary escape characters β
Extends π‘ Suggestions Disallow renaming import, export, and destructured assignments to the same name π§ Fix Disallow redundant return statements π§ Fix Require π§ Fix Disallow Disallow specified warning terms in comments Disallow β
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 assignment operator shorthand where possible π§ Fix Require using arrow functions for callbacks π§ Fix Require π§ Fix Require destructuring from arrays and/or objects π§ Fix Disallow the use of π§ Fix Enforce using named capture group in regular expression π‘ Suggestions Disallow π§ Fix Disallow use of π§ 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 π‘ Suggestions Require rest parameters instead of Require spread operators instead of Require template literals instead of string concatenation π§ Fix Enforce the consistent use of the radix argument when using π‘ Suggestions Disallow async functions which have no π‘ Suggestions Enforce the use of π‘ Suggestions Require generator functions to contain β
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 Require or disallow strict mode directives π§ Fix Require symbol descriptions Require Require or disallow βYodaβ conditions π§ Fix thisreturn statements to either always or never specify valuesdefault cases in switch statements=== and !==function expressionsfunction declarations or expressions assigned to variablesfor-in loops to include an if statementalert, confirm, and promptArray constructorsarguments.caller or arguments.calleeconsolecontinue statementselse blocks after return statements in if statementsnull comparisons without type-checking operatorseval().bind()eval()-like methodsthis in contexts where the value of this is undefined__iterator__ propertyif statements as the only statement in else blocksnew operators outside of assignments or comparisonsnew operators with the Function objectnew operators with the String, Number, and Boolean objects\8 and \9 escape sequences in string literalsObject constructor without an argumentfunction parameters++ and --__proto__ propertyimportreturn statementsjavascript: urlsundefinedundefined as an identifier.call() and .apply()catch clauseslet or const instead of varvoid operatorswith statementsconst declarations for variables that are never reassigned after declaredMath.pow in favor of the ** operatorparseInt() and Number.parseInt() in favor of binary, octal, and hexadecimal literalsObject.prototype.hasOwnProperty.call() and prefer use of Object.hasOwn()RegExp constructor in favor of regular expression literalsarguments.apply()parseInt()await expressionu or v flag on RegExpyieldvar declarations be placed at the top of their containing scope
These rules care about how the code looks rather than how it executes: Require or disallow Unicode byte order mark (BOM) π§ Fix
These rules have been deprecated in accordance with the deprecation policy, and replaced by newer rules: array-bracket-newline deprecated β π§ Fix array-bracket-spacing deprecated β π§ Fix array-element-newline deprecated β π§ Fix arrow-parens deprecated β π§ Fix arrow-spacing deprecated β π§ Fix block-spacing deprecated β π§ Fix brace-style deprecated β π§ Fix callback-return deprecated β comma-dangle deprecated β π§ Fix comma-spacing deprecated β π§ Fix comma-style deprecated β π§ Fix computed-property-spacing deprecated β π§ Fix dot-location deprecated β π§ Fix eol-last deprecated β π§ Fix func-call-spacing deprecated β π§ Fix function-call-argument-newline deprecated β π§ Fix function-paren-newline deprecated β π§ Fix generator-star-spacing deprecated β π§ Fix global-require deprecated β handle-callback-err deprecated β id-blacklist deprecated Replaced by β implicit-arrow-linebreak deprecated β π§ Fix indent deprecated β π§ Fix indent-legacy deprecated Replaced by β π§ Fix jsx-quotes deprecated β π§ Fix key-spacing deprecated β π§ Fix keyword-spacing deprecated β π§ Fix line-comment-position deprecated β linebreak-style deprecated β π§ Fix lines-around-comment deprecated β π§ Fix lines-around-directive deprecated Replaced by β π§ Fix lines-between-class-members deprecated β π§ Fix max-len deprecated β max-statements-per-line deprecated β multiline-comment-style deprecated β π§ Fix multiline-ternary deprecated β π§ Fix new-parens deprecated β π§ Fix newline-after-var deprecated Replaced by β π§ Fix newline-before-return deprecated Replaced by β π§ Fix newline-per-chained-call deprecated β π§ Fix no-buffer-constructor deprecated β no-catch-shadow deprecated Replaced by β no-confusing-arrow deprecated β π§ Fix no-extra-parens deprecated β π§ Fix no-extra-semi deprecated β π§ Fix no-floating-decimal deprecated β π§ Fix no-mixed-operators deprecated β no-mixed-requires deprecated β no-mixed-spaces-and-tabs deprecated β no-multi-spaces deprecated β π§ Fix no-multiple-empty-lines deprecated β π§ Fix no-native-reassign deprecated Replaced by β no-negated-in-lhs deprecated Replaced by β no-new-object deprecated Replaced by β no-new-require deprecated β no-new-symbol deprecated Replaced by β no-path-concat deprecated β no-process-env deprecated β no-process-exit deprecated β no-restricted-modules deprecated β no-return-await deprecated β π‘ Suggestions no-spaced-func deprecated Replaced by β π§ Fix no-sync deprecated β no-tabs deprecated β no-trailing-spaces deprecated β π§ Fix no-whitespace-before-property deprecated β π§ Fix nonblock-statement-body-position deprecated β π§ Fix object-curly-newline deprecated β π§ Fix object-curly-spacing deprecated β π§ Fix object-property-newline deprecated β π§ Fix one-var-declaration-per-line deprecated β π§ Fix operator-linebreak deprecated β π§ Fix padded-blocks deprecated β π§ Fix padding-line-between-statements deprecated β π§ Fix prefer-reflect deprecated β quote-props deprecated β π§ Fix quotes deprecated β π§ Fix rest-spread-spacing deprecated β π§ Fix semi deprecated β π§ Fix semi-spacing deprecated β π§ Fix semi-style deprecated β π§ Fix space-before-blocks deprecated β π§ Fix space-before-function-paren deprecated β π§ Fix space-in-parens deprecated β π§ Fix space-infix-ops deprecated β π§ Fix space-unary-ops deprecated β π§ Fix spaced-comment deprecated β π§ Fix switch-colon-spacing deprecated β π§ Fix template-curly-spacing deprecated β π§ Fix template-tag-spacing deprecated β π§ Fix wrap-iife deprecated β π§ Fix wrap-regex deprecated β π§ Fix yield-star-spacing deprecated β π§ Fix id-denylistindentpadding-line-between-statementspadding-line-between-statementspadding-line-between-statementsno-shadowno-global-assignno-unsafe-negationno-object-constructorno-new-native-nonconstructorfunc-call-spacing
These rules from older versions of ESLint (before the deprecation policy existed) have been replaced by newer rules: generator-star removed Replaced by global-strict removed Replaced by no-arrow-condition removed Replaced by no-comma-dangle removed Replaced by no-empty-class removed Replaced by no-empty-label removed Replaced by no-extra-strict removed Replaced by no-reserved-keys removed Replaced by no-space-before-semi removed Replaced by no-wrap-func removed Replaced by space-after-function-name removed Replaced by space-after-keywords removed Replaced by space-before-function-parentheses removed Replaced by space-before-keywords removed Replaced by space-in-brackets removed Replaced by space-return-throw-case removed Replaced by space-unary-word-ops removed Replaced by spaced-line-comment removed Replaced by valid-jsdoc removed Replaced by require-jsdoc removed Replaced by generator-star-spacingstrictno-confusing-arrowno-constant-conditioncomma-dangleno-empty-character-classno-labelsstrictquote-propssemi-spacingno-extra-parensspace-before-function-parenkeyword-spacingspace-before-function-parenkeyword-spacingobject-curly-spacingarray-bracket-spacingkeyword-spacingspace-unary-opsspaced-comment
© OpenJS Foundation and other contributors
Licensed under the MIT License.
https://eslint.org/docs/latest/rules