eslint-plugin-putout 12.5.1 → 12.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 +5 -1
- package/lib/add-newline-after-function-call/index.js +2 -13
- package/lib/index.js +1 -0
- package/lib/putout/index.js +49 -39
- package/lib/putout/parse-error.js +8 -0
- package/lib/ts.js +3 -0
- package/lib/wrap.js +17 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -101,7 +101,11 @@ When using 🐊`Putout` in IDE with `--fix` on save, or when you want to disable
|
|
|
101
101
|
}
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
Disabled `ESLint` rules:
|
|
105
|
+
|
|
106
|
+
- [no-useless-return](https://eslint.org/docs/rules/no-useless-return)
|
|
107
|
+
|
|
108
|
+
Disabled 🐊`Putout` rules:
|
|
105
109
|
|
|
106
110
|
- [remove-empty](https://github.com/coderaiser/putout/tree/v22.0.0/packages/plugin-remove-empty);
|
|
107
111
|
- [remove-unused-variables](https://github.com/coderaiser/putout/tree/v22.0.0/packages/remove-unused-variables);
|
|
@@ -15,7 +15,7 @@ const regExp = /^;?\n( +)?\n +$/;
|
|
|
15
15
|
module.exports.category = 'layout';
|
|
16
16
|
module.exports.report = () => 'Add newline after function call';
|
|
17
17
|
|
|
18
|
-
module.exports.filter = ({text, node, getText, getCommentsAfter}) => {
|
|
18
|
+
module.exports.filter = ({text, node, getText, getCommentsAfter, getSpacesAfterNode}) => {
|
|
19
19
|
if (!isExpressionStatement(node.parent))
|
|
20
20
|
return false;
|
|
21
21
|
|
|
@@ -33,7 +33,7 @@ module.exports.filter = ({text, node, getText, getCommentsAfter}) => {
|
|
|
33
33
|
if (n < 3)
|
|
34
34
|
return false;
|
|
35
35
|
|
|
36
|
-
const spaces = getSpacesAfterNode(node, {text
|
|
36
|
+
const spaces = getSpacesAfterNode(node, {text});
|
|
37
37
|
|
|
38
38
|
if (regExp.test(spaces))
|
|
39
39
|
return false;
|
|
@@ -84,14 +84,3 @@ module.exports.include = () => [
|
|
|
84
84
|
'CallExpression',
|
|
85
85
|
];
|
|
86
86
|
|
|
87
|
-
function getSpacesAfterNode(node, {getText, text = getText(node)}) {
|
|
88
|
-
let spaces = '';
|
|
89
|
-
let i = 0;
|
|
90
|
-
|
|
91
|
-
while (!spaces || /^[ \n;]+$/.test(spaces))
|
|
92
|
-
spaces = getText(node, 0, ++i)
|
|
93
|
-
.replace(text, '');
|
|
94
|
-
|
|
95
|
-
return spaces.slice(0, -1);
|
|
96
|
-
}
|
|
97
|
-
|
package/lib/index.js
CHANGED
package/lib/putout/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const tryCatch = require('try-catch');
|
|
4
|
+
|
|
3
5
|
const {
|
|
4
6
|
ignores,
|
|
5
7
|
findPlaces,
|
|
@@ -13,6 +15,7 @@ const traverse = require('@babel/traverse').default;
|
|
|
13
15
|
const v8 = require('v8');
|
|
14
16
|
|
|
15
17
|
const parseOptions = require('putout/parse-options');
|
|
18
|
+
const {parseError} = require('./parse-error');
|
|
16
19
|
|
|
17
20
|
const cwd = process.cwd();
|
|
18
21
|
const getContextOptions = ({options}) => {
|
|
@@ -23,6 +26,8 @@ const getContextOptions = ({options}) => {
|
|
|
23
26
|
const copyAST = (a) => v8.deserialize(v8.serialize(a));
|
|
24
27
|
const returns = (a) => () => a;
|
|
25
28
|
|
|
29
|
+
const EMPTY_VISITORS = {};
|
|
30
|
+
|
|
26
31
|
module.exports = {
|
|
27
32
|
meta: {
|
|
28
33
|
type: 'suggestion',
|
|
@@ -35,45 +40,50 @@ module.exports = {
|
|
|
35
40
|
},
|
|
36
41
|
|
|
37
42
|
create(context) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
43
|
+
const name = context.getFilename();
|
|
44
|
+
const options = getContextOptions(context);
|
|
45
|
+
const resultOptions = parseOptions({
|
|
46
|
+
name,
|
|
47
|
+
options,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (ignores(cwd, name, resultOptions))
|
|
51
|
+
return EMPTY_VISITORS;
|
|
52
|
+
|
|
53
|
+
const source = context.getSourceCode();
|
|
54
|
+
const {text} = source;
|
|
55
|
+
const node = source.ast;
|
|
56
|
+
|
|
57
|
+
const ast = parse(text, {
|
|
58
|
+
parser: createParser(node),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const [error, places = []] = tryCatch(findPlaces, ast, text, resultOptions);
|
|
62
|
+
|
|
63
|
+
if (error)
|
|
64
|
+
context.report({
|
|
65
|
+
message: `${parseError(error)} (putout)`,
|
|
66
|
+
node,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
for (const {rule, message, position} of places) {
|
|
70
|
+
context.report({
|
|
71
|
+
message: `${message} (${rule})`,
|
|
72
|
+
fix: fix({
|
|
73
|
+
ast,
|
|
74
|
+
text,
|
|
75
|
+
node,
|
|
76
|
+
source,
|
|
77
|
+
resultOptions,
|
|
78
|
+
}),
|
|
79
|
+
loc: {
|
|
80
|
+
start: position,
|
|
81
|
+
end: position,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return EMPTY_VISITORS;
|
|
77
87
|
},
|
|
78
88
|
};
|
|
79
89
|
|
package/lib/ts.js
CHANGED
package/lib/wrap.js
CHANGED
|
@@ -8,10 +8,15 @@ const prepare = (plugin, context, options) => (node) => {
|
|
|
8
8
|
const getText = source.getText.bind(source);
|
|
9
9
|
const getCommentsBefore = source.getCommentsBefore.bind(source);
|
|
10
10
|
const getCommentsAfter = source.getCommentsAfter.bind(source);
|
|
11
|
+
|
|
11
12
|
const getSpacesBeforeNode = createGetSpacesBeforeNode({
|
|
12
13
|
getText,
|
|
13
14
|
});
|
|
14
15
|
|
|
16
|
+
const getSpacesAfterNode = createGetSpacesAfterNode({
|
|
17
|
+
getText,
|
|
18
|
+
});
|
|
19
|
+
|
|
15
20
|
const text = getText(node);
|
|
16
21
|
|
|
17
22
|
const result = filter({
|
|
@@ -22,6 +27,7 @@ const prepare = (plugin, context, options) => (node) => {
|
|
|
22
27
|
getCommentsBefore,
|
|
23
28
|
getCommentsAfter,
|
|
24
29
|
getSpacesBeforeNode,
|
|
30
|
+
getSpacesAfterNode,
|
|
25
31
|
filename,
|
|
26
32
|
});
|
|
27
33
|
|
|
@@ -106,3 +112,14 @@ const createGetSpacesBeforeNode = ({getText}) => (node, text = getText(node)) =>
|
|
|
106
112
|
return spaces.slice(1);
|
|
107
113
|
};
|
|
108
114
|
|
|
115
|
+
const createGetSpacesAfterNode = ({getText}) => (node, {text = getText(node)}) => {
|
|
116
|
+
let spaces = '';
|
|
117
|
+
let i = 0;
|
|
118
|
+
|
|
119
|
+
while (!spaces || /^[ \n;]+$/.test(spaces))
|
|
120
|
+
spaces = getText(node, 0, ++i)
|
|
121
|
+
.replace(text, '');
|
|
122
|
+
|
|
123
|
+
return spaces.slice(0, -1);
|
|
124
|
+
};
|
|
125
|
+
|