@putout/eslint 3.9.0 β 4.1.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/README.md +6 -6
- package/lib/eslint.js +1 -13
- package/lib/get-eslint.mjs +14 -86
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -50,27 +50,27 @@ Isn't it looks similar to π**Putout** way? It definitely is! But... It has a
|
|
|
50
50
|
And you can even override any of **ESLint** βοΈ options with help of `config` property:
|
|
51
51
|
|
|
52
52
|
```js
|
|
53
|
+
import {safeAlign} from 'eslint-plugin-putout';
|
|
54
|
+
|
|
53
55
|
const [source, places] = await eslint({
|
|
54
56
|
name: 'hello.js',
|
|
55
57
|
code: `const t = 'hi'\n`,
|
|
56
58
|
fix: false,
|
|
57
|
-
config:
|
|
58
|
-
extends: ['plugin:putout/recommended'],
|
|
59
|
-
},
|
|
59
|
+
config: [safeAlign],
|
|
60
60
|
});
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
If you want to apply π**Putout** transformations using [`putout/putout`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#readme) **ESLint** rule, enable π**Putout** with the same called but lowercased flag:
|
|
64
64
|
|
|
65
65
|
```js
|
|
66
|
+
import {safeAlign} from 'eslint-plugin-putout';
|
|
67
|
+
|
|
66
68
|
const [source, places] = await eslint({
|
|
67
69
|
name: 'hello.js',
|
|
68
70
|
code: `const t = 'hi'\n`,
|
|
69
71
|
fix: true,
|
|
70
72
|
putout: true,
|
|
71
|
-
config:
|
|
72
|
-
extends: ['plugin:putout/recommended'],
|
|
73
|
-
},
|
|
73
|
+
config: [safeAlign],
|
|
74
74
|
});
|
|
75
75
|
```
|
|
76
76
|
|
package/lib/eslint.js
CHANGED
|
@@ -40,10 +40,6 @@ const noConfigFound = (config, configError) => {
|
|
|
40
40
|
return !keys(config.rules).length;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
const cutNewLine = ({message}) => ({
|
|
44
|
-
message: message.replace(/\n.*/, ''),
|
|
45
|
-
});
|
|
46
|
-
|
|
47
43
|
module.exports = async ({name, code, fix, config, putout = false}) => {
|
|
48
44
|
const noChanges = [
|
|
49
45
|
code,
|
|
@@ -60,21 +56,13 @@ module.exports = async ({name, code, fix, config, putout = false}) => {
|
|
|
60
56
|
|
|
61
57
|
const {getESLint} = ESLint;
|
|
62
58
|
|
|
63
|
-
const
|
|
59
|
+
const eslint = await getESLint({
|
|
64
60
|
name,
|
|
65
61
|
fix,
|
|
66
62
|
config,
|
|
67
63
|
overrideConfigFile,
|
|
68
64
|
});
|
|
69
65
|
|
|
70
|
-
if (eslintError) {
|
|
71
|
-
const places = [
|
|
72
|
-
convertToPlace(cutNewLine(eslintError)),
|
|
73
|
-
];
|
|
74
|
-
|
|
75
|
-
return [code, places];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
66
|
const [configError, finalConfig] = await tryToCatch(eslint.calculateConfigForFile, name);
|
|
79
67
|
|
|
80
68
|
if (noConfigFound(finalConfig, configError))
|
package/lib/get-eslint.mjs
CHANGED
|
@@ -1,67 +1,14 @@
|
|
|
1
1
|
import {dirname} from 'node:path';
|
|
2
2
|
import process from 'node:process';
|
|
3
3
|
import {loadESLint} from 'eslint';
|
|
4
|
-
import {findUp} from 'find-up';
|
|
5
4
|
|
|
5
|
+
const {isArray} = Array;
|
|
6
|
+
const maybeArray = (a) => isArray(a) ? a : [a];
|
|
6
7
|
const CWD = process.cwd();
|
|
7
8
|
|
|
8
|
-
export const getESLint = async ({name, fix, config
|
|
9
|
+
export const getESLint = async ({name, fix, config = [], overrideConfigFile, loadESLintOverride = loadESLint}) => {
|
|
9
10
|
const cwd = dirname(name).replace(/^\./, CWD);
|
|
10
|
-
const eslint = await chooseESLint({
|
|
11
|
-
fix,
|
|
12
|
-
cwd,
|
|
13
|
-
config,
|
|
14
|
-
overrideConfigFile,
|
|
15
|
-
loadESLintOverride,
|
|
16
|
-
findFlat,
|
|
17
|
-
findRC,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
calculateConfigForFile: eslint.calculateConfigForFile.bind(eslint),
|
|
22
|
-
lintText: eslint.lintText.bind(eslint),
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
async function chooseESLint({cwd, config, fix, overrideConfigFile, loadESLintOverride, findFlat, findRC}) {
|
|
27
|
-
const runESLint = await getESLintRunner({
|
|
28
|
-
cwd,
|
|
29
|
-
overrideConfigFile,
|
|
30
|
-
findFlat,
|
|
31
|
-
findRC,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
return await runESLint({
|
|
35
|
-
loadESLintOverride,
|
|
36
|
-
cwd,
|
|
37
|
-
config,
|
|
38
|
-
overrideConfigFile,
|
|
39
|
-
fix,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async function getOldESLint({cwd, fix, config, overrideConfigFile, loadESLintOverride = loadESLint}) {
|
|
44
|
-
const ESLint = await loadESLintOverride({
|
|
45
|
-
useFlatConfig: false,
|
|
46
|
-
});
|
|
47
11
|
|
|
48
|
-
const eslint = new ESLint({
|
|
49
|
-
cwd,
|
|
50
|
-
fix,
|
|
51
|
-
overrideConfig: {
|
|
52
|
-
ignorePatterns: ['!.*'],
|
|
53
|
-
...config,
|
|
54
|
-
},
|
|
55
|
-
...overrideConfigFile && {
|
|
56
|
-
overrideConfigFile,
|
|
57
|
-
useEslintrc: false,
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
return eslint;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async function getFlatESLint({cwd, fix, config, overrideConfigFile, loadESLintOverride = loadESLint}) {
|
|
65
12
|
const FlatESLint = await loadESLintOverride({
|
|
66
13
|
useFlatConfig: true,
|
|
67
14
|
});
|
|
@@ -69,38 +16,19 @@ async function getFlatESLint({cwd, fix, config, overrideConfigFile, loadESLintOv
|
|
|
69
16
|
const eslint = new FlatESLint({
|
|
70
17
|
cwd,
|
|
71
18
|
fix,
|
|
72
|
-
overrideConfig:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
19
|
+
overrideConfig: [
|
|
20
|
+
...maybeArray(config), {
|
|
21
|
+
ignores: ['!.*'],
|
|
22
|
+
}
|
|
23
|
+
,
|
|
24
|
+
],
|
|
76
25
|
...overrideConfigFile && {
|
|
77
26
|
overrideConfigFile,
|
|
78
27
|
},
|
|
79
28
|
});
|
|
80
29
|
|
|
81
|
-
return
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
async function getESLintRunner({cwd, findFlat, findRC, overrideConfigFile}) {
|
|
87
|
-
if (overrideConfigFile)
|
|
88
|
-
return isFlat(overrideConfigFile) ? getFlatESLint : getOldESLint;
|
|
89
|
-
|
|
90
|
-
const [rcConfig = '', flatConfig = ''] = await Promise.all([
|
|
91
|
-
findRC(['.eslintrc.json', '.eslintrc.js'], {
|
|
92
|
-
cwd,
|
|
93
|
-
}),
|
|
94
|
-
findFlat(['eslint.config.js', 'eslint.config.mjs', 'eslint.config.cjs'], {
|
|
95
|
-
cwd,
|
|
96
|
-
}),
|
|
97
|
-
]);
|
|
98
|
-
|
|
99
|
-
const noConfigFound = !rcConfig && !flatConfig;
|
|
100
|
-
const foundRConfig = rcConfig.length > flatConfig.length;
|
|
101
|
-
|
|
102
|
-
if (noConfigFound || foundRConfig)
|
|
103
|
-
return getOldESLint;
|
|
104
|
-
|
|
105
|
-
return getFlatESLint;
|
|
106
|
-
}
|
|
30
|
+
return {
|
|
31
|
+
calculateConfigForFile: eslint.calculateConfigForFile.bind(eslint),
|
|
32
|
+
lintText: eslint.lintText.bind(eslint),
|
|
33
|
+
};
|
|
34
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/eslint",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.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",
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"report": "madrun report"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"find-up": "^7.0.0",
|
|
33
32
|
"once": "^1.4.0",
|
|
34
33
|
"try-to-catch": "^3.0.1"
|
|
35
34
|
},
|
|
@@ -38,12 +37,12 @@
|
|
|
38
37
|
"eslint"
|
|
39
38
|
],
|
|
40
39
|
"devDependencies": {
|
|
40
|
+
"@putout/eslint-flat": "^2.0.0",
|
|
41
41
|
"@putout/plugin-eslint-plugin": "*",
|
|
42
42
|
"c8": "^10.0.0",
|
|
43
43
|
"eslint": "^9.0.0",
|
|
44
44
|
"eslint-plugin-n": "^17.0.0",
|
|
45
|
-
"eslint-plugin-putout": "^
|
|
46
|
-
"lerna": "^6.0.1",
|
|
45
|
+
"eslint-plugin-putout": "^25.0.1",
|
|
47
46
|
"madrun": "^10.0.0",
|
|
48
47
|
"mock-require": "^3.0.3",
|
|
49
48
|
"montag": "^1.0.0",
|