eslint-plugin-putout 13.9.0 → 13.11.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 +51 -49
- package/lib/function-declaration-paren-newline/README.md +18 -8
- package/lib/function-declaration-paren-newline/index.js +17 -7
- package/lib/index.js +2 -0
- package/lib/putout/index.js +2 -1
- package/lib/remove-empty-newline-after-last-element/README.md +25 -0
- package/lib/remove-empty-newline-after-last-element/index.js +20 -0
- package/lib/remove-empty-newline-after-last-specifier/README.md +3 -3
- package/lib/remove-newline-after-default-import/README.md +4 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
12
12
|
```
|
|
13
|
-
|
|
13
|
+
npm i putout eslint eslint-plugin-putout -D
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `putout` and `eslint-plugin-putout` globally.
|
|
@@ -52,6 +52,7 @@ Then configure the rules you want to use under the rules section.
|
|
|
52
52
|
"putout/remove-newline-from-empty-object": "error",
|
|
53
53
|
"putout/remove-empty-newline-before-first-specifier": "error",
|
|
54
54
|
"putout/remove-empty-newline-after-last-specifier": "error",
|
|
55
|
+
"putout/remove-empty-newline-after-last-element": "error",
|
|
55
56
|
"putout/remove-empty-newline-after-import": "error",
|
|
56
57
|
"putout/remove-empty-specifiers": "error",
|
|
57
58
|
"putout/objects-braces-inside-array": "error",
|
|
@@ -60,35 +61,36 @@ Then configure the rules you want to use under the rules section.
|
|
|
60
61
|
}
|
|
61
62
|
```
|
|
62
63
|
|
|
63
|
-
##
|
|
64
|
-
|
|
65
|
-
- [Add newlines between types in union](/packages/eslint-plugin-putout/lib/add-newlines-between-types-in-union)
|
|
66
|
-
- [Add newline before function call](/packages/eslint-plugin-putout/lib/add-newline-before-function-call)
|
|
67
|
-
- [Add newline after function call](/packages/eslint-plugin-putout/lib/add-newline-after-function-call)
|
|
68
|
-
- [Align spaces](/packages/eslint-plugin-putout/lib/align-spaces)
|
|
69
|
-
- [Array element newline](/packages/eslint-plugin-putout/lib/array-element-newline)
|
|
70
|
-
- [Evaluate](/packages/eslint-plugin-putout/lib/evaluate)
|
|
71
|
-
- [Putout](lib/putout)
|
|
72
|
-
- [Single property destructuring](/packages/eslint-plugin-putout/lib/single-property-destructuring)
|
|
73
|
-
- [Multiple properties destructuring](/packages/eslint-plugin-putout/lib/multiple-properties-destructuring)
|
|
74
|
-
- [For-of multiple properties destructuring](/packages/eslint-plugin-putout/lib/for-of-multiple-properties-destructuring)
|
|
75
|
-
- [Long properties destructuring](/packages/eslint-plugin-putout/lib/long-properties-destructuring)
|
|
76
|
-
- [Destructuring as function argument](/packages/eslint-plugin-putout/lib/destructuring-as-function-argument)
|
|
77
|
-
- [Keyword spacing](/packages/eslint-plugin-putout/lib/keyword-spacing)
|
|
78
|
-
- [Newline function call arguments](/packages/eslint-plugin-putout/lib/newline-function-call-arguments)
|
|
79
|
-
- [Function declaration paren newline](/packages/eslint-plugin-putout/lib/function-declaration-paren-newline)
|
|
80
|
-
- [Remove newline after default import](/packages/eslint-plugin-putout/lib/remove-newline-after-default-import)
|
|
81
|
-
- [Remove newline from empty object](/packages/eslint-plugin-putout/lib/remove-newline-from-empty-object)
|
|
82
|
-
- [Remove empty newline before first specifier](/packages/eslint-plugin-putout/lib/remove-empty-newline-before-first-specifier)
|
|
83
|
-
- [Remove empty newline after last specifier](/packages/eslint-plugin-putout/lib/remove-empty-newline-after-last-specifier)
|
|
84
|
-
- [Remove empty newline after
|
|
85
|
-
- [Remove empty
|
|
86
|
-
- [
|
|
87
|
-
- [
|
|
88
|
-
- [
|
|
89
|
-
- [
|
|
90
|
-
- [Tape: add newline
|
|
91
|
-
- [Tape:
|
|
64
|
+
## Rules
|
|
65
|
+
|
|
66
|
+
- [Add newlines between types in union](/packages/eslint-plugin-putout/lib/add-newlines-between-types-in-union#readme)
|
|
67
|
+
- [Add newline before function call](/packages/eslint-plugin-putout/lib/add-newline-before-function-call#readme)
|
|
68
|
+
- [Add newline after function call](/packages/eslint-plugin-putout/lib/add-newline-after-function-call#readme)
|
|
69
|
+
- [Align spaces](/packages/eslint-plugin-putout/lib/align-spaces#readme)
|
|
70
|
+
- [Array element newline](/packages/eslint-plugin-putout/lib/array-element-newline#readme)
|
|
71
|
+
- [Evaluate](/packages/eslint-plugin-putout/lib/evaluate#readme)
|
|
72
|
+
- [Putout](lib/putout#readme)
|
|
73
|
+
- [Single property destructuring](/packages/eslint-plugin-putout/lib/single-property-destructuring#readme)
|
|
74
|
+
- [Multiple properties destructuring](/packages/eslint-plugin-putout/lib/multiple-properties-destructuring#readme)
|
|
75
|
+
- [For-of multiple properties destructuring](/packages/eslint-plugin-putout/lib/for-of-multiple-properties-destructuring#readme)
|
|
76
|
+
- [Long properties destructuring](/packages/eslint-plugin-putout/lib/long-properties-destructuring#readme)
|
|
77
|
+
- [Destructuring as function argument](/packages/eslint-plugin-putout/lib/destructuring-as-function-argument#readme)
|
|
78
|
+
- [Keyword spacing](/packages/eslint-plugin-putout/lib/keyword-spacing#readme)
|
|
79
|
+
- [Newline function call arguments](/packages/eslint-plugin-putout/lib/newline-function-call-arguments#readme)
|
|
80
|
+
- [Function declaration paren newline](/packages/eslint-plugin-putout/lib/function-declaration-paren-newline#readme)
|
|
81
|
+
- [Remove newline after default import](/packages/eslint-plugin-putout/lib/remove-newline-after-default-import#readme)
|
|
82
|
+
- [Remove newline from empty object](/packages/eslint-plugin-putout/lib/remove-newline-from-empty-object#readme)
|
|
83
|
+
- [Remove empty newline before first specifier](/packages/eslint-plugin-putout/lib/remove-empty-newline-before-first-specifier#readme)
|
|
84
|
+
- [Remove empty newline after last specifier](/packages/eslint-plugin-putout/lib/remove-empty-newline-after-last-specifier#readme)
|
|
85
|
+
- [Remove empty newline after last element](/packages/eslint-plugin-putout/lib/remove-empty-newline-after-last-element#readme)
|
|
86
|
+
- [Remove empty newline after import](/packages/eslint-plugin-putout/lib/remove-empty-newline-after-import#readme)
|
|
87
|
+
- [Remove empty specifiers](/packages/eslint-plugin-putout/lib/remove-empty-specifiers#readme)
|
|
88
|
+
- [Objects braces inside array](/packages/eslint-plugin-putout/lib/objects-braces-inside-array#readme)
|
|
89
|
+
- [Object init](/packages/eslint-plugin-putout/lib/object-init#readme)
|
|
90
|
+
- [No unresolved](/packages/eslint-plugin-putout/lib/no-unresolved#readme)
|
|
91
|
+
- [Tape: add newline before assertion]('/packages/eslint-plugin-putout/lib/tape-add-new-line-before-assertion#readme)
|
|
92
|
+
- [Tape: add newline between tests]('/packages/eslint-plugin-putout/lib/tape-add-new-line-between-tests#readme)
|
|
93
|
+
- [Tape: remove newline before t.end()]('/packages/eslint-plugin-putout/lib/tape-remove-newline-before-t-end#readme)
|
|
92
94
|
|
|
93
95
|
### Safe mode
|
|
94
96
|
|
|
@@ -107,28 +109,28 @@ When using 🐊`Putout` in IDE with `--fix` on save, or when you want to disable
|
|
|
107
109
|
|
|
108
110
|
Disabled `ESLint` rules:
|
|
109
111
|
|
|
110
|
-
- [`no-useless-return`](https://eslint.org/docs/rules/no-useless-return)
|
|
111
|
-
- [`putout/remove-newline-from-empty-object`](https://eslint.org/docs/rules/no-useless-return)
|
|
112
|
+
- [`no-useless-return`](https://eslint.org/docs/rules/no-useless-return#readme)
|
|
113
|
+
- [`putout/remove-newline-from-empty-object`](https://eslint.org/docs/rules/no-useless-return#readme)
|
|
112
114
|
|
|
113
115
|
Disabled 🐊`Putout` rules:
|
|
114
116
|
|
|
115
|
-
- [`remove-empty`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-remove-empty);
|
|
116
|
-
- [`nodejs/remove-process-exit`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-nodejs#remove-process-exit);
|
|
117
|
-
- [`remove-unused-variables`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-unused-variables);
|
|
118
|
-
- [`typescript/remove-unused-types`](https://github.com/coderaiser/putout/tree/v24.0.2/packages/plugin-typescript#remove-unused-types);
|
|
119
|
-
- [`remove-unused-for-of-variables`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-unused-for-of-variables);
|
|
120
|
-
- [`remove-unused-expressions`](https://github.com/coderaiser/putout/tree/v24.0.0/packages);
|
|
121
|
-
- [`remove-unreferenced-variables`](https://github.com/coderaiser/putout/tree/24.1.0/packages);
|
|
122
|
-
- [`remove-useless-return`](https://github.com/coderaiser/putout/tree/master/remove-useless-return);
|
|
123
|
-
- [`remove-useless-arguments`](https://github.com/coderaiser/putout/tree/master/remove-useless-arguments);
|
|
124
|
-
- [`remove-useless-spread`](https://github.com/coderaiser/putout/tree/master/remove-useless-spread/#readme);
|
|
125
|
-
- [`remove-useless-variables/rename`](https://github.com/coderaiser/putout/tree/master/remove-useless-arguments#rename);
|
|
126
|
-
- [`remove-skip`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-skip);
|
|
127
|
-
- [`remove-only`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-only);
|
|
128
|
-
- [`remove-console`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-console);
|
|
129
|
-
- [`remove-debugger`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-debugger);
|
|
130
|
-
- [`remove-unreachable-code`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-unreachable-code);
|
|
131
|
-
- [`convert-for-to-for-of`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/convert-for-to-for-of);
|
|
117
|
+
- [`remove-empty`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-remove-empty#readme);
|
|
118
|
+
- [`nodejs/remove-process-exit`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-nodejs#remove-process-exit#readme);
|
|
119
|
+
- [`remove-unused-variables`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-unused-variables#readme);
|
|
120
|
+
- [`typescript/remove-unused-types`](https://github.com/coderaiser/putout/tree/v24.0.2/packages/plugin-typescript#remove-unused-types#readme);
|
|
121
|
+
- [`remove-unused-for-of-variables`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-unused-for-of-variables#readme);
|
|
122
|
+
- [`remove-unused-expressions`](https://github.com/coderaiser/putout/tree/v24.0.0/packages#readme);
|
|
123
|
+
- [`remove-unreferenced-variables`](https://github.com/coderaiser/putout/tree/24.1.0/packages#readme);
|
|
124
|
+
- [`remove-useless-return`](https://github.com/coderaiser/putout/tree/master/remove-useless-return#readme);
|
|
125
|
+
- [`remove-useless-arguments`](https://github.com/coderaiser/putout/tree/master/remove-useless-arguments#readme);
|
|
126
|
+
- [`remove-useless-spread`](https://github.com/coderaiser/putout/tree/master/remove-useless-spread/#readme#readme);
|
|
127
|
+
- [`remove-useless-variables/rename`](https://github.com/coderaiser/putout/tree/master/remove-useless-arguments#rename#readme);
|
|
128
|
+
- [`remove-skip`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-skip#readme);
|
|
129
|
+
- [`remove-only`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-only#readme);
|
|
130
|
+
- [`remove-console`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-console#readme);
|
|
131
|
+
- [`remove-debugger`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-debugger#readme);
|
|
132
|
+
- [`remove-unreachable-code`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-unreachable-code#readme);
|
|
133
|
+
- [`convert-for-to-for-of`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/convert-for-to-for-of#readme);
|
|
132
134
|
|
|
133
135
|
### safe+align
|
|
134
136
|
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# function-declaration-paren-newline
|
|
2
2
|
|
|
3
|
-
Similar to `
|
|
3
|
+
Remove newlines between parens in function declaration. Similar to `ESLint` rule [function-paren-newline](https://eslint.org/docs/rules/function-declaration-paren-newline), but forbids new lines in function declarations and expressions arguments.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
This rule aims to add spaces around `catch`
|
|
8
|
-
|
|
9
|
-
Examples of **incorrect** code for this rule:
|
|
5
|
+
## ❌ Incorrect code example
|
|
10
6
|
|
|
11
7
|
```js
|
|
12
8
|
function f(
|
|
@@ -16,9 +12,17 @@ function f(
|
|
|
16
12
|
const fn = (
|
|
17
13
|
{a, b, c},
|
|
18
14
|
) => {};
|
|
15
|
+
|
|
16
|
+
regexpTree.traverse(ast, {
|
|
17
|
+
RegExp(
|
|
18
|
+
{node},
|
|
19
|
+
) {
|
|
20
|
+
const {body} = node;
|
|
21
|
+
},
|
|
22
|
+
});
|
|
19
23
|
```
|
|
20
24
|
|
|
21
|
-
|
|
25
|
+
## ✅ Correct code example
|
|
22
26
|
|
|
23
27
|
```js
|
|
24
28
|
function f({a, b, c}) {}
|
|
@@ -31,4 +35,10 @@ const fnWithCall = ({a, b, c}) => {
|
|
|
31
35
|
b,
|
|
32
36
|
);
|
|
33
37
|
};
|
|
38
|
+
|
|
39
|
+
regexpTree.traverse(ast, {
|
|
40
|
+
RegExp({node}) {
|
|
41
|
+
const {body} = node;
|
|
42
|
+
},
|
|
43
|
+
});
|
|
34
44
|
```
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const fixNewLines = (text) => {
|
|
4
|
-
return text
|
|
5
|
-
.replace(/\(\n\s+/, '(')
|
|
6
|
-
.replace(/,?\n\s+\)/, ')');
|
|
7
|
-
};
|
|
8
|
-
|
|
9
3
|
module.exports.report = () => {
|
|
10
4
|
return `Unexpected new lines around arguments`;
|
|
11
5
|
};
|
|
12
6
|
|
|
13
|
-
module.exports.fix = ({text}) =>
|
|
7
|
+
module.exports.fix = ({text, node, getText}) => {
|
|
8
|
+
const {body} = node.body;
|
|
9
|
+
node.body.body = [];
|
|
10
|
+
|
|
11
|
+
const paramsText = getText(node);
|
|
12
|
+
|
|
13
|
+
node.body.body = body;
|
|
14
|
+
|
|
15
|
+
const newText = paramsText
|
|
16
|
+
.replace(/\(\n(\s+)?/, '(')
|
|
17
|
+
.replace(/,?\n\s+\)/, ')')
|
|
18
|
+
.replace(/,\n(\s+)?{/, ', {')
|
|
19
|
+
.replace(/},\n(\s+)?\)/, '})')
|
|
20
|
+
.replace(/,\n(\s+)?/, ', ');
|
|
21
|
+
|
|
22
|
+
return text.replace(paramsText, newText);
|
|
23
|
+
};
|
|
14
24
|
|
|
15
25
|
module.exports.include = () => [
|
|
16
26
|
'FunctionDeclaration',
|
package/lib/index.js
CHANGED
|
@@ -33,6 +33,7 @@ module.exports.rules = {
|
|
|
33
33
|
...getWrapRule('remove-newline-from-empty-object'),
|
|
34
34
|
...getWrapRule('remove-empty-newline-before-first-specifier'),
|
|
35
35
|
...getWrapRule('remove-empty-newline-after-last-specifier'),
|
|
36
|
+
...getWrapRule('remove-empty-newline-after-last-element'),
|
|
36
37
|
...getWrapRule('remove-empty-specifiers'),
|
|
37
38
|
...getWrapRule('objects-braces-inside-array'),
|
|
38
39
|
...getWrapRule('object-init'),
|
|
@@ -72,6 +73,7 @@ const recommended = {
|
|
|
72
73
|
'putout/remove-newline-from-empty-object': 'error',
|
|
73
74
|
'putout/remove-empty-newline-before-first-specifier': 'error',
|
|
74
75
|
'putout/remove-empty-newline-after-last-specifier': 'error',
|
|
76
|
+
'putout/remove-empty-newline-after-last-element': 'error',
|
|
75
77
|
'putout/remove-empty-newline-after-import': 'error',
|
|
76
78
|
'putout/remove-empty-specifiers': 'error',
|
|
77
79
|
'putout/objects-braces-inside-array': 'error',
|
package/lib/putout/index.js
CHANGED
|
@@ -96,6 +96,8 @@ const fix = ({ast, text, node, source, resultOptions}) => (fixer) => {
|
|
|
96
96
|
transform(ast, text, resultOptions);
|
|
97
97
|
|
|
98
98
|
const [, last] = lastToken.range;
|
|
99
|
+
|
|
100
|
+
removeParent(ast);
|
|
99
101
|
const code = print(ast);
|
|
100
102
|
|
|
101
103
|
return fixer.replaceTextRange([0, last], code);
|
|
@@ -103,7 +105,6 @@ const fix = ({ast, text, node, source, resultOptions}) => (fixer) => {
|
|
|
103
105
|
|
|
104
106
|
const createParser = (node) => {
|
|
105
107
|
const ast = copyAST(node);
|
|
106
|
-
removeParent(ast);
|
|
107
108
|
|
|
108
109
|
const parser = {
|
|
109
110
|
parse: returns(ast),
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# remove-empty-newline-after-last-element
|
|
2
|
+
|
|
3
|
+
## Rule Details
|
|
4
|
+
|
|
5
|
+
This rule aims to remove empty newline after last element.
|
|
6
|
+
|
|
7
|
+
## ❌ Incorrect code example
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
push([
|
|
11
|
+
a,
|
|
12
|
+
b,
|
|
13
|
+
|
|
14
|
+
]);
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## ✅ Correct code example
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
push([
|
|
21
|
+
a,
|
|
22
|
+
b,
|
|
23
|
+
|
|
24
|
+
]);
|
|
25
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.category = 'array';
|
|
4
|
+
module.exports.report = () => 'Remove newline after last element';
|
|
5
|
+
|
|
6
|
+
const regExp = /\n\n(\s+)?]/;
|
|
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
|
+
'ArrayExpression',
|
|
19
|
+
];
|
|
20
|
+
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# remove-empty-newline-after-last-specifier
|
|
2
2
|
|
|
3
3
|
## Rule Details
|
|
4
4
|
|
|
5
5
|
This rule aims to remove empty newline after last specifier.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## ❌ Incorrect code example
|
|
8
8
|
|
|
9
9
|
```js
|
|
10
10
|
import {
|
|
@@ -20,7 +20,7 @@ push({
|
|
|
20
20
|
});
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
## ✅ Correct code example
|
|
24
24
|
|
|
25
25
|
```js
|
|
26
26
|
import {
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# remove-newline-after-default-import
|
|
2
2
|
|
|
3
3
|
Fixes [`object-curly-newline`](https://eslint.org/docs/rules/object-curly-newline) + [`eslint-plugin-modules-newline`](https://github.com/gmsorrow/eslint-plugin-modules-newline).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This rule aims to remove newline after default import, before opening curly brace (`{`).
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Examples of **incorrect** code for this rule:
|
|
7
|
+
## ❌ Incorrect code example
|
|
10
8
|
|
|
11
9
|
```js
|
|
12
10
|
import x,
|
|
@@ -16,7 +14,7 @@ import x,
|
|
|
16
14
|
} from 'y';
|
|
17
15
|
```
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
## ✅ Correct code example
|
|
20
18
|
|
|
21
19
|
```js
|
|
22
20
|
import x, {
|