eslint-plugin-putout 11.8.0 → 11.12.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 +7 -4
- package/lib/array-element-newline/README.md +28 -0
- package/lib/array-element-newline/index.js +56 -0
- package/lib/index.js +4 -0
- package/lib/json.js +0 -1
- package/lib/keyword-spacing/README.md +5 -5
- package/lib/object-init/README.md +2 -6
- package/lib/putout/README.md +1 -1
- package/lib/tape-add-newline-before-assertion/README.md +3 -3
- 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/lib/yaml.js +1 -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 putout with built-in rules from [@putout/eslint-config](https://github.com/coderaiser/eslint-plugin-putout/tree/master/packages/eslint-config).
|
|
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
|
|
|
@@ -36,6 +36,7 @@ Then configure the rules you want to use under the rules section.
|
|
|
36
36
|
{
|
|
37
37
|
"rules": {
|
|
38
38
|
"putout/putout": "error",
|
|
39
|
+
"putout/array-element-newline": "error",
|
|
39
40
|
"putout/single-property-destructuring": "error",
|
|
40
41
|
"putout/multiple-properties-destructuring": "error",
|
|
41
42
|
"putout/long-properties-destructuring": "error",
|
|
@@ -57,7 +58,8 @@ Then configure the rules you want to use under the rules section.
|
|
|
57
58
|
|
|
58
59
|
## Supported Rules
|
|
59
60
|
|
|
60
|
-
- [
|
|
61
|
+
- [Putout](lib/putout)
|
|
62
|
+
- [Array element newline](/packages/eslint-plugin-putout/lib/array-element-newline)
|
|
61
63
|
- [Single property destructuring](/packages/eslint-plugin-putout/lib/single-property-destructuring)
|
|
62
64
|
- [Multiple properties destructuring](/packages/eslint-plugin-putout/lib/multiple-properties-destructuring)
|
|
63
65
|
- [For-of multiple properties destructuring](/packages/eslint-plugin-putout/lib/for-of-multiple-properties-destructuring)
|
|
@@ -76,8 +78,9 @@ Then configure the rules you want to use under the rules section.
|
|
|
76
78
|
- [Object init](/packages/eslint-plugin-putout/lib/object-init)
|
|
77
79
|
- [No unresolved](/packages/eslint-plugin-putout/lib/no-unresolved)
|
|
78
80
|
- [Evaluate](/packages/eslint-plugin-putout/lib/evaluate)
|
|
79
|
-
- [Tape: add
|
|
80
|
-
- [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)
|
|
81
84
|
|
|
82
85
|
### Safe mode
|
|
83
86
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Add new lines between types in union (add-newlines-between-types-in-union)
|
|
2
|
+
|
|
3
|
+
Because [`array-element-newline`](https://eslint.org/docs/rules/array-element-newline) requires [`array-bracket-newline`](https://eslint.org/docs/rules/array-bracket-newline).
|
|
4
|
+
And `array-bracket-newline` and conflicts with [`object-braces-inside-array`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout/lib/objects-braces-inside-array).
|
|
5
|
+
|
|
6
|
+
## Rule Details
|
|
7
|
+
|
|
8
|
+
This rule aims to add newlines between array elements.
|
|
9
|
+
|
|
10
|
+
Examples of **incorrect** code for this rule:
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
const a = [1, 2, 3, 4, 5, 6, 7];
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Examples of **correct** code for this rule:
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
const a = [
|
|
20
|
+
1,
|
|
21
|
+
2,
|
|
22
|
+
3,
|
|
23
|
+
4,
|
|
24
|
+
5,
|
|
25
|
+
6,
|
|
26
|
+
7,
|
|
27
|
+
];
|
|
28
|
+
```
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types} = require('putout');
|
|
4
|
+
const {
|
|
5
|
+
isMemberExpression,
|
|
6
|
+
isVariableDeclarator,
|
|
7
|
+
} = types;
|
|
8
|
+
|
|
9
|
+
module.exports.category = 'array';
|
|
10
|
+
module.exports.report = () => 'Add newlines between array elements';
|
|
11
|
+
|
|
12
|
+
const regexp = /['\da-zA-Z]+, ['\da-zA-Z]/;
|
|
13
|
+
|
|
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
|
+
};
|
|
23
|
+
|
|
24
|
+
module.exports.filter = ({text, node}) => {
|
|
25
|
+
if (isMemberExpression(node.parent))
|
|
26
|
+
return false;
|
|
27
|
+
|
|
28
|
+
const supported = node.elements
|
|
29
|
+
.every(isSupportedNode);
|
|
30
|
+
|
|
31
|
+
if (!supported)
|
|
32
|
+
return false;
|
|
33
|
+
|
|
34
|
+
if (!isVariableDeclarator(node.parent))
|
|
35
|
+
return false;
|
|
36
|
+
|
|
37
|
+
if (node.elements.length < 4)
|
|
38
|
+
return false;
|
|
39
|
+
|
|
40
|
+
if (regexp.test(text))
|
|
41
|
+
return true;
|
|
42
|
+
|
|
43
|
+
return false;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
module.exports.fix = ({text}) => {
|
|
47
|
+
return text
|
|
48
|
+
.replace(/\[/g, '[\n')
|
|
49
|
+
.replace(/\]/g, '\n]')
|
|
50
|
+
.replace(/,/g, ',\n');
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
module.exports.include = () => [
|
|
54
|
+
'ArrayExpression',
|
|
55
|
+
];
|
|
56
|
+
|
package/lib/index.js
CHANGED
|
@@ -16,6 +16,7 @@ const getWrapRule = (a) => ({
|
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
module.exports.rules = {
|
|
19
|
+
...getWrapRule('array-element-newline'),
|
|
19
20
|
...getWrapRule('single-property-destructuring'),
|
|
20
21
|
...getWrapRule('multiple-properties-destructuring'),
|
|
21
22
|
...getWrapRule('for-of-multiple-properties-destructuring'),
|
|
@@ -36,6 +37,7 @@ module.exports.rules = {
|
|
|
36
37
|
...getWrapRule('evaluate'),
|
|
37
38
|
...getWrapRule('tape-add-newline-before-assertion'),
|
|
38
39
|
...getWrapRule('tape-add-newline-between-tests'),
|
|
40
|
+
...getWrapRule('tape-remove-newline-before-t-end'),
|
|
39
41
|
...getRule('putout'),
|
|
40
42
|
};
|
|
41
43
|
|
|
@@ -49,6 +51,7 @@ const recommended = {
|
|
|
49
51
|
'no-debugger': 'off',
|
|
50
52
|
'no-unused-vars': 'off',
|
|
51
53
|
|
|
54
|
+
'putout/array-element-newline': 'error',
|
|
52
55
|
'putout/single-property-destructuring': 'error',
|
|
53
56
|
'putout/multiple-properties-destructuring': 'error',
|
|
54
57
|
'putout/for-of-multiple-properties-destructuring': 'error',
|
|
@@ -69,6 +72,7 @@ const recommended = {
|
|
|
69
72
|
'putout/evaluate': 'error',
|
|
70
73
|
'putout/tape-add-newline-before-assertion': 'error',
|
|
71
74
|
'putout/tape-add-newline-between-tests': 'error',
|
|
75
|
+
'putout/tape-remove-newline-before-t-end': 'error',
|
|
72
76
|
'putout/putout': 'error',
|
|
73
77
|
|
|
74
78
|
'node/no-unsupported-features/es-syntax': 'off',
|
package/lib/json.js
CHANGED
|
@@ -21,15 +21,15 @@ try {
|
|
|
21
21
|
} catch(error) {
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
if
|
|
24
|
+
if(a) {
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
for
|
|
27
|
+
for(i = 0; i < n; i++) {}
|
|
28
28
|
|
|
29
|
-
for
|
|
29
|
+
for(x of y) {}
|
|
30
30
|
|
|
31
31
|
async () => {
|
|
32
|
-
for await
|
|
32
|
+
for await(x of y) {}
|
|
33
33
|
};
|
|
34
34
|
```
|
|
35
35
|
|
|
@@ -37,7 +37,7 @@ Examples of **correct** code for this rule:
|
|
|
37
37
|
|
|
38
38
|
```js
|
|
39
39
|
try {
|
|
40
|
-
}
|
|
40
|
+
}catch {
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
try {
|
|
@@ -7,13 +7,9 @@ In the same way as eslint [object-property-newline](https://github.com/coderaise
|
|
|
7
7
|
Examples of **incorrect** code for this rule:
|
|
8
8
|
|
|
9
9
|
```js
|
|
10
|
-
const user = {
|
|
11
|
-
name,
|
|
12
|
-
};
|
|
10
|
+
const user = {name};
|
|
13
11
|
|
|
14
|
-
module.exports = {
|
|
15
|
-
lint: 'putout lint',
|
|
16
|
-
};
|
|
12
|
+
module.exports = {lint: 'putout lint'};
|
|
17
13
|
```
|
|
18
14
|
|
|
19
15
|
Examples of **correct** code for this rule:
|
package/lib/putout/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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
|
|
|
@@ -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
|
+
|
package/lib/yaml.js
CHANGED