Skip to content

eslint/rules/arrays ​

Arrays: Array methods, array creation, sorting and searching. Rules of ESLint, typescript-eslint and SonarJS (the Sonar way profile of SonarQube) on this subject, every rule listed; the TypeScript rules apply to TypeScript files only.

26 rules, 16 on. Source: lint/eslint/rules/arrays.mjs.

RuleSettingFilesWhat it checksWhy
array-callback-returnerror, {"allowImplicit":true,"checkForEach":true}JS + TSEnforce return statements in callbacks of array methodsCustom: a bare return; is allowed; forEach callbacks must not return a value.
no-sparse-arrayserrorJS + TSDisallow sparse arrays—
id-lengthoffJS + TSEnforce minimum and maximum identifier lengths—
no-array-constructorerrorJS + TSDisallow Array constructorsReplaced by the TS version.
no-useless-concatinfoJS + TSDisallow unnecessary concatenation of literals or template literals—
sort-keysoffJS + TSRequire object keys to be sorted—
sort-varsoffJS + TSRequire variables within the same declaration block to be sorted—
sonarjs/no-incorrect-string-concatoffJS + TSStrings and non-strings should not be addedOff: not in the Sonar way profile of SonarQube.
sonarjs/array-callback-without-returnoffJS + TSCallbacks of array methods should have return statementsOff: duplicate of array-callback-return.
sonarjs/no-alphabetical-sortoffJS + TS"Array.prototype.sort()" and "Array.prototype.toSorted()" should use a compare functionOff: duplicate of @typescript-eslint/require-array-sort-compare.
sonarjs/no-array-deleteoffJS + TS"delete" should not be used on arraysOff: duplicate of @typescript-eslint/no-array-delete.
sonarjs/array-constructoroffJS + TSArray constructors should not be usedOff: not in the Sonar way profile of SonarQube.
sonarjs/no-associative-arrayswarnJS + TSArray indexes should be numeric—
sonarjs/no-element-overwriteerrorJS + TSCollection elements should not be replaced unconditionally—
sonarjs/no-in-misuseerrorJS + TS"in" should not be used on arrays—
sonarjs/no-misleading-array-reverseerrorJS + TSArray-mutating methods should not be used misleadingly—
sonarjs/reduce-initial-valueerrorJS + TS"Array.reduce()" calls should include an initial value—
@typescript-eslint/array-typeerrorTSRequire consistently using either T[] or Array<T> for arrays—
no-array-constructoroffTSDisallow Array constructorsReplaced by the TS version.
@typescript-eslint/no-array-constructorerrorTSDisallow generic Array constructors—
@typescript-eslint/no-array-deleteerrorTSDisallow using the delete operator on array values—
@typescript-eslint/prefer-findinfoTSEnforce the use of Array.prototype.find() over Array.prototype.filter() followed by [0] when looking for a single result—
@typescript-eslint/prefer-includeserrorTSEnforce includes method over indexOf method—
@typescript-eslint/prefer-reduce-type-parametererrorTSEnforce using type parameter when calling Array#reduce instead of using a type assertion—
@typescript-eslint/require-array-sort-compareerrorTSRequire Array#sort and Array#toSorted calls to always provide a compareFunction—
@typescript-eslint/sort-type-constituentsoffTSEnforce constituents of a type union/intersection to be sorted alphabeticallyDeprecated: replaced by eslint-plugin-perfectionist.

Generated from the JSDoc of the sources.