eslint-plugin-putout 14.2.0 → 14.5.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/lib/destructuring-as-function-argument/README.md +6 -7
- package/lib/keyword-spacing/index.js +4 -4
- package/lib/newline-function-call-arguments/README.md +5 -6
- package/lib/no-unresolved/README.md +12 -13
- package/lib/nonblock-statement-body-newline/README.md +21 -0
- package/lib/nonblock-statement-body-newline/index.js +36 -7
- package/lib/object-init/README.md +5 -5
- package/lib/objects-braces-inside-array/README.md +5 -4
- package/lib/remove-empty-newline-after-import/README.md +4 -6
- 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 +4 -3
- package/package.json +1 -1
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# destructuring-as-function-argument
|
|
2
2
|
|
|
3
|
-
When
|
|
3
|
+
When 🐊[**Putout**](https://github.com/coderaiser/putout) [removes unused variables](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-unused-variables#readme) located in function argument object pattern, it formats it in a multiple lines.
|
|
4
|
+
This rule aims keep curly braces in one line when you use destructuring as function argument.
|
|
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 login = ({
|
|
@@ -16,7 +15,7 @@ const login = ({
|
|
|
16
15
|
};
|
|
17
16
|
```
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
## ✅ Example of correct code
|
|
20
19
|
|
|
21
20
|
```js
|
|
22
21
|
const login = ({username, password}) => {
|
|
@@ -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,13 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# no-unresolved
|
|
2
2
|
|
|
3
|
+
Check if path can be resolved and fix if cannot.
|
|
3
4
|
Similar to [`no-unresolved`](https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-unresolved.md) from
|
|
4
|
-
[`eslint-plugin-
|
|
5
|
+
[`eslint-plugin-import`](https://github.com/import-js/eslint-plugin-import). But supports only `ESM` and have `autofix`.
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
Part of [`eslint-plugin-putout`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
[File extension is mandatory](https://nodejs.org/api/esm.html#esm_mandatory_file_extensions) and will produce an error from `node.js`:
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
```
|
|
12
|
+
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/coderaiser/putout/y' imported from /Users/coderaiser/putout/x.mjs
|
|
13
|
+
Did you mean to import ../y.js?
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## ❌ Example of incorrect code
|
|
11
17
|
|
|
12
18
|
```js
|
|
13
19
|
import x from './y';
|
|
@@ -18,14 +24,7 @@ export * as dir from './dir';
|
|
|
18
24
|
export {m} from './y';
|
|
19
25
|
```
|
|
20
26
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/coderaiser/putout/y' imported from /Users/coderaiser/putout/x.mjs
|
|
25
|
-
Did you mean to import ../y.js?
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
Examples of **correct** code for this rule:
|
|
27
|
+
## ✅ Example of correct code
|
|
29
28
|
|
|
30
29
|
```js
|
|
31
30
|
import x from './y.js';
|
|
@@ -8,6 +8,18 @@ Remove newline inside statement body. Part of [**eslint-plugin-putout**](https:/
|
|
|
8
8
|
if (a)
|
|
9
9
|
|
|
10
10
|
b();
|
|
11
|
+
|
|
12
|
+
for (a of b)
|
|
13
|
+
|
|
14
|
+
a();
|
|
15
|
+
|
|
16
|
+
while (a)
|
|
17
|
+
|
|
18
|
+
b();
|
|
19
|
+
|
|
20
|
+
for (;;)
|
|
21
|
+
|
|
22
|
+
a();
|
|
11
23
|
```
|
|
12
24
|
|
|
13
25
|
## ✅ Example of correct code
|
|
@@ -15,4 +27,13 @@ if (a)
|
|
|
15
27
|
```js
|
|
16
28
|
if (a)
|
|
17
29
|
b();
|
|
30
|
+
|
|
31
|
+
for (a of b)
|
|
32
|
+
a();
|
|
33
|
+
|
|
34
|
+
while (a)
|
|
35
|
+
b();
|
|
36
|
+
|
|
37
|
+
for (;;)
|
|
38
|
+
a();
|
|
18
39
|
```
|
|
@@ -1,26 +1,55 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {types} = require('putout');
|
|
4
|
-
const {
|
|
4
|
+
const {
|
|
5
|
+
isBlockStatement,
|
|
6
|
+
isIfStatement,
|
|
7
|
+
isExpressionStatement,
|
|
8
|
+
} = types;
|
|
5
9
|
|
|
6
10
|
const reg = /\)\n(\s+)?\n/;
|
|
7
11
|
|
|
8
|
-
module.exports.report = () => `Remove newline`;
|
|
12
|
+
module.exports.report = () => `Remove useless newline`;
|
|
9
13
|
|
|
10
14
|
module.exports.fix = ({text}) => {
|
|
11
|
-
|
|
15
|
+
const result = text.replace(reg, ')\n');
|
|
16
|
+
return result;
|
|
12
17
|
};
|
|
13
18
|
|
|
14
19
|
module.exports.include = () => [
|
|
15
20
|
'IfStatement',
|
|
21
|
+
'ForOfStatement',
|
|
22
|
+
'ForStatement',
|
|
23
|
+
'WhileStatement',
|
|
16
24
|
];
|
|
17
25
|
|
|
18
|
-
module.exports.filter = ({
|
|
19
|
-
|
|
26
|
+
module.exports.filter = ({text, node}) => {
|
|
27
|
+
if (isIf(text, node))
|
|
28
|
+
return true;
|
|
20
29
|
|
|
21
|
-
if (
|
|
30
|
+
if (isBody(text, node))
|
|
31
|
+
return true;
|
|
32
|
+
|
|
33
|
+
return false;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function isIf(text, node) {
|
|
37
|
+
if (!isIfStatement(node))
|
|
38
|
+
return false;
|
|
39
|
+
|
|
40
|
+
const {consequent, alternate} = node;
|
|
41
|
+
|
|
42
|
+
if (!isExpressionStatement(alternate) && !isExpressionStatement(consequent))
|
|
22
43
|
return false;
|
|
23
44
|
|
|
24
45
|
return reg.test(text);
|
|
25
|
-
}
|
|
46
|
+
}
|
|
26
47
|
|
|
48
|
+
function isBody(text, node) {
|
|
49
|
+
const {body} = node;
|
|
50
|
+
|
|
51
|
+
if (isBlockStatement(body))
|
|
52
|
+
return false;
|
|
53
|
+
|
|
54
|
+
return reg.test(text);
|
|
55
|
+
}
|
|
@@ -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 = [{
|
|
@@ -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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {rules} = require('@putout/eslint-config');
|
|
4
|
+
const warnOnUnsupportedTypeScriptVersion = false;
|
|
4
5
|
|
|
5
6
|
const extensionRules = {
|
|
6
7
|
'no-undef': 'off',
|
|
@@ -24,9 +25,7 @@ const extensionRules = {
|
|
|
24
25
|
// broken
|
|
25
26
|
'@typescript-eslint/indent': 'off',
|
|
26
27
|
|
|
27
|
-
'lines-between-class-members': 'off',
|
|
28
|
-
'@typescript-eslint/lines-between-class-members': 'error',
|
|
29
|
-
|
|
28
|
+
'@typescript-eslint/lines-between-class-members': 'off',
|
|
30
29
|
'@typescript-eslint/no-array-constructor': 'off',
|
|
31
30
|
|
|
32
31
|
'no-extra-parens': 'off',
|
|
@@ -68,6 +67,7 @@ const ts = {
|
|
|
68
67
|
files: '*.ts',
|
|
69
68
|
parser: '@typescript-eslint/parser',
|
|
70
69
|
parserOptions: {
|
|
70
|
+
warnOnUnsupportedTypeScriptVersion,
|
|
71
71
|
ecmaFeatures: {
|
|
72
72
|
jsx: false,
|
|
73
73
|
},
|
|
@@ -94,6 +94,7 @@ module.exports = [
|
|
|
94
94
|
...ts,
|
|
95
95
|
files: '*.tsx',
|
|
96
96
|
parserOptions: {
|
|
97
|
+
warnOnUnsupportedTypeScriptVersion,
|
|
97
98
|
ecmaFeatures: {
|
|
98
99
|
jsx: true,
|
|
99
100
|
},
|