@putout/plugin-eslint
v9.1.0
Published
🐊Putout plugin for eslint config
Downloads
57,589
Maintainers
Readme
@putout/plugin-eslint
Find and fix problems in your JavaScript code
(c) eslint.org
🐊Putout plugin helps to automate fixing ESLint config.
Install
npm i @putout/plugin-eslint -D
Rules
- ✅ add-putout;
- ✅ apply-dir-to-flat;
- ✅ apply-match-to-flat;
- ✅ apply-safe-align;
- ✅ convert-export-match-to-declaration;
- ✅ convert-files-to-array;
- ✅ convert-ide-to-safe;
- ✅ convert-node-to-n;
- ✅ convert-plugins-array-to-object;
- ✅ convert-rc-to-flat;
- ✅ convert-require-to-import;
- ✅ declare;
- ✅ move-putout-to-end-of-extends;
- ✅ remove-no-missing;
- ✅ remove-no-unpublished-require;
- ✅ remove-no-unsupported-features;
- ✅ remove-overrides-with-empty-rules;
- ✅ remove-useless-slice;
- ✅ remove-useless-properties;
Config
{
"rules": {
"eslint/add-putout": "on",
"eslint/apply-dir-to-flat": "on",
"eslint/apply-safe-align": "on",
"eslint/apply-match-to-flat": "on",
"eslint/move-putout-to-end-of-extends": "on",
"eslint/convert-export-match-to-decleration": "on",
"eslint/convert-files-to-array": "on",
"eslint/convert-ide-to-safe": "on",
"eslint/convert-require-to-import": "on",
"eslint/convert-node-to-n": "on",
"eslint/declare": "on",
"eslint/remove-no-missing": "on",
"eslint/remove-no-unpublished-require": "on",
"eslint/remove-no-unsupported-features": "on",
"eslint/remove-overrides-with-empty-rules": "on",
"eslint/remove-useless-slice": "on",
"eslint/remove-useless-properties": "on",
"eslint/convert-plugins-array-to-object": "on",
"eslint/convert-rc-to-flat": "off"
}
}
add-putout
{
"extends": [
+ "plugin:putout/safe+align",
"plugin:node/recommended"
],
"plugins": [
+ "putout",
"node"
]
}
apply-safe-align
{
- "rules": {
- "putout/align-spaces": "error"
- },
"extends": [
- "plugin:putout/safe",
+ "plugin:putout/safe+align",
"plugin:node/recommended"
],
"plugins": [
"putout",
"node"
]
}
apply-dir-to-flat
matchToFlatDir()
and mergeESLintConfigs
supports __dirname
or import.meta.url
starting from v2
of @putout/eslint-flat
.
Check out in 🐊Putout Editor.
❌ Example of incorrect code
const scriptsConfig = await matchToFlatDir('scripts');
const monoConfig = await mergeESLintConfigs(['codemods', 'packages', 'rules']);
module.exports = [
...scriptsConfig,
...monoConfig,
];
✅ Example of correct code
// CommonJS
const scriptsConfig = await matchToFlatDir(__dirname, 'scripts');
// ESM
const monoConfig = await mergeESLintConfigs(import.meta.url, ['codemods', 'packages', 'rules']);
module.exports = [
...scriptsConfig,
...monoConfig,
];
apply-match-to-flat
Check out in 🐊Putout Editor.
❌ Example of incorrect code
import {safeAlign} from 'eslint-plugin-putout/config';
export default [
...safeAlign, {
files: ['*.d.ts'],
rules: {
'no-var': 'off',
},
}, {
files: ['*.spec.*'],
rules: {
'node/no-extraneous-import': 'off',
},
},
];
✅ Example of correct code
import {safeAlign} from 'eslint-plugin-putout/config';
const config = matchToFlat({
'*.d.ts': {
'no-var': 'off',
},
'*.spec.*': {
'node/no-extraneous-import': 'off',
},
});
export default [
...safeAlign,
...config,
];
move-putout-to-end-of-extends
❌ Example of incorrect code
{
"extends": [
"plugin:putout/recommended",
"plugin:node/recommended"
],
"plugins": [
"putout",
"node"
]
}
✅ Example of correct code
{
"extends": [
"plugin:node/recommended",
"plugin:putout/recommended"
],
"plugins": [
"putout",
"node"
]
}
convert-ide-to-safe
❌ Example of incorrect code
{
"extends": [
"plugin:node/recommended",
"plugin:putout/ide"
],
"plugins": [
"putout",
"node"
]
}
✅ Example of correct code
{
"extends": [
"plugin:node/recommended",
"plugin:putout/safe"
],
"plugins": [
"putout",
"node"
]
}
convert-files-to-array
Check it out in 🐊Putout Editor.
{
"overrides": [{
- "files": "test/*.js",
+ "files": ["test/*.js"],
"rules": {
"node/no-missing-require": "off"
}
}],
};
convert-require-to-import
node/no-missing-require
has no sense when type=module
in package.json
.
Check it out in 🐊Putout Editor.
{
"overrides": [{
"files": "test/*.js",
"rules": {
- "node/no-missing-require": "off"
+ "node/no-missing-import": "off"
}
}],
"extends": [
"plugin:node/recommended",
"plugin:putout/recommended"
],
"plugins": [
"putout",
"node"
]
};
remove-no-unpublished-require
node/remove-no-unpublished-require
should be enabled, since this is a very useful rule, which shows what files should be add to .npmignore
.
{
"overrides": [{
"files": "test/*.js",
"rules": {
- "node/no-unpublished-require": "off"
}
}],
"extends": [
"plugin:node/recommended",
"plugin:putout/recommended"
],
"plugins": [
"putout",
"node"
]
};
remove-no-unsupported-features
node/remove-no-unsupported-features
is already disabled in eslint-plugin-putout.
{
"overrides": [{
"files": "test/*.js",
"rules": {
- "node/no-unpublished-require": "off"
}
}],
"extends": [
"plugin:node/recommended",
"plugin:putout/recommended"
],
"plugins": [
"putout",
"node"
]
};
remove-overrides-with-empty-rules
overrides
with rules: {}
has no sense. Check out in 🐊Putout Editor:
Remove overrides
with one element with empty rules
:
{
- "overrides": [{
- "files": "test/*.js",
- "rules": {
- }
- }],
"extends": [
"plugin:node/recommended",
"plugin:putout/recommended"
],
"plugins": [
"putout",
"node"
]
};
Or remove empty overrides
:
{
- "overrides": [],
"extends": [
"plugin:node/recommended",
"plugin:putout/recommended"
],
"plugins": [
"putout",
"node"
]
};
And ofcourse remove only elements with empty rules
:
{
"overrides": [{
- "files": "test/*.js",
- "rules": {
- }
- }, {
"files": "test/*.js",
"rules": {
"no-semi": "off"
}
}],
"extends": [
"plugin:node/recommended",
"plugin:putout/recommended"
],
"plugins": [
"putout",
"node"
]
};
convert-node-to-n
eslint-plugin-node
is no longer supported. Better to use eslint-plugin-n
.
{
"extends": [
"plugin:putout/safe+align",
- "plugin:node/recommended"
+ "plugin:n/recommended"
],
"plugins": [
"putout",
- "node"
+ "n"
]
}
remove-no-missing
node/remove-no-missing-require
and node/remove-no-missing-import
doesn't supports exports
and already disabled by eslint-plugin-putout
.
{
"overrides": [{
"files": "test/*.js",
"rules": {
- "node/no-missing-require": "off",
- "node/no-missing-import": "off"
}
}],
"extends": [
"plugin:node/recommended",
"plugin:putout/recommended"
],
"plugins": [
"putout",
"node"
]
};
remove-useless-slice
Fixes code after convert-array-copy-to-slice
.
Checkout in 🐊Putout Editor.
❌ Example of incorrect code
export default x.slice();
module.exports = x.slice();
✅ Example of correct code
export default x;
module.exports = x;
remove-useless-properties
Checkout in 🐊Putout Editor.
❌ Example of incorrect code
module.exports = [
...safeAlign, {
rules: {},
},
];
✅ Example of correct code
module.exports = safeAlign;
convert-export-match-to-declaration
Fixes apply-match-to-flat. Checkout in 🐊Putout Editor.
❌ Example of incorrect code
module.exports.match = {
'bin/**': {
'no-process-exit': 'off',
},
};
module.exports = [
...safeAlign, {
rules: {
'node/no-unsupported-features/node-builtins': 'off',
},
},
...matchToFlat(match),
];
✅ Example of correct code
const match = {
'bin/**': {
'no-process-exit': 'off',
},
};
module.exports = [
...safeAlign, {
rules: {
'node/no-unsupported-features/node-builtins': 'off',
},
},
...matchToFlat(match),
];
module.exports.match = match;
declare
Declare:
convert-plugins-array-to-object
On the surface, using a plugin in
flat config
looks very similar to using a plugin ineslintrc
. The big difference is thateslintrc
usedstring
s whereasflat configs
usesobject
s. Instead of specifying the name of a plugin, you import the plugin directly and place it into the pluginskey
.(c) eslint.org
Checkout in 🐊Putout Editor.
❌ Example of incorrect code
export default {
plugins: [react],
};
module.exports = {
plugins: ['react'],
};
✅ Example of correct code
export default {
plugins: {
react,
},
};
module.exports = {
plugins: ['react'],
};
convert-rc-to-flat
Checkout in 🐊Putout Editor:
Converts .eslintrc.json
:
{
"root": true,
"parser": "@typescript-eslint/parser",
"env": {
"node": true
},
"extends": ["eslint:recommended"],
"plugins": ["@nx"],
"rules": {
"@typescript-eslint/explicit-module-boundary-types": "error"
},
"overrides": [{
"files": ["*.json"],
"parser": "jsonc-eslint-parser"
}, {
"files": [
"*.ts",
"*.tsx",
"*.js",
"*.jsx"
],
"rules": {
"@nx/enforce-module-boundaries": ["error", {
"enforceBuildableLibDependency": true,
"allow": [],
"depConstraints": [{
"sourceTag": "*",
"onlyDependOnLibsWithTags": ["*"]
}]
}]
}
}]
}
To .eslint.config.js
:
const nxPlugin = require('@nx/eslint-plugin');
const js = require('@eslint/js');
const globals = require('globals');
const jsoncParser = require('jsonc-eslint-parser');
const tsParser = require('@typescript-eslint/parser');
module.exports = [
js.configs.recommended, {
plugins: {
'@nx': nxPlugin,
},
}, {
languageOptions: {
parser: tsParser,
globals: {
...globals.node,
},
},
rules: {
'@typescript-eslint/explicit-module-boundary-types': ['error'],
},
}, {
files: ['*.json'],
languageOptions: {
parser: jsoncParser,
},
rules: {},
}, {
files: [
'*.ts',
'*.tsx',
'*.js',
'*.jsx',
],
rules: {
'@nx/enforce-module-boundaries': ['error', {
enforceBuildableLibDependency: true,
allow: [],
depConstraints: [{
sourceTag: '*',
onlyDependOnLibsWithTags: ['*'],
}],
}],
},
}];
License
MIT