eslint-plugin-putout 12.0.1 → 12.3.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 +1 -0
- package/lib/add-newline-before-function-call/index.js +4 -14
- package/lib/index.js +1 -0
- package/lib/objects-braces-inside-array/index.js +3 -1
- package/lib/tape-remove-newline-before-t-end/index.js +32 -3
- package/lib/ts.js +63 -10
- package/lib/wrap.js +15 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -109,6 +109,7 @@ List of disabled 🐊`Putout` rules:
|
|
|
109
109
|
- [remove-unused-for-of-variables](https://github.com/coderaiser/putout/tree/v22.0.0/packages/remove-unused-for-of-variables);
|
|
110
110
|
- [remove-unused-expressions](https://github.com/coderaiser/putout/tree/v22.0.0/packages);
|
|
111
111
|
- [remove-useless-return](https://github.com/coderaiser/putout/tree/master/remove-useless-return);
|
|
112
|
+
- [remove-useless-arguments](https://github.com/coderaiser/putout/tree/master/remove-useless-arguments);
|
|
112
113
|
- [remove-skip](https://github.com/coderaiser/putout/tree/v22.0.0/packages/remove-skip);
|
|
113
114
|
- [remove-only](https://github.com/coderaiser/putout/tree/v22.0.0/packages/remove-only);
|
|
114
115
|
- [remove-console](https://github.com/coderaiser/putout/tree/v22.0.0/packages/remove-console);
|
|
@@ -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
|
-
}
|
package/lib/index.js
CHANGED
|
@@ -107,6 +107,7 @@ const safe = {
|
|
|
107
107
|
'remove-unused-for-of-variables': 'off',
|
|
108
108
|
'remove-unreachable-code': 'off',
|
|
109
109
|
'remove-useless-return': 'off',
|
|
110
|
+
'remove-useless-arguments': 'off',
|
|
110
111
|
'tape/remove-skip': 'off',
|
|
111
112
|
'tape/remove-only': 'off',
|
|
112
113
|
'remove-console': 'off',
|
|
@@ -11,6 +11,7 @@ module.exports.include = () => [
|
|
|
11
11
|
|
|
12
12
|
const badStart = /^\[\n(\s+)?{/;
|
|
13
13
|
const badEndReg = /},?\n(\s+)?]/;
|
|
14
|
+
const badMiddle = /\},\n(s+)?\{/;
|
|
14
15
|
|
|
15
16
|
module.exports.filter = ({node, text}) => {
|
|
16
17
|
const {elements} = node;
|
|
@@ -22,8 +23,9 @@ module.exports.filter = ({node, text}) => {
|
|
|
22
23
|
|
|
23
24
|
const isStart = badStart.test(text);
|
|
24
25
|
const isEnd = badEndReg.test(text);
|
|
26
|
+
const isBadMiddle = badMiddle.test(text);
|
|
25
27
|
|
|
26
|
-
return isStart || isEnd;
|
|
28
|
+
return isStart || isEnd || isBadMiddle;
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
module.exports.fix = ({text}) => {
|
|
@@ -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/ts.js
CHANGED
|
@@ -1,5 +1,66 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {rules} = require('@putout/eslint-config');
|
|
4
|
+
|
|
5
|
+
const extensionRules = {
|
|
6
|
+
'no-undef': 'off',
|
|
7
|
+
'no-var': 'off',
|
|
8
|
+
|
|
9
|
+
'brace-style': 'off',
|
|
10
|
+
'@typescript-eslint/brace-style': ['error'],
|
|
11
|
+
|
|
12
|
+
'comma-dangle': 'off',
|
|
13
|
+
'@typescript-eslint/comma-dangle': rules['comma-dangle'],
|
|
14
|
+
|
|
15
|
+
'comma-spacing': 'off',
|
|
16
|
+
'@typescript-eslint/comma-spacing': 'error',
|
|
17
|
+
|
|
18
|
+
// requires type information
|
|
19
|
+
'@typescript-eslint/dot-notation': 'off',
|
|
20
|
+
|
|
21
|
+
'func-call-spacing': 'off',
|
|
22
|
+
'@typescript-eslint/func-call-spacing': 'error',
|
|
23
|
+
|
|
24
|
+
// broken
|
|
25
|
+
'@typescript-eslint/indent': 'off',
|
|
26
|
+
|
|
27
|
+
'lines-between-class-members': 'off',
|
|
28
|
+
'@typescript-eslint/lines-between-class-members': 'error',
|
|
29
|
+
|
|
30
|
+
'@typescript-eslint/no-array-constructor': 'off',
|
|
31
|
+
|
|
32
|
+
'no-extra-parens': 'off',
|
|
33
|
+
'@typescript-eslint/no-extra-parens': 'error',
|
|
34
|
+
|
|
35
|
+
'no-extra-semi': 'off',
|
|
36
|
+
'@typescript-eslint/no-extra-semi': 'error',
|
|
37
|
+
|
|
38
|
+
'@typescript-eslint/no-implied-eval': 'off',
|
|
39
|
+
|
|
40
|
+
'no-unused-vars': 'off',
|
|
41
|
+
'@typescript-eslint/no-unused-vars': 'error',
|
|
42
|
+
|
|
43
|
+
'object-curly-spacing': 'off',
|
|
44
|
+
'@typescript-eslint/object-curly-spacing': 'error',
|
|
45
|
+
|
|
46
|
+
'padding-line-between-statements': 'off',
|
|
47
|
+
'@typescript-eslint/padding-line-between-statements': rules['padding-line-between-statements'],
|
|
48
|
+
|
|
49
|
+
'quotes': 'off',
|
|
50
|
+
'@typescript-eslint/quotes': rules.quotes,
|
|
51
|
+
|
|
52
|
+
'@typescript-eslint/require-await': 'off',
|
|
53
|
+
|
|
54
|
+
'semi': 'off',
|
|
55
|
+
'@typescript-eslint/semi': rules.semi,
|
|
56
|
+
|
|
57
|
+
'space-before-function-paren': 'off',
|
|
58
|
+
'@typescript-eslint/space-before-function-paren': rules['space-before-function-paren'],
|
|
59
|
+
|
|
60
|
+
'space-infix-ops': 'off',
|
|
61
|
+
'@typescript-eslint/space-infix-ops': rules[ 'space-infix-ops'],
|
|
62
|
+
};
|
|
63
|
+
|
|
3
64
|
const ts = {
|
|
4
65
|
files: '*.ts',
|
|
5
66
|
parser: '@typescript-eslint/parser',
|
|
@@ -15,21 +76,13 @@ const ts = {
|
|
|
15
76
|
'plugin:@typescript-eslint/recommended',
|
|
16
77
|
],
|
|
17
78
|
rules: {
|
|
18
|
-
|
|
19
|
-
'no-var': 'off',
|
|
79
|
+
...extensionRules,
|
|
20
80
|
'putout/no-unresolved': 'off',
|
|
21
|
-
'semi': 'off',
|
|
22
|
-
'@typescript-eslint/semi': 'error',
|
|
23
81
|
'@typescript-eslint/array-type': 'error',
|
|
24
|
-
'space-before-function-paren': 'off',
|
|
25
82
|
'@typescript-eslint/no-explicit-any': 'off',
|
|
26
83
|
'@typescript-eslint/ban-types': 'off',
|
|
27
84
|
'@typescript-eslint/no-empty-function': 'off',
|
|
28
|
-
'@typescript-eslint/
|
|
29
|
-
anonymous: 'never',
|
|
30
|
-
named: 'never',
|
|
31
|
-
asyncArrow: 'always',
|
|
32
|
-
}],
|
|
85
|
+
'@typescript-eslint/type-annotation-spacing': 'error',
|
|
33
86
|
},
|
|
34
87
|
};
|
|
35
88
|
|
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
|
+
|