eslint-plugin-putout 13.2.0 → 13.6.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 +11 -4
- package/lib/index.js +6 -0
- package/lib/remove-empty-newline-after-import/README.md +24 -0
- package/lib/remove-empty-newline-after-import/index.js +77 -0
- package/lib/remove-empty-newline-after-import/is-built-in.js +46 -0
- package/lib/remove-empty-specifiers/README.md +17 -0
- package/lib/remove-empty-specifiers/index.js +24 -0
- package/lib/single-property-destructuring/README.md +6 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,6 +52,8 @@ 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-import": "error",
|
|
56
|
+
"putout/remove-empty-specifiers": "error",
|
|
55
57
|
"putout/objects-braces-inside-array": "error",
|
|
56
58
|
"putout/object-init": "error"
|
|
57
59
|
}
|
|
@@ -79,6 +81,8 @@ Then configure the rules you want to use under the rules section.
|
|
|
79
81
|
- [Remove newline from empty object](/packages/eslint-plugin-putout/lib/remove-newline-from-empty-object)
|
|
80
82
|
- [Remove empty newline before first specifier](/packages/eslint-plugin-putout/lib/remove-empty-newline-before-first-specifier)
|
|
81
83
|
- [Remove empty newline after last specifier](/packages/eslint-plugin-putout/lib/remove-empty-newline-after-last-specifier)
|
|
84
|
+
- [Remove empty newline after import](/packages/eslint-plugin-putout/lib/remove-empty-newline-after-import)
|
|
85
|
+
- [Remove empty specifiers](/packages/eslint-plugin-putout/lib/remove-empty-specifiers)
|
|
82
86
|
- [Objects braces inside array](/packages/eslint-plugin-putout/lib/objects-braces-inside-array)
|
|
83
87
|
- [Object init](/packages/eslint-plugin-putout/lib/object-init)
|
|
84
88
|
- [No unresolved](/packages/eslint-plugin-putout/lib/no-unresolved)
|
|
@@ -101,10 +105,6 @@ When using 🐊`Putout` in IDE with `--fix` on save, or when you want to disable
|
|
|
101
105
|
}
|
|
102
106
|
```
|
|
103
107
|
|
|
104
|
-
### safe+align
|
|
105
|
-
|
|
106
|
-
When you want to enable ability to align spaces on empty lines, use `safe+align`.
|
|
107
|
-
|
|
108
108
|
Disabled `ESLint` rules:
|
|
109
109
|
|
|
110
110
|
- [`no-useless-return`](https://eslint.org/docs/rules/no-useless-return)
|
|
@@ -118,11 +118,18 @@ Disabled 🐊`Putout` rules:
|
|
|
118
118
|
- [`typescript/remove-unused-types`](https://github.com/coderaiser/putout/tree/v24.0.2/packages/plugin-typescript#remove-unused-types);
|
|
119
119
|
- [`remove-unused-for-of-variables`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-unused-for-of-variables);
|
|
120
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);
|
|
121
122
|
- [`remove-useless-return`](https://github.com/coderaiser/putout/tree/master/remove-useless-return);
|
|
122
123
|
- [`remove-useless-arguments`](https://github.com/coderaiser/putout/tree/master/remove-useless-arguments);
|
|
124
|
+
- [`remove-useless-variables/rename`](https://github.com/coderaiser/putout/tree/master/remove-useless-arguments#rename);
|
|
123
125
|
- [`remove-skip`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-skip);
|
|
124
126
|
- [`remove-only`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-only);
|
|
125
127
|
- [`remove-console`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-console);
|
|
126
128
|
- [`remove-debugger`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-debugger);
|
|
127
129
|
- [`remove-unreachable-code`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-unreachable-code);
|
|
128
130
|
- [`convert-for-to-for-of`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/convert-for-to-for-of);
|
|
131
|
+
|
|
132
|
+
### safe+align
|
|
133
|
+
|
|
134
|
+
When you want to enable ability to align spaces on empty lines, while have all benefits of `safe` preset: use `safe+align`.
|
|
135
|
+
|
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-specifiers'),
|
|
36
37
|
...getWrapRule('objects-braces-inside-array'),
|
|
37
38
|
...getWrapRule('object-init'),
|
|
38
39
|
...getWrapRule('no-unresolved'),
|
|
@@ -41,6 +42,7 @@ module.exports.rules = {
|
|
|
41
42
|
...getWrapRule('tape-add-newline-between-tests'),
|
|
42
43
|
...getWrapRule('tape-remove-newline-before-t-end'),
|
|
43
44
|
...getRule('putout'),
|
|
45
|
+
...getRule('remove-empty-newline-after-import'),
|
|
44
46
|
};
|
|
45
47
|
|
|
46
48
|
const config = require('@putout/eslint-config');
|
|
@@ -70,6 +72,8 @@ const recommended = {
|
|
|
70
72
|
'putout/remove-newline-from-empty-object': 'error',
|
|
71
73
|
'putout/remove-empty-newline-before-first-specifier': 'error',
|
|
72
74
|
'putout/remove-empty-newline-after-last-specifier': 'error',
|
|
75
|
+
'putout/remove-empty-newline-after-import': 'error',
|
|
76
|
+
'putout/remove-empty-specifiers': 'error',
|
|
73
77
|
'putout/objects-braces-inside-array': 'error',
|
|
74
78
|
'putout/object-init': 'error',
|
|
75
79
|
'putout/no-unresolved': 'error',
|
|
@@ -111,6 +115,8 @@ const safe = {
|
|
|
111
115
|
'remove-unreachable-code': 'off',
|
|
112
116
|
'remove-useless-return': 'off',
|
|
113
117
|
'remove-useless-arguments': 'off',
|
|
118
|
+
'remove-useless-variables/rename': 'off',
|
|
119
|
+
'remove-unreferenced-variables': 'off',
|
|
114
120
|
'tape/remove-skip': 'off',
|
|
115
121
|
'tape/remove-only': 'off',
|
|
116
122
|
'remove-console': 'off',
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Remove empty newline after import (`remove-empty-newline-after-import`)
|
|
2
|
+
|
|
3
|
+
## Rule Details
|
|
4
|
+
|
|
5
|
+
This rule aims to remove empty newline after `import`.
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import {readFile} from 'fs';
|
|
11
|
+
|
|
12
|
+
import {promisify} from 'util';
|
|
13
|
+
|
|
14
|
+
import index from './index.js';
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Examples of **correct** code for this rule:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import {readFile} from 'fs';
|
|
21
|
+
import {promisify} from 'util';
|
|
22
|
+
|
|
23
|
+
import index from './index.js';
|
|
24
|
+
```
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {isBuiltIn} = require('./is-built-in');
|
|
4
|
+
const isLocal = (a) => /^\./.test(a.source.value);
|
|
5
|
+
const isNode = (a) => isBuiltIn(a.source.value);
|
|
6
|
+
|
|
7
|
+
const isSameGroup = (a, b) => {
|
|
8
|
+
if (isLocal(a) && isLocal(b))
|
|
9
|
+
return true;
|
|
10
|
+
|
|
11
|
+
if (isNode(a) && isNode(b))
|
|
12
|
+
return true;
|
|
13
|
+
|
|
14
|
+
return false;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
meta: {
|
|
19
|
+
type: 'suggestion',
|
|
20
|
+
docs: {
|
|
21
|
+
description: 'Putout',
|
|
22
|
+
category: 'putout',
|
|
23
|
+
recommended: true,
|
|
24
|
+
},
|
|
25
|
+
fixable: 'code',
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
create(context) {
|
|
29
|
+
return {
|
|
30
|
+
ImportDeclaration(node) {
|
|
31
|
+
const source = context.getSourceCode();
|
|
32
|
+
const text = source.getText(node);
|
|
33
|
+
const newline = source.getText(node, 0, 2).replace(text, '');
|
|
34
|
+
|
|
35
|
+
if (node.specifiers.length > 1)
|
|
36
|
+
return;
|
|
37
|
+
|
|
38
|
+
if (newline !== '\n\n')
|
|
39
|
+
return;
|
|
40
|
+
|
|
41
|
+
const nextNode = context.getNodeByRangeIndex(node.range[1] + 2);
|
|
42
|
+
|
|
43
|
+
if (!nextNode || nextNode.type !== 'ImportDeclaration')
|
|
44
|
+
return;
|
|
45
|
+
|
|
46
|
+
if (nextNode.specifiers.length > 1)
|
|
47
|
+
return;
|
|
48
|
+
|
|
49
|
+
const allImports = getImports(node.parent);
|
|
50
|
+
|
|
51
|
+
if (!isSameGroup(node, nextNode) && allImports.length > 2)
|
|
52
|
+
return;
|
|
53
|
+
|
|
54
|
+
context.report({
|
|
55
|
+
node,
|
|
56
|
+
message: 'Remove empty newline after import',
|
|
57
|
+
|
|
58
|
+
fix(fixer) {
|
|
59
|
+
return [
|
|
60
|
+
fixer.removeRange([node.range[1], node.range[1] + 1]),
|
|
61
|
+
];
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
function getImports(node) {
|
|
70
|
+
const imports = [];
|
|
71
|
+
for (const current of node.body) {
|
|
72
|
+
if (current.type === 'ImportDeclaration')
|
|
73
|
+
imports.push(current);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return imports;
|
|
77
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const builtInsList = [
|
|
4
|
+
'assert',
|
|
5
|
+
'async_hooks',
|
|
6
|
+
'buffer',
|
|
7
|
+
'child_process',
|
|
8
|
+
'cluster',
|
|
9
|
+
'console',
|
|
10
|
+
'crypto',
|
|
11
|
+
'dgram',
|
|
12
|
+
'diagnostics_channel',
|
|
13
|
+
'dns',
|
|
14
|
+
'domain',
|
|
15
|
+
'fs',
|
|
16
|
+
'fs/promises',
|
|
17
|
+
'http',
|
|
18
|
+
'http2',
|
|
19
|
+
'https',
|
|
20
|
+
'inspector',
|
|
21
|
+
'module',
|
|
22
|
+
'os',
|
|
23
|
+
'path',
|
|
24
|
+
'perf_hooks',
|
|
25
|
+
'process',
|
|
26
|
+
'punycode',
|
|
27
|
+
'querystring',
|
|
28
|
+
'readline',
|
|
29
|
+
'repl',
|
|
30
|
+
'stream',
|
|
31
|
+
'string_decoder',
|
|
32
|
+
'timers',
|
|
33
|
+
'tls',
|
|
34
|
+
'trace_events',
|
|
35
|
+
'tty',
|
|
36
|
+
'url',
|
|
37
|
+
'util',
|
|
38
|
+
'vm',
|
|
39
|
+
'web_crypto_api',
|
|
40
|
+
'web_streams_api',
|
|
41
|
+
'wasi',
|
|
42
|
+
'worker_threads',
|
|
43
|
+
'zlib',
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
module.exports.isBuiltIn = (name) => builtInsList.includes(name);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Remove empty specifiers(`remove-empty-specifiers`)
|
|
2
|
+
|
|
3
|
+
## Rule Details
|
|
4
|
+
|
|
5
|
+
This rule aims to remove empty specifiers.
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import putout, {} from 'putout';
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Examples of **correct** code for this rule:
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import putout from 'putout';
|
|
17
|
+
```
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.category = 'object';
|
|
4
|
+
module.exports.report = () => 'Remove empty import specifiers';
|
|
5
|
+
|
|
6
|
+
module.exports.filter = ({text, node, getCommentsInside}) => {
|
|
7
|
+
const comments = getCommentsInside(node);
|
|
8
|
+
|
|
9
|
+
if (comments.length)
|
|
10
|
+
return false;
|
|
11
|
+
|
|
12
|
+
return text.includes('{}');
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
module.exports.fix = ({text}) => {
|
|
16
|
+
return text
|
|
17
|
+
.replace('import {} from', 'import')
|
|
18
|
+
.replace(/,? {}/, '');
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
module.exports.include = () => [
|
|
22
|
+
'ImportDeclaration',
|
|
23
|
+
];
|
|
24
|
+
|
|
@@ -9,22 +9,23 @@ This rule aims to shorten destructuring of one property.
|
|
|
9
9
|
Examples of **incorrect** code for this rule:
|
|
10
10
|
|
|
11
11
|
```js
|
|
12
|
+
import {
|
|
13
|
+
password,
|
|
14
|
+
} from './user.js';
|
|
15
|
+
|
|
12
16
|
const {
|
|
13
17
|
username,
|
|
14
18
|
} = user;
|
|
15
19
|
|
|
16
|
-
import {
|
|
17
|
-
password,
|
|
18
|
-
} from './user.js';
|
|
19
20
|
```
|
|
20
21
|
|
|
21
22
|
Examples of **correct** code for this rule:
|
|
22
23
|
|
|
23
24
|
```js
|
|
24
|
-
const {username} = user;
|
|
25
25
|
import {password} from './user.js';
|
|
26
|
-
|
|
27
26
|
import {
|
|
28
27
|
helloWorld as simpleHello,
|
|
29
28
|
} from './hello.js';
|
|
29
|
+
|
|
30
|
+
const {username} = user;
|
|
30
31
|
```
|