eslint-plugin-putout 13.4.0 → 13.8.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 +4 -1
- package/lib/index.js +4 -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/single-property-destructuring/README.md +6 -5
- package/lib/ts.js +22 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -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-import": "error",
|
|
55
56
|
"putout/remove-empty-specifiers": "error",
|
|
56
57
|
"putout/objects-braces-inside-array": "error",
|
|
57
58
|
"putout/object-init": "error"
|
|
@@ -80,6 +81,7 @@ Then configure the rules you want to use under the rules section.
|
|
|
80
81
|
- [Remove newline from empty object](/packages/eslint-plugin-putout/lib/remove-newline-from-empty-object)
|
|
81
82
|
- [Remove empty newline before first specifier](/packages/eslint-plugin-putout/lib/remove-empty-newline-before-first-specifier)
|
|
82
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)
|
|
83
85
|
- [Remove empty specifiers](/packages/eslint-plugin-putout/lib/remove-empty-specifiers)
|
|
84
86
|
- [Objects braces inside array](/packages/eslint-plugin-putout/lib/objects-braces-inside-array)
|
|
85
87
|
- [Object init](/packages/eslint-plugin-putout/lib/object-init)
|
|
@@ -116,8 +118,10 @@ Disabled 🐊`Putout` rules:
|
|
|
116
118
|
- [`typescript/remove-unused-types`](https://github.com/coderaiser/putout/tree/v24.0.2/packages/plugin-typescript#remove-unused-types);
|
|
117
119
|
- [`remove-unused-for-of-variables`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-unused-for-of-variables);
|
|
118
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);
|
|
119
122
|
- [`remove-useless-return`](https://github.com/coderaiser/putout/tree/master/remove-useless-return);
|
|
120
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);
|
|
121
125
|
- [`remove-useless-variables/rename`](https://github.com/coderaiser/putout/tree/master/remove-useless-arguments#rename);
|
|
122
126
|
- [`remove-skip`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-skip);
|
|
123
127
|
- [`remove-only`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-only);
|
|
@@ -129,4 +133,3 @@ Disabled 🐊`Putout` rules:
|
|
|
129
133
|
### safe+align
|
|
130
134
|
|
|
131
135
|
When you want to enable ability to align spaces on empty lines, while have all benefits of `safe` preset: use `safe+align`.
|
|
132
|
-
|
package/lib/index.js
CHANGED
|
@@ -42,6 +42,7 @@ module.exports.rules = {
|
|
|
42
42
|
...getWrapRule('tape-add-newline-between-tests'),
|
|
43
43
|
...getWrapRule('tape-remove-newline-before-t-end'),
|
|
44
44
|
...getRule('putout'),
|
|
45
|
+
...getRule('remove-empty-newline-after-import'),
|
|
45
46
|
};
|
|
46
47
|
|
|
47
48
|
const config = require('@putout/eslint-config');
|
|
@@ -71,6 +72,7 @@ const recommended = {
|
|
|
71
72
|
'putout/remove-newline-from-empty-object': 'error',
|
|
72
73
|
'putout/remove-empty-newline-before-first-specifier': 'error',
|
|
73
74
|
'putout/remove-empty-newline-after-last-specifier': 'error',
|
|
75
|
+
'putout/remove-empty-newline-after-import': 'error',
|
|
74
76
|
'putout/remove-empty-specifiers': 'error',
|
|
75
77
|
'putout/objects-braces-inside-array': 'error',
|
|
76
78
|
'putout/object-init': 'error',
|
|
@@ -114,6 +116,8 @@ const safe = {
|
|
|
114
116
|
'remove-useless-return': 'off',
|
|
115
117
|
'remove-useless-arguments': 'off',
|
|
116
118
|
'remove-useless-variables/rename': 'off',
|
|
119
|
+
'remove-useless-spread': 'off',
|
|
120
|
+
'remove-unreferenced-variables': 'off',
|
|
117
121
|
'tape/remove-skip': 'off',
|
|
118
122
|
'tape/remove-only': 'off',
|
|
119
123
|
'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);
|
|
@@ -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
|
```
|
package/lib/ts.js
CHANGED
|
@@ -44,7 +44,7 @@ const extensionRules = {
|
|
|
44
44
|
'@typescript-eslint/object-curly-spacing': 'error',
|
|
45
45
|
|
|
46
46
|
'padding-line-between-statements': 'off',
|
|
47
|
-
'@typescript-eslint/padding-line-between-statements': rules['padding-line-between-statements'],
|
|
47
|
+
'@typescript-eslint/padding-line-between-statements': convertPaddingLines(rules['padding-line-between-statements']),
|
|
48
48
|
|
|
49
49
|
'quotes': 'off',
|
|
50
50
|
'@typescript-eslint/quotes': rules.quotes,
|
|
@@ -101,3 +101,24 @@ module.exports = [
|
|
|
101
101
|
},
|
|
102
102
|
];
|
|
103
103
|
|
|
104
|
+
function convertPaddingLines([state, ...lines]) {
|
|
105
|
+
const newLines = [];
|
|
106
|
+
for (const line of lines) {
|
|
107
|
+
let {prev, next} = line;
|
|
108
|
+
|
|
109
|
+
if (prev.includes('cjs-'))
|
|
110
|
+
prev = prev.replace('cjs-', '');
|
|
111
|
+
|
|
112
|
+
if (next.includes('cjs-'))
|
|
113
|
+
next = next.replace('cjs-', '');
|
|
114
|
+
|
|
115
|
+
newLines.push({
|
|
116
|
+
...line,
|
|
117
|
+
prev,
|
|
118
|
+
next,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return [state, ...newLines];
|
|
123
|
+
}
|
|
124
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-putout",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.8.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"description": "eslint plugin for putout",
|
|
6
6
|
"release": false,
|
|
@@ -48,6 +48,8 @@
|
|
|
48
48
|
"typescript": "^4.5.2"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
+
"@babel/plugin-syntax-typescript": "^7.12.1",
|
|
52
|
+
"@putout/test": "^4.3.0",
|
|
51
53
|
"c8": "^7.5.0",
|
|
52
54
|
"eslint": "^8.0.1",
|
|
53
55
|
"eslint-plugin-eslint-plugin": "^3.2.0",
|
|
@@ -55,9 +57,8 @@
|
|
|
55
57
|
"mocha": "^9.0.1",
|
|
56
58
|
"montag": "^1.0.0",
|
|
57
59
|
"simport": "^1.2.0",
|
|
58
|
-
"supertape": "^6.
|
|
59
|
-
"try-to-catch": "^3.0.0"
|
|
60
|
-
"@babel/plugin-syntax-typescript": "^7.12.1"
|
|
60
|
+
"supertape": "^6.13.1",
|
|
61
|
+
"try-to-catch": "^3.0.0"
|
|
61
62
|
},
|
|
62
63
|
"engines": {
|
|
63
64
|
"node": ">=14"
|