eslint-plugin-putout 12.0.1 → 12.0.2
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.
|
@@ -13,7 +13,7 @@ const regExp = /^\n( +)?\n +$/;
|
|
|
13
13
|
module.exports.category = 'typescript';
|
|
14
14
|
module.exports.report = () => 'Add newline before function call';
|
|
15
15
|
|
|
16
|
-
module.exports.filter = ({text, node,
|
|
16
|
+
module.exports.filter = ({text, node, getCommentsBefore, getSpacesBeforeNode}) => {
|
|
17
17
|
if (!isExpressionStatement(node.parent))
|
|
18
18
|
return false;
|
|
19
19
|
|
|
@@ -31,7 +31,7 @@ module.exports.filter = ({text, node, getText, getCommentsBefore}) => {
|
|
|
31
31
|
if (n < 3)
|
|
32
32
|
return false;
|
|
33
33
|
|
|
34
|
-
const spaces = getSpacesBeforeNode(node,
|
|
34
|
+
const spaces = getSpacesBeforeNode(node, text);
|
|
35
35
|
|
|
36
36
|
if (regExp.test(spaces))
|
|
37
37
|
return false;
|
|
@@ -48,7 +48,7 @@ module.exports.filter = ({text, node, getText, getCommentsBefore}) => {
|
|
|
48
48
|
if (!isVariableDeclaration(prevA))
|
|
49
49
|
return false;
|
|
50
50
|
|
|
51
|
-
const spaces = getSpacesBeforeNode(prevA
|
|
51
|
+
const spaces = getSpacesBeforeNode(prevA);
|
|
52
52
|
|
|
53
53
|
if (regExp.test(spaces))
|
|
54
54
|
return false;
|
|
@@ -56,7 +56,7 @@ module.exports.filter = ({text, node, getText, getCommentsBefore}) => {
|
|
|
56
56
|
if (!nextA)
|
|
57
57
|
return true;
|
|
58
58
|
|
|
59
|
-
const nextSpaces = getSpacesBeforeNode(nextA
|
|
59
|
+
const nextSpaces = getSpacesBeforeNode(nextA);
|
|
60
60
|
return !regExp.test(nextSpaces);
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -71,13 +71,3 @@ module.exports.include = () => [
|
|
|
71
71
|
'CallExpression',
|
|
72
72
|
];
|
|
73
73
|
|
|
74
|
-
function getSpacesBeforeNode(node, {getText, text = getText(node)}) {
|
|
75
|
-
let spaces = '';
|
|
76
|
-
let i = 0;
|
|
77
|
-
|
|
78
|
-
while (!spaces || /^[ \n]+$/.test(spaces))
|
|
79
|
-
spaces = getText(node, ++i)
|
|
80
|
-
.replace(text, '');
|
|
81
|
-
|
|
82
|
-
return spaces.slice(1);
|
|
83
|
-
}
|
|
@@ -1,16 +1,45 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {
|
|
4
|
+
operator,
|
|
5
|
+
types,
|
|
6
|
+
} = require('putout');
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
isCallExpression,
|
|
10
|
+
isIdentifier,
|
|
11
|
+
} = types;
|
|
12
|
+
|
|
13
|
+
const {compare} = operator;
|
|
14
|
+
|
|
3
15
|
module.exports.category = 'tape';
|
|
4
16
|
module.exports.report = () => 'Remove newline before t.end()';
|
|
5
17
|
|
|
6
18
|
const newlineReg = /\n( +)?\n +t.end\(\)/;
|
|
7
19
|
|
|
8
|
-
module.exports.filter = ({text}) => {
|
|
20
|
+
module.exports.filter = ({text, node}) => {
|
|
9
21
|
if (!/^test(\.only|\.skip)?\(/.test(text))
|
|
10
22
|
return false;
|
|
11
23
|
|
|
12
|
-
if (newlineReg.test(text))
|
|
13
|
-
return
|
|
24
|
+
if (!newlineReg.test(text))
|
|
25
|
+
return false;
|
|
26
|
+
|
|
27
|
+
const {body} = node.arguments[1].body;
|
|
28
|
+
const n = body.length;
|
|
29
|
+
|
|
30
|
+
for (let i = 1; i < n; i++) {
|
|
31
|
+
const current = body[i];
|
|
32
|
+
const prev = body[i - 1];
|
|
33
|
+
|
|
34
|
+
if (!compare(current, 't.end()'))
|
|
35
|
+
continue;
|
|
36
|
+
|
|
37
|
+
if (!isCallExpression(prev.expression))
|
|
38
|
+
break;
|
|
39
|
+
|
|
40
|
+
const {callee} = prev.expression;
|
|
41
|
+
return isIdentifier(callee.object, {name: 't'});
|
|
42
|
+
}
|
|
14
43
|
|
|
15
44
|
return false;
|
|
16
45
|
};
|
package/lib/wrap.js
CHANGED
|
@@ -8,6 +8,9 @@ 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
|
+
const getSpacesBeforeNode = createGetSpacesBeforeNode({
|
|
12
|
+
getText,
|
|
13
|
+
});
|
|
11
14
|
|
|
12
15
|
const text = getText(node);
|
|
13
16
|
|
|
@@ -18,6 +21,7 @@ const prepare = (plugin, context, options) => (node) => {
|
|
|
18
21
|
getText,
|
|
19
22
|
getCommentsBefore,
|
|
20
23
|
getCommentsAfter,
|
|
24
|
+
getSpacesBeforeNode,
|
|
21
25
|
filename,
|
|
22
26
|
});
|
|
23
27
|
|
|
@@ -91,3 +95,14 @@ function getTraversers(names, plugin) {
|
|
|
91
95
|
return traversers;
|
|
92
96
|
}
|
|
93
97
|
|
|
98
|
+
const createGetSpacesBeforeNode = ({getText}) => (node, text = getText(node)) => {
|
|
99
|
+
let spaces = '';
|
|
100
|
+
let i = 0;
|
|
101
|
+
|
|
102
|
+
while (!spaces || /^[ \n]+$/.test(spaces))
|
|
103
|
+
spaces = getText(node, ++i)
|
|
104
|
+
.replace(text, '');
|
|
105
|
+
|
|
106
|
+
return spaces.slice(1);
|
|
107
|
+
};
|
|
108
|
+
|