eslint-plugin-putout 11.10.0 → 11.14.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 -4
- package/lib/add-newline-before-function-call/README.md +26 -0
- package/lib/add-newline-before-function-call/index.js +74 -0
- package/lib/array-element-newline/index.js +12 -4
- package/lib/index.js +4 -0
- package/lib/putout/README.md +1 -1
- package/lib/tape-add-newline-before-assertion/README.md +8 -4
- package/lib/tape-add-newline-before-assertion/index.js +1 -1
- package/lib/tape-add-newline-between-tests/README.md +3 -3
- package/lib/tape-add-newline-between-tests/index.js +1 -1
- package/lib/tape-remove-newline-before-t-end/README.md +30 -0
- package/lib/tape-remove-newline-before-t-end/index.js +25 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[CoverageURL]: https://coveralls.io/github/coderaiser/putout?branch=master
|
|
6
6
|
[CoverageIMGURL]: https://coveralls.io/repos/coderaiser/putout/badge.svg?branch=master&service=github
|
|
7
7
|
|
|
8
|
-
[`ESLint`](https://eslint.org) plugin for [
|
|
8
|
+
[`ESLint`](https://eslint.org) plugin for 🐊[`Putout`](https://github.com/coderaiser/putout) with built-in rules from [@putout/eslint-config](https://github.com/coderaiser/eslint-plugin-putout/tree/master/packages/eslint-config).
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
@@ -58,7 +58,7 @@ Then configure the rules you want to use under the rules section.
|
|
|
58
58
|
|
|
59
59
|
## Supported Rules
|
|
60
60
|
|
|
61
|
-
- [
|
|
61
|
+
- [Putout](lib/putout)
|
|
62
62
|
- [Array element newline](/packages/eslint-plugin-putout/lib/array-element-newline)
|
|
63
63
|
- [Single property destructuring](/packages/eslint-plugin-putout/lib/single-property-destructuring)
|
|
64
64
|
- [Multiple properties destructuring](/packages/eslint-plugin-putout/lib/multiple-properties-destructuring)
|
|
@@ -78,8 +78,9 @@ Then configure the rules you want to use under the rules section.
|
|
|
78
78
|
- [Object init](/packages/eslint-plugin-putout/lib/object-init)
|
|
79
79
|
- [No unresolved](/packages/eslint-plugin-putout/lib/no-unresolved)
|
|
80
80
|
- [Evaluate](/packages/eslint-plugin-putout/lib/evaluate)
|
|
81
|
-
- [Tape: add
|
|
82
|
-
- [Tape: add
|
|
81
|
+
- [Tape: add newline before assertion]('/packages/eslint-plugin-putout/lib/tape-add-new-line-before-assertion)
|
|
82
|
+
- [Tape: add newline between tests]('/packages/eslint-plugin-putout/lib/tape-add-new-line-between-tests)
|
|
83
|
+
- [Tape: remove newline before t.end()]('/packages/eslint-plugin-putout/lib/tape-remove-newline-before-t-end)
|
|
83
84
|
|
|
84
85
|
### Safe mode
|
|
85
86
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Add new line before function call (add-newline-before-function-call)
|
|
2
|
+
|
|
3
|
+
## Rule Details
|
|
4
|
+
|
|
5
|
+
This rule aims to add newline before function call.
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
export function parse() {
|
|
11
|
+
const a = 1;
|
|
12
|
+
const b = 2;
|
|
13
|
+
fn();
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Examples of **correct** code for this rule:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
export function parse() {
|
|
21
|
+
const a = 1;
|
|
22
|
+
const b = 2;
|
|
23
|
+
|
|
24
|
+
fn();
|
|
25
|
+
}
|
|
26
|
+
```
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types} = require('putout');
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
isBlockStatement,
|
|
7
|
+
isVariableDeclaration,
|
|
8
|
+
isExpressionStatement,
|
|
9
|
+
} = types;
|
|
10
|
+
|
|
11
|
+
module.exports.category = 'typescript';
|
|
12
|
+
module.exports.report = () => 'Add newline before function call';
|
|
13
|
+
|
|
14
|
+
module.exports.filter = ({text, node, getText}) => {
|
|
15
|
+
if (!isExpressionStatement(node.parent))
|
|
16
|
+
return false;
|
|
17
|
+
|
|
18
|
+
const {parent} = node.parent;
|
|
19
|
+
|
|
20
|
+
if (!isBlockStatement(parent))
|
|
21
|
+
return false;
|
|
22
|
+
|
|
23
|
+
const {body} = parent;
|
|
24
|
+
const n = body.length;
|
|
25
|
+
|
|
26
|
+
if (n < 3)
|
|
27
|
+
return false;
|
|
28
|
+
|
|
29
|
+
const spaces = getSpacesBeforeNode(node, {text, getText});
|
|
30
|
+
|
|
31
|
+
if (/^\n +\n +$/.test(spaces))
|
|
32
|
+
return false;
|
|
33
|
+
|
|
34
|
+
for (let i = 2; i < n; i++) {
|
|
35
|
+
const current = body[i];
|
|
36
|
+
|
|
37
|
+
if (current !== node.parent)
|
|
38
|
+
continue;
|
|
39
|
+
|
|
40
|
+
const prevA = body[i - 1];
|
|
41
|
+
|
|
42
|
+
if (!isVariableDeclaration(prevA))
|
|
43
|
+
continue;
|
|
44
|
+
|
|
45
|
+
const spaces = getSpacesBeforeNode(prevA, {getText});
|
|
46
|
+
|
|
47
|
+
if (/^\n +\n +$/.test(spaces))
|
|
48
|
+
return false;
|
|
49
|
+
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return false;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
module.exports.fix = ({text}) => {
|
|
57
|
+
return `\n${text}`;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
module.exports.include = () => [
|
|
61
|
+
'CallExpression',
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
function getSpacesBeforeNode(node, {getText, text = getText(node)}) {
|
|
65
|
+
let spaces = '';
|
|
66
|
+
let i = 0;
|
|
67
|
+
|
|
68
|
+
while (!spaces || /^[ \n]+$/.test(spaces))
|
|
69
|
+
spaces = getText(node, ++i)
|
|
70
|
+
.replace(text, '');
|
|
71
|
+
|
|
72
|
+
return spaces.slice(1);
|
|
73
|
+
}
|
|
74
|
+
|
|
@@ -11,16 +11,24 @@ module.exports.report = () => 'Add newlines between array elements';
|
|
|
11
11
|
|
|
12
12
|
const regexp = /['\da-zA-Z]+, ['\da-zA-Z]/;
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const isSupportedNode = (a) => {
|
|
15
|
+
if (a.type === 'Literal')
|
|
16
|
+
return true;
|
|
17
|
+
|
|
18
|
+
if (a.type === 'Identifier')
|
|
19
|
+
return true;
|
|
20
|
+
|
|
21
|
+
return false;
|
|
22
|
+
};
|
|
15
23
|
|
|
16
24
|
module.exports.filter = ({text, node}) => {
|
|
17
25
|
if (isMemberExpression(node.parent))
|
|
18
26
|
return false;
|
|
19
27
|
|
|
20
|
-
const
|
|
21
|
-
.every(
|
|
28
|
+
const supported = node.elements
|
|
29
|
+
.every(isSupportedNode);
|
|
22
30
|
|
|
23
|
-
if (!
|
|
31
|
+
if (!supported)
|
|
24
32
|
return false;
|
|
25
33
|
|
|
26
34
|
if (!isVariableDeclarator(node.parent))
|
package/lib/index.js
CHANGED
|
@@ -27,6 +27,7 @@ module.exports.rules = {
|
|
|
27
27
|
...getWrapRule('newline-function-call-arguments'),
|
|
28
28
|
...getWrapRule('function-declaration-paren-newline'),
|
|
29
29
|
...getWrapRule('add-newlines-between-types-in-union'),
|
|
30
|
+
...getWrapRule('add-newline-before-function-call'),
|
|
30
31
|
...getWrapRule('remove-newline-after-default-import'),
|
|
31
32
|
...getWrapRule('remove-newline-from-empty-object'),
|
|
32
33
|
...getWrapRule('remove-empty-newline-before-first-specifier'),
|
|
@@ -37,6 +38,7 @@ module.exports.rules = {
|
|
|
37
38
|
...getWrapRule('evaluate'),
|
|
38
39
|
...getWrapRule('tape-add-newline-before-assertion'),
|
|
39
40
|
...getWrapRule('tape-add-newline-between-tests'),
|
|
41
|
+
...getWrapRule('tape-remove-newline-before-t-end'),
|
|
40
42
|
...getRule('putout'),
|
|
41
43
|
};
|
|
42
44
|
|
|
@@ -61,6 +63,7 @@ const recommended = {
|
|
|
61
63
|
'putout/newline-function-call-arguments': 'error',
|
|
62
64
|
'putout/function-declaration-paren-newline': 'error',
|
|
63
65
|
'putout/add-newlines-between-types-in-union': 'error',
|
|
66
|
+
'putout/add-newline-before-function-call': 'error',
|
|
64
67
|
'putout/remove-newline-after-default-import': 'error',
|
|
65
68
|
'putout/remove-newline-from-empty-object': 'error',
|
|
66
69
|
'putout/remove-empty-newline-before-first-specifier': 'error',
|
|
@@ -71,6 +74,7 @@ const recommended = {
|
|
|
71
74
|
'putout/evaluate': 'error',
|
|
72
75
|
'putout/tape-add-newline-before-assertion': 'error',
|
|
73
76
|
'putout/tape-add-newline-between-tests': 'error',
|
|
77
|
+
'putout/tape-remove-newline-before-t-end': 'error',
|
|
74
78
|
'putout/putout': 'error',
|
|
75
79
|
|
|
76
80
|
'node/no-unsupported-features/es-syntax': 'off',
|
package/lib/putout/README.md
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
# Add
|
|
1
|
+
# Add newline before assertion (add-newline-before-assertion)
|
|
2
2
|
|
|
3
|
-
Add
|
|
3
|
+
Add newline before `t.equal()` etc, for [supertape](https://github.com/coderaiser/supertape).
|
|
4
4
|
|
|
5
5
|
## Rule Details
|
|
6
6
|
|
|
7
|
-
This rule aims to add
|
|
7
|
+
This rule aims to add newline before assertion.
|
|
8
8
|
|
|
9
9
|
Examples of **incorrect** code for this rule:
|
|
10
10
|
|
|
11
11
|
```js
|
|
12
12
|
test('lint: do some check', (t) => {
|
|
13
|
-
const
|
|
13
|
+
const expected = 1 + 2;
|
|
14
|
+
|
|
15
|
+
fn();
|
|
14
16
|
t.equal(result, 3);
|
|
15
17
|
t.end();
|
|
16
18
|
});
|
|
@@ -22,6 +24,8 @@ Examples of **correct** code for this rule:
|
|
|
22
24
|
test('lint: do some check', (t) => {
|
|
23
25
|
const result = 1 + 2;
|
|
24
26
|
|
|
27
|
+
fn();
|
|
28
|
+
|
|
25
29
|
t.equal(result, 3);
|
|
26
30
|
t.end();
|
|
27
31
|
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
# Add
|
|
1
|
+
# Add newline between tests (add-newline-between-tests)
|
|
2
2
|
|
|
3
|
-
Add
|
|
3
|
+
Add newline between tests, for [supertape](https://github.com/coderaiser/supertape).
|
|
4
4
|
|
|
5
5
|
## Rule Details
|
|
6
6
|
|
|
7
|
-
This rule aims to add
|
|
7
|
+
This rule aims to add newline between tests.
|
|
8
8
|
|
|
9
9
|
Examples of **incorrect** code for this rule:
|
|
10
10
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports.category = 'tape';
|
|
4
|
-
module.exports.report = () => 'Add
|
|
4
|
+
module.exports.report = () => 'Add newline between tests';
|
|
5
5
|
|
|
6
6
|
module.exports.filter = ({text, node, getText, getCommentsBefore}) => {
|
|
7
7
|
if (!/^test(\.only|\.skip)?\(/.test(text))
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Remove newline before `t.end()` (remove-newline-before-t-end)
|
|
2
|
+
|
|
3
|
+
Remove newline before `t.end()`, for [supertape](https://github.com/coderaiser/supertape).
|
|
4
|
+
|
|
5
|
+
## Rule Details
|
|
6
|
+
|
|
7
|
+
This rule aims to remove newline before `t.end()`.
|
|
8
|
+
|
|
9
|
+
Examples of **incorrect** code for this rule:
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
test('lint: do some check', (t) => {
|
|
13
|
+
const result = 1 + 2;
|
|
14
|
+
|
|
15
|
+
t.equal(result, 3);
|
|
16
|
+
|
|
17
|
+
t.end();
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Examples of **correct** code for this rule:
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
test('lint: do some check', (t) => {
|
|
25
|
+
const result = 1 + 2;
|
|
26
|
+
|
|
27
|
+
t.equal(result, 3);
|
|
28
|
+
t.end();
|
|
29
|
+
});
|
|
30
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.category = 'tape';
|
|
4
|
+
module.exports.report = () => 'Remove newline before t.end()';
|
|
5
|
+
|
|
6
|
+
const newlineReg = /\n( +)?\n +t.end\(\)/;
|
|
7
|
+
|
|
8
|
+
module.exports.filter = ({text}) => {
|
|
9
|
+
if (!/^test(\.only|\.skip)?\(/.test(text))
|
|
10
|
+
return false;
|
|
11
|
+
|
|
12
|
+
if (newlineReg.test(text))
|
|
13
|
+
return true;
|
|
14
|
+
|
|
15
|
+
return false;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
module.exports.fix = ({text}) => {
|
|
19
|
+
return text.replace(newlineReg, '\n t.end()');
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
module.exports.include = () => [
|
|
23
|
+
'CallExpression',
|
|
24
|
+
];
|
|
25
|
+
|