The official e18e ESLint plugin for modernizing JavaScript/TypeScript code and improving performance.
This plugin focuses on applying the e18e community's best practices and advise to JavaScript/TypeScript codebases.
There are a few categories of rules in this plugin:
Each of these can be enabled individually, or you can use the recommended configuration to enable all rules.
npm install --save-dev @e18e/eslint-plugin
Add the plugin to your eslint.config.js:
import e18e from '@e18e/eslint-plugin';
export default [
// Use the recommended configuration (includes all categories)
e18e.configs.recommended,
// Or use specific category configurations
e18e.configs.modernization,
e18e.configs.moduleReplacements,
e18e.configs.performanceImprovements,
// Or configure rules manually
{
plugins: {
e18e
},
rules: {
'e18e/prefer-array-at': 'error',
'e18e/prefer-array-fill': 'error',
'e18e/prefer-includes': 'error'
}
}
];
If you're using oxlint, you can enable the e18e plugin by adding it to your .oxlintrc.json file:
{
"jsPlugins": ["@e18e/eslint-plugin"],
"rules": {
"e18e/prefer-includes": "error"
}
}
You can enable the recommended configuration by copying the rules from each of the ESLint configuration files into your .oxlintrc.json file.
Copying these rules into your rules object will achieve the same effect as using the recommended configuration in ESLint.
[!NOTE] Our type-aware rules depend on TypeScript ESLint's parser, which means they will not work with oxlint at this time.
package.jsonSome rules (e.g. ban-dependencies) can be used against your package.json.
You can achieve this by using @eslint/json or jsonc-eslint-parser.
For example, with @eslint/json and eslint.config.js:
import e18e from '@e18e/eslint-plugin';
import json from '@eslint/json';
import {defineConfig} from 'eslint/config';
export default defineConfig([
{
files: ['package.json'],
language: 'json/json',
plugins: {
e18e,
json
},
extends: ['e18e/recommended'],
}
]);
Or with jsonc-eslint-parser and eslint.config.js:
import e18e from '@e18e/eslint-plugin';
import jsonParser from 'jsonc-eslint-parser';
import {defineConfig} from 'eslint/config';
export default defineConfig([
{
files: ['package.json'],
languageOptions: {
parser: jsonParser
},
plugins: {
e18e
},
extends: ['e18e/recommended'],
}
]);
Read more at the
@eslint/json docs and
jsonc-eslint-parser docs.
Legend:
| Rule | Description | Recommended | Fixable | Requires Types |
|---|---|---|---|---|
| prefer-array-at | Prefer Array.prototype.at() over length-based indexing | ✅ | ✅ | 🔶 |
| prefer-array-fill | Prefer Array.prototype.fill() over Array.from() or map() with constant values | ✅ | ✅ | ✖️ |
| prefer-includes | Prefer .includes() over indexOf() comparisons for arrays and strings | ✅ | ✅ | ✖️ |
| prefer-array-to-reversed | Prefer Array.prototype.toReversed() over copying and reversing arrays | ✅ | ✅ | 🔶 |
| prefer-array-to-sorted | Prefer Array.prototype.toSorted() over copying and sorting arrays | ✅ | ✅ | 🔶 |
| prefer-array-to-spliced | Prefer Array.prototype.toSpliced() over copying and splicing arrays | ✅ | ✅ | ✖️ |
| prefer-exponentiation-operator | Prefer the exponentiation operator ** over Math.pow() | ✅ | ✅ | ✖️ |
| prefer-nullish-coalescing | Prefer nullish coalescing operator (?? and ??=) over verbose null checks | ✅ | ✅ | ✖️ |
| prefer-object-has-own | Prefer Object.hasOwn() over Object.prototype.hasOwnProperty.call() and obj.hasOwnProperty() | ✅ | ✅ | ✖️ |
| prefer-spread-syntax | Prefer spread syntax over Array.concat(), Array.from(), Object.assign({}, ...), and Function.apply() | ✅ | ✅ | 🔶 |
| prefer-url-canparse | Prefer URL.canParse() over try-catch blocks for URL validation | ✅ | 💡 | ✖️ |
| prefer-get-or-insert | Prefer Map.prototype.getOrInsert() over reading a map entry with a default and writing it back | ✖️ | ✅ | ✖️ |
| Rule | Description | Recommended | Fixable | Requires Types |
|---|---|---|---|---|
| ban-dependencies | Disallow dependencies in favor of more performant or secure alternatives | ✅ | ✖️ | ✖️ |
| Rule | Description | Recommended | Fixable | Requires Types |
|---|---|---|---|---|
| no-indexof-equality | Prefer startsWith() for strings and direct array access over indexOf() equality checks | ✖️ | ✅ | ✅ |
| prefer-array-from-map | Prefer Array.from(iterable, mapper) over [...iterable].map(mapper) to avoid intermediate array allocation | ✅ | ✅ | ✖️ |
| prefer-array-some | Prefer Array.some() over Array.find() and Array.filter().length checks when checking for element existence | ✅ | ✅ | ✖️ |
| prefer-timer-args | Prefer passing function and arguments directly to setTimeout/setInterval instead of wrapping in an arrow function or using bind | ✅ | ✅ | ✖️ |
| prefer-date-now | Prefer Date.now() over new Date().getTime() and +new Date() | ✅ | ✅ | ✖️ |
| prefer-regex-test | Prefer RegExp.test() over String.match() and RegExp.exec() when only checking for match existence | ✅ | ✅ | 🔶 |
| prefer-static-regex | Prefer defining regular expressions at module scope to avoid re-compilation on every function call | ✅ | ✖️ | 🔶 |
| prefer-inline-equality | Prefer inline equality checks over temporary object creation for simple comparisons | ✖️ | ✅ | 🔶 |
| prefer-string-fromcharcode | Prefer String.fromCharCode() over String.fromCodePoint() for code points below 0x10000 | ✅ | ✅ | ✖️ |
| prefer-includes-over-regex-test | Prefer s.includes() / startsWith / endsWith over /literal/.test(s) when the regex has no metacharacters or flags | ✖️ | ✅ | ✖️ |
| prefer-charcode-at-in-loop | Prefer charCodeAt() over indexed string access for single-character comparisons inside loops | ✖️ | 💡 | 🔶 |
| prefer-throw-if-no-entry | Prefer {throwIfNoEntry: false} over relying on a thrown error for missing fs entries from sync stat calls | ✖️ | 💡 | ✖️ |
| no-delete-property | Disallow delete on properties — V8 deoptimizes the object to dictionary mode | ✖️ | 💡 | ✖️ |
| prefer-flatmap-over-map-flat | Prefer Array.prototype.flatMap() over .map(fn).flat() to skip the intermediate array | ✖️ | ✅ | ✖️ |
| prefer-slice-over-split-index | Prefer indexOf(needle) and slice(...) over split()[N] when splitting a string into two pieces | ✖️ | ✖️ | ✖️ |
| no-spread-in-reduce | Disallow spreading the accumulator inside a .reduce() callback — it's O(N²) | ✖️ | ✖️ | ✖️ |
| prefer-static-collator | Prefer hoisting an Intl.Collator over calling localeCompare inside a sort/toSorted callback | ✖️ | ✖️ | ✖️ |
MIT
TypeScript
99.8%
The official e18e ESLint plugin for modernizing JavaScript/TypeScript code and improving performance.
This plugin focuses on applying the e18e community's best practices and advise to JavaScript/TypeScript codebases.
There are a few categories of rules in this plugin:
Each of these can be enabled individually, or you can use the recommended configuration to enable all rules.
npm install --save-dev @e18e/eslint-plugin
Add the plugin to your eslint.config.js:
import e18e from '@e18e/eslint-plugin';
export default [
// Use the recommended configuration (includes all categories)
e18e.configs.recommended,
// Or use specific category configurations
e18e.configs.modernization,
e18e.configs.moduleReplacements,
e18e.configs.performanceImprovements,
// Or configure rules manually
{
plugins: {
e18e
},
rules: {
'e18e/prefer-array-at': 'error',
'e18e/prefer-array-fill': 'error',
'e18e/prefer-includes': 'error'
}
}
];
If you're using oxlint, you can enable the e18e plugin by adding it to your .oxlintrc.json file:
{
"jsPlugins": ["@e18e/eslint-plugin"],
"rules": {
"e18e/prefer-includes": "error"
}
}
You can enable the recommended configuration by copying the rules from each of the ESLint configuration files into your .oxlintrc.json file.
Copying these rules into your rules object will achieve the same effect as using the recommended configuration in ESLint.
[!NOTE] Our type-aware rules depend on TypeScript ESLint's parser, which means they will not work with oxlint at this time.
package.jsonSome rules (e.g. ban-dependencies) can be used against your package.json.
You can achieve this by using @eslint/json or jsonc-eslint-parser.
For example, with @eslint/json and eslint.config.js:
import e18e from '@e18e/eslint-plugin';
import json from '@eslint/json';
import {defineConfig} from 'eslint/config';
export default defineConfig([
{
files: ['package.json'],
language: 'json/json',
plugins: {
e18e,
json
},
extends: ['e18e/recommended'],
}
]);
Or with jsonc-eslint-parser and eslint.config.js:
import e18e from '@e18e/eslint-plugin';
import jsonParser from 'jsonc-eslint-parser';
import {defineConfig} from 'eslint/config';
export default defineConfig([
{
files: ['package.json'],
languageOptions: {
parser: jsonParser
},
plugins: {
e18e
},
extends: ['e18e/recommended'],
}
]);
Read more at the
@eslint/json docs and
jsonc-eslint-parser docs.
Legend:
| Rule | Description | Recommended | Fixable | Requires Types |
|---|---|---|---|---|
| prefer-array-at | Prefer Array.prototype.at() over length-based indexing | ✅ | ✅ | 🔶 |
| prefer-array-fill | Prefer Array.prototype.fill() over Array.from() or map() with constant values | ✅ | ✅ | ✖️ |
| prefer-includes | Prefer .includes() over indexOf() comparisons for arrays and strings | ✅ | ✅ | ✖️ |
| prefer-array-to-reversed | Prefer Array.prototype.toReversed() over copying and reversing arrays | ✅ | ✅ | 🔶 |
| prefer-array-to-sorted | Prefer Array.prototype.toSorted() over copying and sorting arrays | ✅ | ✅ | 🔶 |
| prefer-array-to-spliced | Prefer Array.prototype.toSpliced() over copying and splicing arrays | ✅ | ✅ | ✖️ |
| prefer-exponentiation-operator | Prefer the exponentiation operator ** over Math.pow() | ✅ | ✅ | ✖️ |
| prefer-nullish-coalescing | Prefer nullish coalescing operator (?? and ??=) over verbose null checks | ✅ | ✅ | ✖️ |
| prefer-object-has-own | Prefer Object.hasOwn() over Object.prototype.hasOwnProperty.call() and obj.hasOwnProperty() | ✅ | ✅ | ✖️ |
| prefer-spread-syntax | Prefer spread syntax over Array.concat(), Array.from(), Object.assign({}, ...), and Function.apply() | ✅ | ✅ | 🔶 |
| prefer-url-canparse | Prefer URL.canParse() over try-catch blocks for URL validation | ✅ | 💡 | ✖️ |
| prefer-get-or-insert | Prefer Map.prototype.getOrInsert() over reading a map entry with a default and writing it back | ✖️ | ✅ | ✖️ |
| Rule | Description | Recommended | Fixable | Requires Types |
|---|---|---|---|---|
| ban-dependencies | Disallow dependencies in favor of more performant or secure alternatives | ✅ | ✖️ | ✖️ |
| Rule | Description | Recommended | Fixable | Requires Types |
|---|---|---|---|---|
| no-indexof-equality | Prefer startsWith() for strings and direct array access over indexOf() equality checks | ✖️ | ✅ | ✅ |
| prefer-array-from-map | Prefer Array.from(iterable, mapper) over [...iterable].map(mapper) to avoid intermediate array allocation | ✅ | ✅ | ✖️ |
| prefer-array-some | Prefer Array.some() over Array.find() and Array.filter().length checks when checking for element existence | ✅ | ✅ | ✖️ |
| prefer-timer-args | Prefer passing function and arguments directly to setTimeout/setInterval instead of wrapping in an arrow function or using bind | ✅ | ✅ | ✖️ |
| prefer-date-now | Prefer Date.now() over new Date().getTime() and +new Date() | ✅ | ✅ | ✖️ |
| prefer-regex-test | Prefer RegExp.test() over String.match() and RegExp.exec() when only checking for match existence | ✅ | ✅ | 🔶 |
| prefer-static-regex | Prefer defining regular expressions at module scope to avoid re-compilation on every function call | ✅ | ✖️ | 🔶 |
| prefer-inline-equality | Prefer inline equality checks over temporary object creation for simple comparisons | ✖️ | ✅ | 🔶 |
| prefer-string-fromcharcode | Prefer String.fromCharCode() over String.fromCodePoint() for code points below 0x10000 | ✅ | ✅ | ✖️ |
| prefer-includes-over-regex-test | Prefer s.includes() / startsWith / endsWith over /literal/.test(s) when the regex has no metacharacters or flags | ✖️ | ✅ | ✖️ |
| prefer-charcode-at-in-loop | Prefer charCodeAt() over indexed string access for single-character comparisons inside loops | ✖️ | 💡 | 🔶 |
| prefer-throw-if-no-entry | Prefer {throwIfNoEntry: false} over relying on a thrown error for missing fs entries from sync stat calls | ✖️ | 💡 | ✖️ |
| no-delete-property | Disallow delete on properties — V8 deoptimizes the object to dictionary mode | ✖️ | 💡 | ✖️ |
| prefer-flatmap-over-map-flat | Prefer Array.prototype.flatMap() over .map(fn).flat() to skip the intermediate array | ✖️ | ✅ | ✖️ |
| prefer-slice-over-split-index | Prefer indexOf(needle) and slice(...) over split()[N] when splitting a string into two pieces | ✖️ | ✖️ | ✖️ |
| no-spread-in-reduce | Disallow spreading the accumulator inside a .reduce() callback — it's O(N²) | ✖️ | ✖️ | ✖️ |
| prefer-static-collator | Prefer hoisting an Intl.Collator over calling localeCompare inside a sort/toSorted callback | ✖️ | ✖️ | ✖️ |
MIT
TypeScript
99.8%