eslint-plugin-putout 14.6.0 → 14.8.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 +4 -0
- package/lib/markdown.js +5 -1
- package/lib/putout/index.js +14 -43
- package/package.json +1 -1
package/README.md
CHANGED
package/lib/markdown.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const parserOpts = require('@putout/engine-parser/babel/options');
|
|
4
|
+
const parserPlugins = require('@putout/engine-parser/babel/plugins');
|
|
4
5
|
const [ts] = require('./ts');
|
|
5
6
|
|
|
6
7
|
const commonRules = {
|
|
@@ -28,7 +29,10 @@ module.exports = [{
|
|
|
28
29
|
requireConfigFile: false,
|
|
29
30
|
babelOptions: {
|
|
30
31
|
sourceType: 'module',
|
|
31
|
-
parserOpts
|
|
32
|
+
parserOpts: {
|
|
33
|
+
...parserOpts,
|
|
34
|
+
plugins: parserPlugins,
|
|
35
|
+
},
|
|
32
36
|
plugins: [
|
|
33
37
|
'@babel/plugin-syntax-class-properties',
|
|
34
38
|
],
|
package/lib/putout/index.js
CHANGED
|
@@ -10,10 +10,6 @@ const {
|
|
|
10
10
|
parse,
|
|
11
11
|
} = require('putout');
|
|
12
12
|
|
|
13
|
-
const traverse = require('@babel/traverse').default;
|
|
14
|
-
|
|
15
|
-
const v8 = require('v8');
|
|
16
|
-
|
|
17
13
|
const parseOptions = require('putout/parse-options');
|
|
18
14
|
const {parseError} = require('./parse-error');
|
|
19
15
|
|
|
@@ -23,9 +19,6 @@ const getContextOptions = ({options}) => {
|
|
|
23
19
|
return allContextOptions;
|
|
24
20
|
};
|
|
25
21
|
|
|
26
|
-
const copyAST = (a) => v8.deserialize(v8.serialize(a));
|
|
27
|
-
const returns = (a) => () => a;
|
|
28
|
-
|
|
29
22
|
const EMPTY_VISITORS = {};
|
|
30
23
|
|
|
31
24
|
module.exports = {
|
|
@@ -54,20 +47,29 @@ module.exports = {
|
|
|
54
47
|
const {text} = source;
|
|
55
48
|
const node = source.ast;
|
|
56
49
|
|
|
57
|
-
const ast = parse
|
|
58
|
-
|
|
50
|
+
const [errorParser, ast] = tryCatch(parse, text, {
|
|
51
|
+
isTS: true,
|
|
59
52
|
});
|
|
60
53
|
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
if (errorParser) {
|
|
55
|
+
context.report({
|
|
56
|
+
message: `${parseError(errorParser)} (putout)`,
|
|
57
|
+
node,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return EMPTY_VISITORS;
|
|
61
|
+
}
|
|
63
62
|
|
|
64
63
|
const [error, places = []] = tryCatch(findPlaces, ast, text, resultOptions);
|
|
65
64
|
|
|
66
|
-
if (error)
|
|
65
|
+
if (error) {
|
|
67
66
|
context.report({
|
|
68
67
|
message: `${parseError(error)} (putout)`,
|
|
69
68
|
node,
|
|
70
69
|
});
|
|
70
|
+
|
|
71
|
+
return EMPTY_VISITORS;
|
|
72
|
+
}
|
|
71
73
|
|
|
72
74
|
for (const {rule, message, position} of places) {
|
|
73
75
|
context.report({
|
|
@@ -105,34 +107,3 @@ const fix = ({ast, text, node, source, resultOptions}) => (fixer) => {
|
|
|
105
107
|
return fixer.replaceTextRange([0, last], code);
|
|
106
108
|
};
|
|
107
109
|
|
|
108
|
-
// 1. We cannot modify ESLint AST
|
|
109
|
-
// 2. Parent nodes makes Recast go crazy, so they should be removed
|
|
110
|
-
// 3. Recast creates original nodes with copies of each nodes
|
|
111
|
-
// 4. Parser does nothing but returns original AST before estree to babel
|
|
112
|
-
// 5. All this stuff made to gain performance benefit of avoiding a duble parsing: ESLint, and then Babel
|
|
113
|
-
// 6. Always can be removed and switched to direct parsing by Putout, when benefits outweight supporting all of this magic
|
|
114
|
-
const createParser = (node) => {
|
|
115
|
-
const ast = copyAST(node);
|
|
116
|
-
removeParent(ast);
|
|
117
|
-
|
|
118
|
-
const parser = {
|
|
119
|
-
parse: returns(ast),
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
return parser;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
// ESLint adds parent to each node
|
|
126
|
-
// it makes recase go crazy
|
|
127
|
-
// so we better drop them out
|
|
128
|
-
//
|
|
129
|
-
// https://github.com/eslint/eslint/blob/v8.4.0/lib/linter/linter.js#L964
|
|
130
|
-
function removeParent(ast) {
|
|
131
|
-
traverse(ast, {
|
|
132
|
-
noScope: true,
|
|
133
|
-
enter(path) {
|
|
134
|
-
delete path.node.parent;
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
|