eslint-plugin-putout 11.6.0 → 11.10.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 +6 -6
- package/lib/array-element-newline/README.md +28 -0
- package/lib/array-element-newline/index.js +48 -0
- package/lib/index.js +4 -0
- package/lib/json.js +0 -1
- package/lib/keyword-spacing/README.md +5 -5
- package/lib/no-unresolved/README.md +2 -3
- package/lib/object-init/README.md +2 -6
- package/lib/remove-empty-newline-after-last-specifier/README.md +11 -0
- package/lib/remove-empty-newline-after-last-specifier/index.js +2 -1
- package/lib/remove-empty-newline-before-first-specifier/README.md +35 -0
- package/lib/remove-empty-newline-before-first-specifier/index.js +21 -0
- package/lib/remove-newline-from-empty-object/README.md +0 -1
- package/lib/single-property-destructuring/README.md +4 -0
- package/lib/single-property-destructuring/index.js +17 -6
- package/lib/yaml.js +1 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
# eslint-plugin-putout [![NPM version][NPMIMGURL]][NPMURL] [![
|
|
1
|
+
# eslint-plugin-putout [![NPM version][NPMIMGURL]][NPMURL] [![Coverage Status][CoverageIMGURL]][CoverageURL]
|
|
2
2
|
|
|
3
3
|
[NPMIMGURL]: https://img.shields.io/npm/v/eslint-plugin-putout.svg?style=flat&longCache=true
|
|
4
|
-
[BuildStatusIMGURL]: https://img.shields.io/travis/coderaiser/eslint-plugin-putout/master.svg?style=flat&longCache=true
|
|
5
|
-
[DependencyStatusIMGURL]: https://david-dm.org/coderaiser/eslint-plugin-putout.svg?path=packages/eslint-plugin-putout
|
|
6
4
|
[NPMURL]: https://npmjs.org/package/eslint-plugin-putout "npm"
|
|
7
|
-
[BuildStatusURL]: https://travis-ci.org/coderaiser/eslint-plugin-putout "Build Status"
|
|
8
|
-
[DependencyStatusURL]: https://david-dm.org/coderaiser/eslint-plugin-putout?path=packages/eslint-plugin-putout "Dependency Status"
|
|
9
5
|
[CoverageURL]: https://coveralls.io/github/coderaiser/putout?branch=master
|
|
10
6
|
[CoverageIMGURL]: https://coveralls.io/repos/coderaiser/putout/badge.svg?branch=master&service=github
|
|
11
7
|
|
|
12
|
-
[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).
|
|
13
9
|
|
|
14
10
|
## Installation
|
|
15
11
|
|
|
@@ -40,6 +36,7 @@ Then configure the rules you want to use under the rules section.
|
|
|
40
36
|
{
|
|
41
37
|
"rules": {
|
|
42
38
|
"putout/putout": "error",
|
|
39
|
+
"putout/array-element-newline": "error",
|
|
43
40
|
"putout/single-property-destructuring": "error",
|
|
44
41
|
"putout/multiple-properties-destructuring": "error",
|
|
45
42
|
"putout/long-properties-destructuring": "error",
|
|
@@ -51,6 +48,7 @@ Then configure the rules you want to use under the rules section.
|
|
|
51
48
|
"putout/add-newlines-between-types-in-union": "error",
|
|
52
49
|
"putout/remove-newline-after-default-import": "error",
|
|
53
50
|
"putout/remove-newline-from-empty-object": "error",
|
|
51
|
+
"putout/remove-empty-newline-before-first-specifier": "error",
|
|
54
52
|
"putout/remove-empty-newline-after-last-specifier": "error",
|
|
55
53
|
"putout/objects-braces-inside-array": "error",
|
|
56
54
|
"putout/object-init": "error"
|
|
@@ -61,6 +59,7 @@ Then configure the rules you want to use under the rules section.
|
|
|
61
59
|
## Supported Rules
|
|
62
60
|
|
|
63
61
|
- [putout](lib/putout)
|
|
62
|
+
- [Array element newline](/packages/eslint-plugin-putout/lib/array-element-newline)
|
|
64
63
|
- [Single property destructuring](/packages/eslint-plugin-putout/lib/single-property-destructuring)
|
|
65
64
|
- [Multiple properties destructuring](/packages/eslint-plugin-putout/lib/multiple-properties-destructuring)
|
|
66
65
|
- [For-of multiple properties destructuring](/packages/eslint-plugin-putout/lib/for-of-multiple-properties-destructuring)
|
|
@@ -73,6 +72,7 @@ Then configure the rules you want to use under the rules section.
|
|
|
73
72
|
- [Add newlines between types in union](/packages/eslint-plugin-putout/lib/add-newlines-between-types-in-union)
|
|
74
73
|
- [Remove newline after default import](/packages/eslint-plugin-putout/lib/remove-newline-after-default-import)
|
|
75
74
|
- [Remove newline from empty object](/packages/eslint-plugin-putout/lib/remove-newline-from-empty-object)
|
|
75
|
+
- [Remove empty newline before first specifier](/packages/eslint-plugin-putout/lib/remove-empty-newline-before-first-specifier)
|
|
76
76
|
- [Remove empty newline after last specifier](/packages/eslint-plugin-putout/lib/remove-empty-newline-after-last-specifier)
|
|
77
77
|
- [Objects braces inside array](/packages/eslint-plugin-putout/lib/objects-braces-inside-array)
|
|
78
78
|
- [Object init](/packages/eslint-plugin-putout/lib/object-init)
|
|
@@ -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,48 @@
|
|
|
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 isESTreeLiteral = (a) => a.type === 'Literal';
|
|
15
|
+
|
|
16
|
+
module.exports.filter = ({text, node}) => {
|
|
17
|
+
if (isMemberExpression(node.parent))
|
|
18
|
+
return false;
|
|
19
|
+
|
|
20
|
+
const isAllPrimitives = node.elements
|
|
21
|
+
.every(isESTreeLiteral);
|
|
22
|
+
|
|
23
|
+
if (!isAllPrimitives )
|
|
24
|
+
return false;
|
|
25
|
+
|
|
26
|
+
if (!isVariableDeclarator(node.parent))
|
|
27
|
+
return false;
|
|
28
|
+
|
|
29
|
+
if (node.elements.length < 4)
|
|
30
|
+
return false;
|
|
31
|
+
|
|
32
|
+
if (regexp.test(text))
|
|
33
|
+
return true;
|
|
34
|
+
|
|
35
|
+
return false;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
module.exports.fix = ({text}) => {
|
|
39
|
+
return text
|
|
40
|
+
.replace(/\[/g, '[\n')
|
|
41
|
+
.replace(/\]/g, '\n]')
|
|
42
|
+
.replace(/,/g, ',\n');
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
module.exports.include = () => [
|
|
46
|
+
'ArrayExpression',
|
|
47
|
+
];
|
|
48
|
+
|
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'),
|
|
@@ -28,6 +29,7 @@ module.exports.rules = {
|
|
|
28
29
|
...getWrapRule('add-newlines-between-types-in-union'),
|
|
29
30
|
...getWrapRule('remove-newline-after-default-import'),
|
|
30
31
|
...getWrapRule('remove-newline-from-empty-object'),
|
|
32
|
+
...getWrapRule('remove-empty-newline-before-first-specifier'),
|
|
31
33
|
...getWrapRule('remove-empty-newline-after-last-specifier'),
|
|
32
34
|
...getWrapRule('objects-braces-inside-array'),
|
|
33
35
|
...getWrapRule('object-init'),
|
|
@@ -48,6 +50,7 @@ const recommended = {
|
|
|
48
50
|
'no-debugger': 'off',
|
|
49
51
|
'no-unused-vars': 'off',
|
|
50
52
|
|
|
53
|
+
'putout/array-element-newline': 'error',
|
|
51
54
|
'putout/single-property-destructuring': 'error',
|
|
52
55
|
'putout/multiple-properties-destructuring': 'error',
|
|
53
56
|
'putout/for-of-multiple-properties-destructuring': 'error',
|
|
@@ -60,6 +63,7 @@ const recommended = {
|
|
|
60
63
|
'putout/add-newlines-between-types-in-union': 'error',
|
|
61
64
|
'putout/remove-newline-after-default-import': 'error',
|
|
62
65
|
'putout/remove-newline-from-empty-object': 'error',
|
|
66
|
+
'putout/remove-empty-newline-before-first-specifier': 'error',
|
|
63
67
|
'putout/remove-empty-newline-after-last-specifier': 'error',
|
|
64
68
|
'putout/objects-braces-inside-array': 'error',
|
|
65
69
|
'putout/object-init': 'error',
|
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 {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# check if path can be resolved and fix if cannot (no-unresolved)
|
|
2
2
|
|
|
3
|
-
Similar to [`no-unresolved`](https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-unresolved.md) from
|
|
4
|
-
|
|
3
|
+
Similar to [`no-unresolved`](https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-unresolved.md) from
|
|
4
|
+
[`eslint-plugin-putout`](https://github.com/import-js/eslint-plugin-import). But supports only `ESM` and have `autofix`.
|
|
5
5
|
|
|
6
6
|
## Rule Details
|
|
7
7
|
|
|
@@ -27,4 +27,3 @@ Examples of **correct** code for this rule:
|
|
|
27
27
|
import x from './y.js';
|
|
28
28
|
import dir from './dir/index.js';
|
|
29
29
|
```
|
|
30
|
-
|
|
@@ -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:
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module.exports.category = 'import';
|
|
4
4
|
module.exports.report = () => 'Remove newline after last specifier';
|
|
5
5
|
|
|
6
|
-
const regExp = /\n\s+}/;
|
|
6
|
+
const regExp = /\n\n(\s+)?}/;
|
|
7
7
|
|
|
8
8
|
module.exports.filter = ({text}) => {
|
|
9
9
|
return regExp.test(text);
|
|
@@ -16,5 +16,6 @@ module.exports.fix = ({text}) => {
|
|
|
16
16
|
|
|
17
17
|
module.exports.include = () => [
|
|
18
18
|
'ImportDeclaration',
|
|
19
|
+
'ObjectExpression',
|
|
19
20
|
];
|
|
20
21
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Remove empty new line before first specifier(remove-empty-newline-before-first-specifier)
|
|
2
|
+
|
|
3
|
+
## Rule Details
|
|
4
|
+
|
|
5
|
+
This rule aims to remove empty newline before first specifier.
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import {
|
|
11
|
+
|
|
12
|
+
a,
|
|
13
|
+
b,
|
|
14
|
+
} from 'y';
|
|
15
|
+
|
|
16
|
+
push({
|
|
17
|
+
|
|
18
|
+
a,
|
|
19
|
+
b,
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Examples of **correct** code for this rule:
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import {
|
|
27
|
+
a,
|
|
28
|
+
b,
|
|
29
|
+
} from 'y';
|
|
30
|
+
|
|
31
|
+
push({
|
|
32
|
+
a,
|
|
33
|
+
b,
|
|
34
|
+
});
|
|
35
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.category = 'import';
|
|
4
|
+
module.exports.report = () => 'Remove newline before first specifier';
|
|
5
|
+
|
|
6
|
+
const regExp = /{\n(\s+)?\n/;
|
|
7
|
+
|
|
8
|
+
module.exports.filter = ({text}) => {
|
|
9
|
+
return regExp.test(text);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
module.exports.fix = ({text}) => {
|
|
13
|
+
return text
|
|
14
|
+
.replace(regExp, '{\n');
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
module.exports.include = () => [
|
|
18
|
+
'ImportDeclaration',
|
|
19
|
+
'ObjectExpression',
|
|
20
|
+
];
|
|
21
|
+
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
operator,
|
|
5
|
+
types,
|
|
6
|
+
} = require('putout');
|
|
7
|
+
|
|
4
8
|
const {
|
|
5
9
|
isRestElement,
|
|
6
10
|
isImportDeclaration,
|
|
@@ -10,6 +14,10 @@ const {
|
|
|
10
14
|
const NewLinesReg = /([\s,]+)?\n(\s+)?/g;
|
|
11
15
|
const AssignRegExp = /{\n?.*=.*\n?.*}/;
|
|
12
16
|
|
|
17
|
+
const {
|
|
18
|
+
compare,
|
|
19
|
+
} = operator;
|
|
20
|
+
|
|
13
21
|
module.exports.category = 'destructuring';
|
|
14
22
|
module.exports.report = () => 'Keep curly braces on one line when you have one destructuring property';
|
|
15
23
|
|
|
@@ -18,16 +26,19 @@ module.exports.include = () => [
|
|
|
18
26
|
'ImportDeclaration[specifiers.length=1]',
|
|
19
27
|
];
|
|
20
28
|
|
|
21
|
-
module.exports.filter = ({node, getText}) => {
|
|
22
|
-
const
|
|
29
|
+
module.exports.filter = ({node, text, getText}) => {
|
|
30
|
+
const parentText = getText(node.parent);
|
|
31
|
+
|
|
32
|
+
if (isImportDeclaration(node) && !compare(node.specifiers[0].local, node.specifiers[0].imported))
|
|
33
|
+
return false;
|
|
23
34
|
|
|
24
|
-
if (isImportDeclaration(node) && /import {\n/.test(
|
|
35
|
+
if (isImportDeclaration(node) && /import {\n/.test(text))
|
|
25
36
|
return true;
|
|
26
37
|
|
|
27
|
-
if (AssignRegExp.test(
|
|
38
|
+
if (AssignRegExp.test(parentText))
|
|
28
39
|
return false;
|
|
29
40
|
|
|
30
|
-
if (isVariableDeclarator(node) && /(const|let|var) {\n/.test(
|
|
41
|
+
if (isVariableDeclarator(node) && /(const|let|var) {\n/.test(parentText))
|
|
31
42
|
return true;
|
|
32
43
|
|
|
33
44
|
return false;
|
package/lib/yaml.js
CHANGED
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-putout",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.10.0",
|
|
4
4
|
"description": "eslint plugin for putout",
|
|
5
5
|
"release": false,
|
|
6
6
|
"tag": false,
|
|
7
|
+
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout",
|
|
7
8
|
"changelog": false,
|
|
8
9
|
"repository": {
|
|
9
10
|
"type": "git",
|