eslint-plugin-putout 14.4.0 → 14.7.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 +18 -18
- package/lib/keyword-spacing/index.js +4 -4
- package/lib/newline-function-call-arguments/README.md +5 -6
- package/lib/object-init/README.md +5 -5
- package/lib/objects-braces-inside-array/README.md +5 -4
- package/lib/putout/index.js +9 -38
- package/lib/remove-empty-newline-after-import/README.md +4 -6
- package/lib/remove-empty-newline-after-import/index.js +1 -0
- package/lib/remove-empty-newline-after-last-element/README.md +1 -1
- package/lib/remove-empty-newline-before-first-specifier/README.md +4 -5
- package/lib/remove-empty-specifiers/README.md +4 -5
- package/lib/remove-newline-from-empty-object/README.md +4 -5
- package/lib/ts.js +2 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -132,24 +132,24 @@ Disabled **ESLint** rules:
|
|
|
132
132
|
|
|
133
133
|
Disabled 🐊**Putout** rules:
|
|
134
134
|
|
|
135
|
-
-
|
|
136
|
-
-
|
|
137
|
-
-
|
|
138
|
-
-
|
|
139
|
-
-
|
|
140
|
-
-
|
|
141
|
-
-
|
|
142
|
-
-
|
|
143
|
-
-
|
|
144
|
-
-
|
|
145
|
-
-
|
|
146
|
-
-
|
|
147
|
-
-
|
|
148
|
-
-
|
|
149
|
-
-
|
|
150
|
-
-
|
|
151
|
-
-
|
|
152
|
-
-
|
|
135
|
+
- ✅ [`remove-empty`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-remove-empty#readme);
|
|
136
|
+
- ✅ [`nodejs/remove-process-exit`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-nodejs#remove-process-exit#readme);
|
|
137
|
+
- ✅ [`remove-unused-variables`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-remove-unused-variables#readme);
|
|
138
|
+
- ✅ [`typescript/remove-unused-types`](https://github.com/coderaiser/putout/tree/v24.0.2/packages/plugin-typescript#remove-unused-types#readme);
|
|
139
|
+
- ✅ [`remove-unused-for-of-variables`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-remove-unused-for-of-variables#readme);
|
|
140
|
+
- ✅ [`remove-unused-expressions`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-removeunused-expressions#readme);
|
|
141
|
+
- ✅ [`remove-unreferenced-variables`](https://github.com/coderaiser/putout/tree/24.1.0/packages/plugin-remove-unreferenced-variables#readme);
|
|
142
|
+
- ✅ [`remove-useless-arguments`](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-arguments#readme);
|
|
143
|
+
- ✅ [`remove-useless-for-of`](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-for-of#readme);
|
|
144
|
+
- ✅ [`remove-useless-return`](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-return#readme);
|
|
145
|
+
- ✅ [`remove-useless-spread`](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-spread/#readme#readme);
|
|
146
|
+
- ✅ [`remove-useless-variables/rename`](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-arguments#rename#readme);
|
|
147
|
+
- ✅ [`remove-skip`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-tape#remove-skip);
|
|
148
|
+
- ✅ [`remove-only`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-tape#remove-only);
|
|
149
|
+
- ✅ [`remove-console`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-remove-console#readme);
|
|
150
|
+
- ✅ [`remove-debugger`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-remove-debugger#readme);
|
|
151
|
+
- ✅ [`remove-unreachable-code`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-remove-unreachable-code#readme);
|
|
152
|
+
- ✅ [`convert-for-to-for-of`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-convert-for-to-for-of#readme);
|
|
153
153
|
|
|
154
154
|
### safe+align
|
|
155
155
|
|
|
@@ -87,13 +87,13 @@ function checkSwitch(text) {
|
|
|
87
87
|
|
|
88
88
|
function fixCatch(text) {
|
|
89
89
|
return text
|
|
90
|
-
.
|
|
91
|
-
.
|
|
92
|
-
.
|
|
90
|
+
.replaceAll('catch{', 'catch {')
|
|
91
|
+
.replaceAll('}catch', '} catch')
|
|
92
|
+
.replaceAll('catch (', 'catch(');
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
function fixSwitch(text) {
|
|
96
96
|
return text
|
|
97
|
-
.
|
|
97
|
+
.replaceAll('switch (', 'switch(');
|
|
98
98
|
}
|
|
99
99
|
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# newline-function-call-arguments
|
|
2
2
|
|
|
3
3
|
Addition to eslint's [function-paren-newline](https://eslint.org/docs/rules/function-paren-newline)
|
|
4
|
+
This rule aims to fix eslint transform adding new line after opening brace.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
Part of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Examples of **incorrect** code for this rule:
|
|
8
|
+
## ❌ Example of incorrect code
|
|
10
9
|
|
|
11
10
|
```js
|
|
12
11
|
const onConnectError = squad(superFn(connect_error),
|
|
@@ -15,7 +14,7 @@ const onConnectError = squad(superFn(connect_error),
|
|
|
15
14
|
getDescription);
|
|
16
15
|
```
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
## ✅ Example of correct code
|
|
19
18
|
|
|
20
19
|
```js
|
|
21
20
|
const onConnectError = squad(
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# object-init
|
|
2
2
|
|
|
3
|
-
In the same way as
|
|
3
|
+
Keep each property on separate line when initializing an object. In the same way as **ESLint** [`object-property-newline`](https://eslint.org/docs/rules/object-property-newline) but for initializing variables with [**Object Expression**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Part of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## ❌ Example of incorrect code
|
|
8
8
|
|
|
9
9
|
```js
|
|
10
10
|
const user = {name};
|
|
@@ -12,7 +12,7 @@ const user = {name};
|
|
|
12
12
|
module.exports = {lint: 'putout lint'};
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
## ✅ Example of correct code
|
|
16
16
|
|
|
17
17
|
```js
|
|
18
18
|
const user = {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# object-braces-inside-array
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Keep braces on the same line as brackets.
|
|
4
|
+
Part of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
## ❌ Example of incorrect code
|
|
6
7
|
|
|
7
8
|
```js
|
|
8
9
|
const expected = [
|
|
@@ -15,7 +16,7 @@ const expected = [
|
|
|
15
16
|
];
|
|
16
17
|
```
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
## ✅ Example of correct code
|
|
19
20
|
|
|
20
21
|
```js
|
|
21
22
|
const expected = [{
|
package/lib/putout/index.js
CHANGED
|
@@ -10,10 +10,6 @@ const {
|
|
|
10
10
|
parse,
|
|
11
11
|
} = require('putout');
|
|
12
12
|
|
|
13
|
-
const traverse = require('@babel/traverse').default;
|
|
14
|
-
|
|
15
|
-
const v8 = require('v8');
|
|
16
|
-
|
|
17
13
|
const parseOptions = require('putout/parse-options');
|
|
18
14
|
const {parseError} = require('./parse-error');
|
|
19
15
|
|
|
@@ -23,9 +19,6 @@ const getContextOptions = ({options}) => {
|
|
|
23
19
|
return allContextOptions;
|
|
24
20
|
};
|
|
25
21
|
|
|
26
|
-
const copyAST = (a) => v8.deserialize(v8.serialize(a));
|
|
27
|
-
const returns = (a) => () => a;
|
|
28
|
-
|
|
29
22
|
const EMPTY_VISITORS = {};
|
|
30
23
|
|
|
31
24
|
module.exports = {
|
|
@@ -54,17 +47,20 @@ module.exports = {
|
|
|
54
47
|
const {text} = source;
|
|
55
48
|
const node = source.ast;
|
|
56
49
|
|
|
57
|
-
const ast = parse
|
|
58
|
-
|
|
50
|
+
const [errorParser, ast] = tryCatch(parse, text, {
|
|
51
|
+
isTS: true,
|
|
59
52
|
});
|
|
60
53
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (error)
|
|
54
|
+
if (errorParser) {
|
|
64
55
|
context.report({
|
|
65
|
-
message: `${parseError(
|
|
56
|
+
message: `${parseError(errorParser)} (putout)`,
|
|
66
57
|
node,
|
|
67
58
|
});
|
|
59
|
+
|
|
60
|
+
return EMPTY_VISITORS;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const places = findPlaces(ast, text, resultOptions);
|
|
68
64
|
|
|
69
65
|
for (const {rule, message, position} of places) {
|
|
70
66
|
context.report({
|
|
@@ -97,33 +93,8 @@ const fix = ({ast, text, node, source, resultOptions}) => (fixer) => {
|
|
|
97
93
|
|
|
98
94
|
const [, last] = lastToken.range;
|
|
99
95
|
|
|
100
|
-
removeParent(ast);
|
|
101
96
|
const code = print(ast);
|
|
102
97
|
|
|
103
98
|
return fixer.replaceTextRange([0, last], code);
|
|
104
99
|
};
|
|
105
100
|
|
|
106
|
-
const createParser = (node) => {
|
|
107
|
-
const ast = copyAST(node);
|
|
108
|
-
|
|
109
|
-
const parser = {
|
|
110
|
-
parse: returns(ast),
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
return parser;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
// ESLint adds parent to each node
|
|
117
|
-
// it makes recase go crazy
|
|
118
|
-
// so we better drop them
|
|
119
|
-
//
|
|
120
|
-
// https://github.com/eslint/eslint/blob/v8.4.0/lib/linter/linter.js#L964
|
|
121
|
-
function removeParent(ast) {
|
|
122
|
-
traverse(ast, {
|
|
123
|
-
noScope: true,
|
|
124
|
-
enter(path) {
|
|
125
|
-
delete path.node.parent;
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# remove-empty-newline-after-import
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This rule aims to remove empty newline after [`import` statement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import). Part of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Examples of **incorrect** code for this rule:
|
|
5
|
+
## ❌ Example of incorrect code
|
|
8
6
|
|
|
9
7
|
```js
|
|
10
8
|
import {readFile} from 'fs';
|
|
@@ -14,7 +12,7 @@ import {promisify} from 'util';
|
|
|
14
12
|
import index from './index.js';
|
|
15
13
|
```
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
## ✅ Example of correct code
|
|
18
16
|
|
|
19
17
|
```js
|
|
20
18
|
import {readFile} from 'fs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# remove-empty-newline-after-last-element
|
|
2
2
|
|
|
3
3
|
Remove empty newline after last element.
|
|
4
|
-
Part of [
|
|
4
|
+
Part of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
|
|
5
5
|
|
|
6
6
|
## ❌ Example of incorrect code
|
|
7
7
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Rule Details
|
|
1
|
+
# remove-empty-newline-before-first-specifier
|
|
4
2
|
|
|
5
3
|
This rule aims to remove empty newline before first specifier.
|
|
4
|
+
Part of [`eslint-plugin-putout`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
## ❌ Example of incorrect code
|
|
8
7
|
|
|
9
8
|
```js
|
|
10
9
|
import {
|
|
@@ -20,7 +19,7 @@ push({
|
|
|
20
19
|
});
|
|
21
20
|
```
|
|
22
21
|
|
|
23
|
-
|
|
22
|
+
## ✅ Example of correct code
|
|
24
23
|
|
|
25
24
|
```js
|
|
26
25
|
import {
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Rule Details
|
|
1
|
+
# remove-empty-specifiers
|
|
4
2
|
|
|
5
3
|
This rule aims to remove empty specifiers.
|
|
4
|
+
Part of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
## ❌ Example of incorrect code
|
|
8
7
|
|
|
9
8
|
```js
|
|
10
9
|
import putout, {} from 'putout';
|
|
11
10
|
```
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
## ✅ Example of correct code
|
|
14
13
|
|
|
15
14
|
```js
|
|
16
15
|
import putout from 'putout';
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Rule Details
|
|
1
|
+
# remove-newline-from-empty-object
|
|
4
2
|
|
|
5
3
|
This rule aims to remove newline from empty object.
|
|
4
|
+
Part of [`eslint-plugin-putout`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
## ❌ Example of incorrect code
|
|
8
7
|
|
|
9
8
|
```js
|
|
10
9
|
const a = {
|
|
11
10
|
};
|
|
12
11
|
```
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
## ✅ Example of correct code
|
|
15
14
|
|
|
16
15
|
```js
|
|
17
16
|
const a = {};
|
package/lib/ts.js
CHANGED
|
@@ -25,9 +25,7 @@ const extensionRules = {
|
|
|
25
25
|
// broken
|
|
26
26
|
'@typescript-eslint/indent': 'off',
|
|
27
27
|
|
|
28
|
-
'lines-between-class-members': 'off',
|
|
29
|
-
'@typescript-eslint/lines-between-class-members': 'error',
|
|
30
|
-
|
|
28
|
+
'@typescript-eslint/lines-between-class-members': 'off',
|
|
31
29
|
'@typescript-eslint/no-array-constructor': 'off',
|
|
32
30
|
|
|
33
31
|
'no-extra-parens': 'off',
|
|
@@ -106,6 +104,7 @@ module.exports = [
|
|
|
106
104
|
|
|
107
105
|
function convertPaddingLines([state, ...lines]) {
|
|
108
106
|
const newLines = [];
|
|
107
|
+
|
|
109
108
|
for (const line of lines) {
|
|
110
109
|
let {prev, next} = line;
|
|
111
110
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-putout",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.7.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"description": "eslint plugin for putout",
|
|
6
6
|
"release": false,
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@putout/test": "^5.0.0",
|
|
53
53
|
"c8": "^7.5.0",
|
|
54
54
|
"eslint": "^8.0.1",
|
|
55
|
-
"eslint-plugin-eslint-plugin": "^
|
|
55
|
+
"eslint-plugin-eslint-plugin": "^4.1.0",
|
|
56
56
|
"madrun": "^9.0.0",
|
|
57
57
|
"mocha": "^9.0.1",
|
|
58
58
|
"montag": "^1.0.0",
|