@putout/eslint 3.0.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/create-plugin/index.js +1 -2
- package/lib/eslint.js +5 -1
- package/lib/get-eslint.mjs +50 -25
- package/package.json +5 -5
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const prepare = (plugin, context, options) => (node) => {
|
|
4
4
|
const {filter, report} = plugin;
|
|
5
|
-
|
|
6
5
|
const {sourceCode, filename} = context;
|
|
7
6
|
|
|
8
7
|
const getText = sourceCode.getText.bind(sourceCode);
|
|
@@ -95,7 +94,7 @@ function getMeta(plugin) {
|
|
|
95
94
|
docs: {
|
|
96
95
|
recommended,
|
|
97
96
|
},
|
|
98
|
-
schema:
|
|
97
|
+
schema: false,
|
|
99
98
|
fixable,
|
|
100
99
|
};
|
|
101
100
|
}
|
package/lib/eslint.js
CHANGED
|
@@ -19,6 +19,9 @@ const noConfigFound = (config, configError) => {
|
|
|
19
19
|
if (configError)
|
|
20
20
|
return false;
|
|
21
21
|
|
|
22
|
+
if (!config)
|
|
23
|
+
return true;
|
|
24
|
+
|
|
22
25
|
return !keys(config.rules).length;
|
|
23
26
|
};
|
|
24
27
|
|
|
@@ -70,8 +73,9 @@ module.exports = async ({name, code, fix, config, putout = false}) => {
|
|
|
70
73
|
return [code, places];
|
|
71
74
|
}
|
|
72
75
|
|
|
76
|
+
// that's right, we disabled "putout" rules in "config"
|
|
77
|
+
// and now it located in eslint's cache
|
|
73
78
|
!putout && disablePutout(finalConfig);
|
|
74
|
-
// that's right, we disabled "putout" rules in "config" // and now it located in eslint's cache
|
|
75
79
|
|
|
76
80
|
const results = await eslint.lintText(code, {
|
|
77
81
|
filePath: name,
|
package/lib/get-eslint.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import {dirname} from 'node:path';
|
|
2
|
+
import {loadESLint} from 'eslint';
|
|
3
|
+
import {findUp} from 'find-up';
|
|
3
4
|
|
|
4
|
-
const {
|
|
5
|
-
|
|
6
|
-
export const getESLint = ({name, fix, config, overrideConfigFile, ESLintOverride, find = findUpSync}) => {
|
|
7
|
-
const eslint = chooseESLint({
|
|
5
|
+
export const getESLint = async ({name, fix, config, overrideConfigFile, loadESLintOverride, find = findUp, findFlat = find, findRC = find}) => {
|
|
6
|
+
const eslint = await chooseESLint({
|
|
8
7
|
fix,
|
|
9
8
|
name,
|
|
10
9
|
config,
|
|
11
10
|
overrideConfigFile,
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
loadESLintOverride,
|
|
12
|
+
findFlat,
|
|
13
|
+
findRC,
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
return {
|
|
@@ -19,29 +19,28 @@ export const getESLint = ({name, fix, config, overrideConfigFile, ESLintOverride
|
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
function chooseESLint({name, config, fix, overrideConfigFile,
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
name,
|
|
29
|
-
config,
|
|
30
|
-
overrideConfigFile: overrideConfigFile || flatConfigPath,
|
|
31
|
-
fix,
|
|
32
|
-
});
|
|
22
|
+
async function chooseESLint({name, config, fix, overrideConfigFile, loadESLintOverride, findFlat, findRC}) {
|
|
23
|
+
const runESLint = await getESLintRunner(name, {
|
|
24
|
+
overrideConfigFile,
|
|
25
|
+
findFlat,
|
|
26
|
+
findRC,
|
|
27
|
+
});
|
|
33
28
|
|
|
34
|
-
return
|
|
29
|
+
return await runESLint({
|
|
30
|
+
loadESLintOverride,
|
|
35
31
|
name,
|
|
36
32
|
config,
|
|
37
|
-
ESLintOverride,
|
|
38
33
|
overrideConfigFile,
|
|
39
34
|
fix,
|
|
40
35
|
});
|
|
41
36
|
}
|
|
42
37
|
|
|
43
|
-
function getOldESLint({fix, config, overrideConfigFile,
|
|
44
|
-
const
|
|
38
|
+
async function getOldESLint({fix, config, overrideConfigFile, loadESLintOverride = loadESLint}) {
|
|
39
|
+
const ESLint = await loadESLintOverride({
|
|
40
|
+
useFlatConfig: false,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const eslint = new ESLint({
|
|
45
44
|
fix,
|
|
46
45
|
overrideConfig: {
|
|
47
46
|
ignorePatterns: ['!.*'],
|
|
@@ -56,8 +55,12 @@ function getOldESLint({fix, config, overrideConfigFile, ESLintOverride = LegacyE
|
|
|
56
55
|
return eslint;
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
function getFlatESLint({fix, config, overrideConfigFile,
|
|
60
|
-
const
|
|
58
|
+
async function getFlatESLint({fix, config, overrideConfigFile, loadESLintOverride = loadESLint}) {
|
|
59
|
+
const FlatESLint = await loadESLintOverride({
|
|
60
|
+
useFlatConfig: true,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const eslint = new FlatESLint({
|
|
61
64
|
fix,
|
|
62
65
|
overrideConfig: {
|
|
63
66
|
ignores: ['!.*'],
|
|
@@ -70,3 +73,25 @@ function getFlatESLint({fix, config, overrideConfigFile, ESLintOverride = FlatES
|
|
|
70
73
|
|
|
71
74
|
return eslint;
|
|
72
75
|
}
|
|
76
|
+
|
|
77
|
+
const isFlat = (a) => a?.includes('config');
|
|
78
|
+
|
|
79
|
+
async function getESLintRunner(name, {findFlat, findRC, overrideConfigFile}) {
|
|
80
|
+
if (overrideConfigFile)
|
|
81
|
+
return isFlat(overrideConfigFile) ? getFlatESLint : getOldESLint;
|
|
82
|
+
|
|
83
|
+
const cwd = dirname(name);
|
|
84
|
+
const [rcConfig = '', flatConfig = ''] = await Promise.all([
|
|
85
|
+
findRC(['.eslintrc.json', '.eslintrc.js'], {
|
|
86
|
+
cwd,
|
|
87
|
+
}),
|
|
88
|
+
findFlat('eslint.config.js', 'eslint.config.mjs', 'eslint.config.cjs', {
|
|
89
|
+
cwd,
|
|
90
|
+
}),
|
|
91
|
+
]);
|
|
92
|
+
|
|
93
|
+
if (rcConfig.length > flatConfig.length)
|
|
94
|
+
return getOldESLint;
|
|
95
|
+
|
|
96
|
+
return getFlatESLint;
|
|
97
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/eslint",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Wrapper that simplifies ESLint API and makes it compatible with 🐊Putout",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
],
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@putout/plugin-eslint-plugin": "*",
|
|
41
|
-
"c8": "^
|
|
42
|
-
"eslint": "^
|
|
43
|
-
"eslint-plugin-n": "^
|
|
41
|
+
"c8": "^9.0.0",
|
|
42
|
+
"eslint": "^9.0.0",
|
|
43
|
+
"eslint-plugin-n": "^17.0.0",
|
|
44
44
|
"eslint-plugin-putout": "^22.0.0",
|
|
45
45
|
"just-camel-case": "^4.0.2",
|
|
46
46
|
"lerna": "^6.0.1",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"montag": "^1.0.0",
|
|
50
50
|
"nodemon": "^3.0.1",
|
|
51
51
|
"putout": "*",
|
|
52
|
-
"supertape": "^
|
|
52
|
+
"supertape": "^10.0.0",
|
|
53
53
|
"try-catch": "^3.0.0"
|
|
54
54
|
},
|
|
55
55
|
"license": "MIT",
|