The official e18e ESLint plugin for modernizing code and improving performance.
npm install @e18e/eslint-plugin> 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:
- Modernization - New syntax and APIs which improve code readability and performance
- Module replacements - Community recommended alternatives to popular libraries, focused on performance and size
- Performance improvements - Patterns that can be optimized for better runtime performance
Each of these can be enabled individually, or you can use the recommended configuration to enable all rules.
``bash`
npm install --save-dev @e18e/eslint-plugin
Add the plugin to your eslint.config.js:
`ts
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:
`json`
{
"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.
- modernization configuration
- module replacements configuration
- performance improvements configuration
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.
Some 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:
`ts
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:
`ts
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:
- ✅ = Yes / Enabled
- ✖️ = No / Disabled
- 💡 = Has suggestions (requires user confirmation for fixes)
- 🔶 = Optionally uses types (works without TypeScript but more powerful with it)
| Rule | Description | Recommended | Fixable | Requires Types |
|------|-------------|-------------|---------|----------------|
| prefer-array-at | Prefer Array.prototype.at() over length-based indexing | ✅ | ✅ | 🔶 |Array.prototype.fill()
| prefer-array-fill | Prefer over Array.from() or map() with constant values | ✅ | ✅ | ✖️ |.includes()
| prefer-includes | Prefer over indexOf() comparisons for arrays and strings | ✅ | ✅ | ✖️ |Array.prototype.toReversed()
| prefer-array-to-reversed | Prefer over copying and reversing arrays | ✅ | ✅ | ✖️ |Array.prototype.toSorted()
| prefer-array-to-sorted | Prefer over copying and sorting arrays | ✅ | ✅ | ✖️ |Array.prototype.toSpliced()
| prefer-array-to-spliced | Prefer 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 | ✅ | ✅ | ✖️ |Object.hasOwn()
| prefer-object-has-own | Prefer over Object.prototype.hasOwnProperty.call() and obj.hasOwnProperty() | ✅ | ✅ | ✖️ |Array.concat()
| prefer-spread-syntax | Prefer spread syntax over , Array.from(), Object.assign({}, ...), and Function.apply() | ✅ | ✅ | ✖️ |URL.canParse()
| prefer-url-canparse | Prefer over try-catch blocks for URL validation | ✅ | 💡 | ✖️ |
| Rule | Description | Recommended | Fixable | Requires Types |
|------|-------------|-------------|---------|----------------|
| ban-dependencies | Ban dependencies in favor of lighter alternatives | ✅ | ✖️ | ✖️ |
| Rule | Description | Recommended | Fixable | Requires Types |
|------|-------------|-------------|---------|----------------|
| no-indexof-equality | Prefer startsWith() for strings and direct array access over indexOf() equality checks | ✖️ | ✅ | ✅ |Array.from(iterable, mapper)
| prefer-array-from-map | Prefer over [...iterable].map(mapper) to avoid intermediate array allocation | ✅ | ✅ | ✖️ |Array.some()
| prefer-array-some | Prefer over Array.find() when checking for element existence | ✅ | ✅ | ✖️ |setTimeout
| prefer-timer-args | Prefer passing function and arguments directly to /setInterval instead of wrapping in an arrow function or using bind | ✅ | ✅ | ✖️ |Date.now()
| prefer-date-now | Prefer over new Date().getTime() and +new Date() | ✅ | ✅ | ✖️ |RegExp.test()
| prefer-regex-test | Prefer over String.match() and RegExp.exec()` when only checking for match existence | ✅ | ✅ | 🔶 |
MIT