eslint-plugin-putout 17.5.1 β 17.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
CHANGED
|
@@ -133,24 +133,43 @@ Disabled **ESLint** rules:
|
|
|
133
133
|
Disabled π**Putout** rules:
|
|
134
134
|
|
|
135
135
|
- β [`apply-template-literals`](https://github.com/coderaiser/putout/tree/v29.0.0/packages/plugin-remove-empty#readme);
|
|
136
|
+
|
|
136
137
|
- β [`remove-empty`](https://github.com/coderaiser/putout/tree/v29.0.0/packages/plugin-remove-empty#readme);
|
|
138
|
+
|
|
137
139
|
- β [`nodejs/remove-process-exit`](https://github.com/coderaiser/putout/tree/v29.0.0/packages/plugin-nodejs#remove-process-exit#readme);
|
|
140
|
+
|
|
138
141
|
- β [`remove-unused-variables`](https://github.com/coderaiser/putout/tree/v29.0.0/packages/plugin-remove-unused-variables#readme);
|
|
142
|
+
|
|
139
143
|
- β [`typescript/remove-unused-types`](https://github.com/coderaiser/putout/tree/v24.0.2/packages/plugin-typescript#remove-unused-types#readme);
|
|
140
|
-
|
|
141
|
-
- β [`remove-
|
|
144
|
+
|
|
145
|
+
- β [`remove-unused-expressions`](https://github.com/coderaiser/putout/tree/v29.0.0/packages/plugin-remove-unused-expressions#readme);
|
|
146
|
+
|
|
147
|
+
- β [`remove-unreferenced-variables`](https://github.com/coderaiser/putout/tree/v29.0.0/packages/plugin-remove-unreferenced-variables#readme);
|
|
148
|
+
|
|
142
149
|
- β [`remove-useless-arguments`](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-arguments#readme);
|
|
150
|
+
|
|
143
151
|
- β [`remove-useless-return`](https://github.com/coderaiser/putout/tree/v29.0.0/packages/plugin-remove-useless-return#readme);
|
|
144
|
-
|
|
145
|
-
- β [`remove-useless-
|
|
152
|
+
|
|
153
|
+
- β [`remove-useless-spread`](https://github.com/coderaiser/putout/tree/v29.0.0/packages/plugin-remove-useless-spread/#readme);
|
|
154
|
+
|
|
155
|
+
- β [`remove-useless-variables/rename`](https://github.com/coderaiser/putout/tree/v29.0.0/packages/plugin-remove-useless-variables#rename);
|
|
156
|
+
|
|
146
157
|
- β [`remove-skip`](https://github.com/coderaiser/putout/tree/v29.0.0/packages/plugin-tape#remove-skip);
|
|
158
|
+
|
|
147
159
|
- β [`remove-only`](https://github.com/coderaiser/putout/tree/v29.0.0/packages/plugin-tape#remove-only);
|
|
160
|
+
|
|
148
161
|
- β [`remove-console`](https://github.com/coderaiser/putout/tree/v29.0.0/packages/plugin-remove-console#readme);
|
|
162
|
+
|
|
149
163
|
- β [`remove-debugger`](https://github.com/coderaiser/putout/tree/v29.0.0/packages/plugin-remove-debugger#readme);
|
|
164
|
+
|
|
150
165
|
- β [`remove-unreachable-code`](https://github.com/coderaiser/putout/tree/v29.0.0/packages/plugin-remove-unreachable-code#readme);
|
|
166
|
+
|
|
151
167
|
- β [`for-of/for`](https://github.com/coderaiser/putout/tree/v29.1.2/packages/plugin-convert-for-to-for-of#readme);
|
|
152
|
-
|
|
153
|
-
- β [`for-of/remove-
|
|
168
|
+
|
|
169
|
+
- β [`for-of/remove-useless`](https://github.com/coderaiser/putout/tree/v29.7.1/packages/plugin-for-of#remove-useless);
|
|
170
|
+
|
|
171
|
+
- β [`for-of/remove-unused-variables`](https://github.com/coderaiser/putout/tree/29.7.1/packages/plugin-for-of#remove-unused-variables);
|
|
172
|
+
|
|
154
173
|
- β [`maybe/noop`](https://github.com/coderaiser/putout/tree/29.2.4/packages/plugin-maybe#noop);
|
|
155
174
|
|
|
156
175
|
### safe+align
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {isImportDeclaration} = require('putout').types;
|
|
4
|
+
const {parseImportSpecifiers} = require('parse-import-specifiers');
|
|
4
5
|
const {
|
|
5
6
|
isCorrectLoc,
|
|
6
7
|
isCorrectImportLoc,
|
|
@@ -9,8 +10,15 @@ const {
|
|
|
9
10
|
module.exports.category = 'destructuring';
|
|
10
11
|
module.exports.report = () => 'Keep each property on separate lines when using multiple destructuring properties';
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
const parseOptions = (options) => {
|
|
13
14
|
const {minProperties = 2} = options[0] || {};
|
|
15
|
+
return {
|
|
16
|
+
minProperties,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
module.exports.include = ({options}) => {
|
|
21
|
+
const {minProperties} = parseOptions(options);
|
|
14
22
|
|
|
15
23
|
return [
|
|
16
24
|
`VariableDeclarator[id.type="ObjectPattern"][id.properties.length>${minProperties}]`,
|
|
@@ -18,16 +26,23 @@ module.exports.include = ({options}) => {
|
|
|
18
26
|
];
|
|
19
27
|
};
|
|
20
28
|
|
|
21
|
-
module.exports.filter = ({node}) => {
|
|
29
|
+
module.exports.filter = ({node}, options) => {
|
|
30
|
+
const {minProperties} = parseOptions(options);
|
|
31
|
+
const {line} = node.loc.start;
|
|
22
32
|
const {
|
|
23
33
|
id,
|
|
24
34
|
specifiers,
|
|
25
35
|
parent,
|
|
26
36
|
} = node;
|
|
27
|
-
const {line} = node.loc.start;
|
|
28
37
|
|
|
29
|
-
if (isImportDeclaration(node))
|
|
38
|
+
if (isImportDeclaration(node)) {
|
|
39
|
+
const {defaults, imports} = parseImportSpecifiers(node.specifiers);
|
|
40
|
+
|
|
41
|
+
if (defaults.length === 1 && imports.length < minProperties)
|
|
42
|
+
return false;
|
|
43
|
+
|
|
30
44
|
return !isCorrectImportLoc(line, specifiers);
|
|
45
|
+
}
|
|
31
46
|
|
|
32
47
|
if (parent.parent && parent.parent.type === 'ForOfStatement')
|
|
33
48
|
return false;
|
package/lib/putout/index.js
CHANGED
|
@@ -14,6 +14,7 @@ const parseOptions = require('putout/parse-options');
|
|
|
14
14
|
const {parseError} = require('./parse-error');
|
|
15
15
|
|
|
16
16
|
const cwd = process.cwd();
|
|
17
|
+
|
|
17
18
|
const getContextOptions = ({options}) => {
|
|
18
19
|
const [allContextOptions = {}] = options;
|
|
19
20
|
return allContextOptions;
|
|
@@ -34,8 +35,9 @@ module.exports = {
|
|
|
34
35
|
},
|
|
35
36
|
|
|
36
37
|
create(context) {
|
|
37
|
-
const name = context.
|
|
38
|
+
const name = context.filename;
|
|
38
39
|
const options = getContextOptions(context);
|
|
40
|
+
|
|
39
41
|
const resultOptions = parseOptions({
|
|
40
42
|
name,
|
|
41
43
|
options,
|
|
@@ -44,7 +46,7 @@ module.exports = {
|
|
|
44
46
|
if (ignores(cwd, name, resultOptions))
|
|
45
47
|
return EMPTY_VISITORS;
|
|
46
48
|
|
|
47
|
-
const source = context.
|
|
49
|
+
const source = context.sourceCode;
|
|
48
50
|
const {text} = source;
|
|
49
51
|
const node = source.ast;
|
|
50
52
|
|
|
@@ -95,6 +97,7 @@ module.exports = {
|
|
|
95
97
|
|
|
96
98
|
const fix = ({ast, text, node, source, resultOptions}) => (fixer) => {
|
|
97
99
|
const includeComments = true;
|
|
100
|
+
|
|
98
101
|
const lastToken = source.getLastToken(node, {
|
|
99
102
|
includeComments,
|
|
100
103
|
});
|
|
@@ -107,4 +110,3 @@ const fix = ({ast, text, node, source, resultOptions}) => (fixer) => {
|
|
|
107
110
|
|
|
108
111
|
return fixer.replaceTextRange([0, last], code);
|
|
109
112
|
};
|
|
110
|
-
|
|
@@ -28,9 +28,11 @@ module.exports = {
|
|
|
28
28
|
create(context) {
|
|
29
29
|
return {
|
|
30
30
|
ImportDeclaration(node) {
|
|
31
|
-
const source = context.
|
|
31
|
+
const source = context.sourceCode;
|
|
32
32
|
const text = source.getText(node);
|
|
33
|
-
const newline = source
|
|
33
|
+
const newline = source
|
|
34
|
+
.getText(node, 0, 2)
|
|
35
|
+
.replace(text, '');
|
|
34
36
|
|
|
35
37
|
if (node.specifiers.length > 1)
|
|
36
38
|
return;
|
|
@@ -57,7 +59,10 @@ module.exports = {
|
|
|
57
59
|
|
|
58
60
|
fix(fixer) {
|
|
59
61
|
return [
|
|
60
|
-
fixer.removeRange([
|
|
62
|
+
fixer.removeRange([
|
|
63
|
+
node.range[1],
|
|
64
|
+
node.range[1] + 1,
|
|
65
|
+
]),
|
|
61
66
|
];
|
|
62
67
|
},
|
|
63
68
|
});
|
|
@@ -16,9 +16,11 @@ module.exports = {
|
|
|
16
16
|
create(context) {
|
|
17
17
|
return {
|
|
18
18
|
VariableDeclaration(node) {
|
|
19
|
-
const source = context.
|
|
19
|
+
const source = context.sourceCode;
|
|
20
20
|
const text = source.getText(node);
|
|
21
|
-
const newline = source
|
|
21
|
+
const newline = source
|
|
22
|
+
.getText(node, 0, 2)
|
|
23
|
+
.replace(text, '');
|
|
22
24
|
|
|
23
25
|
if (newline !== '\n\n')
|
|
24
26
|
return;
|
|
@@ -50,7 +52,10 @@ module.exports = {
|
|
|
50
52
|
|
|
51
53
|
fix(fixer) {
|
|
52
54
|
return [
|
|
53
|
-
fixer.removeRange([
|
|
55
|
+
fixer.removeRange([
|
|
56
|
+
node.range[1],
|
|
57
|
+
node.range[1] + 1,
|
|
58
|
+
]),
|
|
54
59
|
];
|
|
55
60
|
},
|
|
56
61
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-putout",
|
|
3
|
-
"version": "17.
|
|
3
|
+
"version": "17.7.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"description": "ESLint plugin for πPutout",
|
|
6
6
|
"release": false,
|
|
@@ -49,13 +49,15 @@
|
|
|
49
49
|
"@typescript-eslint/eslint-plugin": "^5.5.0",
|
|
50
50
|
"@typescript-eslint/parser": "^5.4.0",
|
|
51
51
|
"align-spaces": "^1.0.0",
|
|
52
|
-
"eslint-plugin-n": "^
|
|
52
|
+
"eslint-plugin-n": "^16.0.0",
|
|
53
53
|
"eslint-plugin-react": "^7.32.2",
|
|
54
|
+
"parse-import-specifiers": "^1.0.1",
|
|
54
55
|
"try-catch": "^3.0.0",
|
|
55
56
|
"typescript": "^5.0.4"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
58
59
|
"@babel/plugin-syntax-typescript": "^7.12.1",
|
|
60
|
+
"@putout/plugin-eslint-plugin": "*",
|
|
59
61
|
"@putout/test": "^6.0.0",
|
|
60
62
|
"c8": "^7.5.0",
|
|
61
63
|
"eslint": "^8.0.1",
|