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.
| Rule | Setting | Files | What it checks | Why |
|---|---|---|---|---|
array-callback-return | error, {"allowImplicit":true,"checkForEach":true} | JS + TS | Enforce return statements in callbacks of array methods | Custom: a bare return; is allowed; forEach callbacks must not return a value. |
no-sparse-arrays | error | JS + TS | Disallow sparse arrays | — |
id-length | off | JS + TS | Enforce minimum and maximum identifier lengths | — |
no-array-constructor | error | JS + TS | Disallow Array constructors | Replaced by the TS version. |
no-useless-concat | info | JS + TS | Disallow unnecessary concatenation of literals or template literals | — |
sort-keys | off | JS + TS | Require object keys to be sorted | — |
sort-vars | off | JS + TS | Require variables within the same declaration block to be sorted | — |
sonarjs/no-incorrect-string-concat | off | JS + TS | Strings and non-strings should not be added | Off: not in the Sonar way profile of SonarQube. |
sonarjs/array-callback-without-return | off | JS + TS | Callbacks of array methods should have return statements | Off: duplicate of array-callback-return. |
sonarjs/no-alphabetical-sort | off | JS + TS | "Array.prototype.sort()" and "Array.prototype.toSorted()" should use a compare function | Off: duplicate of @typescript-eslint/require-array-sort-compare. |
sonarjs/no-array-delete | off | JS + TS | "delete" should not be used on arrays | Off: duplicate of @typescript-eslint/no-array-delete. |
sonarjs/array-constructor | off | JS + TS | Array constructors should not be used | Off: not in the Sonar way profile of SonarQube. |
sonarjs/no-associative-arrays | warn | JS + TS | Array indexes should be numeric | — |
sonarjs/no-element-overwrite | error | JS + TS | Collection elements should not be replaced unconditionally | — |
sonarjs/no-in-misuse | error | JS + TS | "in" should not be used on arrays | — |
sonarjs/no-misleading-array-reverse | error | JS + TS | Array-mutating methods should not be used misleadingly | — |
sonarjs/reduce-initial-value | error | JS + TS | "Array.reduce()" calls should include an initial value | — |
@typescript-eslint/array-type | error | TS | Require consistently using either T[] or Array<T> for arrays | — |
no-array-constructor | off | TS | Disallow Array constructors | Replaced by the TS version. |
@typescript-eslint/no-array-constructor | error | TS | Disallow generic Array constructors | — |
@typescript-eslint/no-array-delete | error | TS | Disallow using the delete operator on array values | — |
@typescript-eslint/prefer-find | info | TS | Enforce the use of Array.prototype.find() over Array.prototype.filter() followed by [0] when looking for a single result | — |
@typescript-eslint/prefer-includes | error | TS | Enforce includes method over indexOf method | — |
@typescript-eslint/prefer-reduce-type-parameter | error | TS | Enforce using type parameter when calling Array#reduce instead of using a type assertion | — |
@typescript-eslint/require-array-sort-compare | error | TS | Require Array#sort and Array#toSorted calls to always provide a compareFunction | — |
@typescript-eslint/sort-type-constituents | off | TS | Enforce constituents of a type union/intersection to be sorted alphabetically | Deprecated: replaced by eslint-plugin-perfectionist. |