@putout/eslint 2.0.0 → 2.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/lib/create-plugin/index.js +15 -11
- package/lib/eslint.js +12 -9
- package/lib/get-eslint.mjs +0 -1
- package/lib/lint/index.js +13 -4
- package/lib/simple-import.js +0 -1
- package/package.json +2 -1
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const prepare = (plugin, context, options) => (node) => {
|
|
4
|
-
const {
|
|
4
|
+
const {
|
|
5
|
+
filter,
|
|
6
|
+
report,
|
|
7
|
+
} = plugin;
|
|
5
8
|
|
|
6
|
-
const source = context.
|
|
7
|
-
const filename = context
|
|
9
|
+
const source = context.sourceCode;
|
|
10
|
+
const {filename} = context;
|
|
8
11
|
const getText = source.getText.bind(source);
|
|
9
12
|
const getCommentsBefore = source.getCommentsBefore.bind(source);
|
|
10
13
|
const getCommentsAfter = source.getCommentsAfter.bind(source);
|
|
@@ -71,7 +74,10 @@ module.exports.createPlugin = (plugin) => {
|
|
|
71
74
|
create(context) {
|
|
72
75
|
const {options} = context;
|
|
73
76
|
const prepared = prepare(plugin, context, options);
|
|
74
|
-
|
|
77
|
+
|
|
78
|
+
const names = plugin.include({
|
|
79
|
+
options,
|
|
80
|
+
});
|
|
75
81
|
|
|
76
82
|
return getTraversers(names, prepared);
|
|
77
83
|
},
|
|
@@ -108,16 +114,16 @@ const createGetSpacesBeforeNode = ({getText}) => (node, text = getText(node)) =>
|
|
|
108
114
|
let spaces = '';
|
|
109
115
|
let i = 0;
|
|
110
116
|
|
|
111
|
-
if (node === node.parent?.body?.[0]
|
|
117
|
+
if (node === node.parent?.body?.[0]?.expression)
|
|
112
118
|
return '';
|
|
113
119
|
|
|
114
120
|
while (!spaces || /^[ \n]+$/.test(spaces))
|
|
115
|
-
spaces = getText(node, ++i)
|
|
116
|
-
.replace(text, '');
|
|
121
|
+
spaces = getText(node, ++i).replace(text, '');
|
|
117
122
|
|
|
118
123
|
return spaces.slice(1);
|
|
119
124
|
};
|
|
120
|
-
|
|
125
|
+
|
|
126
|
+
module.exports.createGetSpacesBeforeNode = createGetSpacesBeforeNode;
|
|
121
127
|
|
|
122
128
|
const createGetSpacesAfterNode = ({getText}) => (node, text = getText(node)) => {
|
|
123
129
|
const reg = /^[ \n;]+$/;
|
|
@@ -129,8 +135,7 @@ const createGetSpacesAfterNode = ({getText}) => (node, text = getText(node)) =>
|
|
|
129
135
|
let i = 0;
|
|
130
136
|
|
|
131
137
|
while (!spaces || reg.test(spaces))
|
|
132
|
-
spaces = getText(node, 0, ++i)
|
|
133
|
-
.replace(text, '');
|
|
138
|
+
spaces = getText(node, 0, ++i).replace(text, '');
|
|
134
139
|
|
|
135
140
|
return spaces.slice(0, -1);
|
|
136
141
|
};
|
|
@@ -149,4 +154,3 @@ function isLastNodeInBody(node) {
|
|
|
149
154
|
|
|
150
155
|
return false;
|
|
151
156
|
}
|
|
152
|
-
|
package/lib/eslint.js
CHANGED
|
@@ -43,6 +43,7 @@ module.exports = async ({name, code, fix, config, putout = false}) => {
|
|
|
43
43
|
return noChanges;
|
|
44
44
|
|
|
45
45
|
const {getESLint} = ESLint;
|
|
46
|
+
|
|
46
47
|
const [eslintError, eslint] = await tryToCatch(getESLint, {
|
|
47
48
|
name,
|
|
48
49
|
fix,
|
|
@@ -50,11 +51,12 @@ module.exports = async ({name, code, fix, config, putout = false}) => {
|
|
|
50
51
|
overrideConfigFile,
|
|
51
52
|
});
|
|
52
53
|
|
|
53
|
-
if (eslintError)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
[convertToPlace(cutNewLine(eslintError))],
|
|
54
|
+
if (eslintError) {
|
|
55
|
+
const places = [
|
|
56
|
+
convertToPlace(cutNewLine(eslintError)),
|
|
57
57
|
];
|
|
58
|
+
return [code, places];
|
|
59
|
+
}
|
|
58
60
|
|
|
59
61
|
const [configError, finalConfig] = await tryToCatch(eslint.calculateConfigForFile, name);
|
|
60
62
|
|
|
@@ -62,10 +64,10 @@ module.exports = async ({name, code, fix, config, putout = false}) => {
|
|
|
62
64
|
return noChanges;
|
|
63
65
|
|
|
64
66
|
if (configError) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
[convertToPlace(parseError(configError))],
|
|
67
|
+
const places = [
|
|
68
|
+
convertToPlace(parseError(configError)),
|
|
68
69
|
];
|
|
70
|
+
return [code, places];
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
!putout && disablePutout(finalConfig);
|
|
@@ -81,7 +83,9 @@ module.exports = async ({name, code, fix, config, putout = false}) => {
|
|
|
81
83
|
|
|
82
84
|
const [report] = results;
|
|
83
85
|
const {output} = report;
|
|
84
|
-
|
|
86
|
+
|
|
87
|
+
const places = report
|
|
88
|
+
.messages
|
|
85
89
|
.map(convertToPlace)
|
|
86
90
|
.filter(Boolean);
|
|
87
91
|
|
|
@@ -141,4 +145,3 @@ function parseError(e) {
|
|
|
141
145
|
message: `Plugin missing: ${messageData.pluginName}`,
|
|
142
146
|
};
|
|
143
147
|
}
|
|
144
|
-
|
package/lib/get-eslint.mjs
CHANGED
package/lib/lint/index.js
CHANGED
|
@@ -12,6 +12,7 @@ module.exports.lint = (source, {fix = true, plugins, filename, options = []}) =>
|
|
|
12
12
|
|
|
13
13
|
if (plugins) {
|
|
14
14
|
const [name, plugin] = plugins[0];
|
|
15
|
+
|
|
15
16
|
allOptions.push({
|
|
16
17
|
rules: {
|
|
17
18
|
[`${name}/plugin`]: 'error',
|
|
@@ -34,12 +35,20 @@ module.exports.lint = (source, {fix = true, plugins, filename, options = []}) =>
|
|
|
34
35
|
mainOptions.filename = filename;
|
|
35
36
|
|
|
36
37
|
if (!fix) {
|
|
37
|
-
const places = linter
|
|
38
|
+
const places = linter
|
|
39
|
+
.verify(source, allOptions, mainOptions)
|
|
40
|
+
.map(convertToPlace);
|
|
41
|
+
|
|
38
42
|
return [source, places];
|
|
39
43
|
}
|
|
40
44
|
|
|
41
|
-
const {
|
|
45
|
+
const {
|
|
46
|
+
output,
|
|
47
|
+
messages,
|
|
48
|
+
} = linter.verifyAndFix(source, allOptions, mainOptions);
|
|
42
49
|
|
|
43
|
-
return [
|
|
50
|
+
return [
|
|
51
|
+
output,
|
|
52
|
+
messages.map(convertToPlace),
|
|
53
|
+
];
|
|
44
54
|
};
|
|
45
|
-
|
package/lib/simple-import.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/eslint",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.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",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"eslint"
|
|
38
38
|
],
|
|
39
39
|
"devDependencies": {
|
|
40
|
+
"@putout/plugin-eslint-plugin": "*",
|
|
40
41
|
"c8": "^7.5.0",
|
|
41
42
|
"eslint": "^8.0.1",
|
|
42
43
|
"eslint-plugin-n": "^15.2.4",
|