eslint-plugin-putout 14.3.0 → 14.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 +18 -18
- 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/object-init/README.md +5 -5
- package/lib/objects-braces-inside-array/README.md +5 -4
- package/lib/putout/index.js +11 -2
- 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 +5 -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
|
|
|
@@ -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';
|
|
@@ -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
|
@@ -58,6 +58,9 @@ module.exports = {
|
|
|
58
58
|
parser: createParser(node),
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
+
// remove parent nodes that was ignored before converting to babel
|
|
62
|
+
removeParent(ast);
|
|
63
|
+
|
|
61
64
|
const [error, places = []] = tryCatch(findPlaces, ast, text, resultOptions);
|
|
62
65
|
|
|
63
66
|
if (error)
|
|
@@ -97,14 +100,20 @@ const fix = ({ast, text, node, source, resultOptions}) => (fixer) => {
|
|
|
97
100
|
|
|
98
101
|
const [, last] = lastToken.range;
|
|
99
102
|
|
|
100
|
-
removeParent(ast);
|
|
101
103
|
const code = print(ast);
|
|
102
104
|
|
|
103
105
|
return fixer.replaceTextRange([0, last], code);
|
|
104
106
|
};
|
|
105
107
|
|
|
108
|
+
// 1. We cannot modify ESLint AST
|
|
109
|
+
// 2. Parent nodes makes Recast go crazy, so they should be removed
|
|
110
|
+
// 3. Recast creates original nodes with copies of each nodes
|
|
111
|
+
// 4. Parser does nothing but returns original AST before estree to babel
|
|
112
|
+
// 5. All this stuff made to gain performance benefit of avoiding a duble parsing: ESLint, and then Babel
|
|
113
|
+
// 6. Always can be removed and switched to direct parsing by Putout, when benefits outweight supporting all of this magic
|
|
106
114
|
const createParser = (node) => {
|
|
107
115
|
const ast = copyAST(node);
|
|
116
|
+
removeParent(ast);
|
|
108
117
|
|
|
109
118
|
const parser = {
|
|
110
119
|
parse: returns(ast),
|
|
@@ -115,7 +124,7 @@ const createParser = (node) => {
|
|
|
115
124
|
|
|
116
125
|
// ESLint adds parent to each node
|
|
117
126
|
// it makes recase go crazy
|
|
118
|
-
// so we better drop them
|
|
127
|
+
// so we better drop them out
|
|
119
128
|
//
|
|
120
129
|
// https://github.com/eslint/eslint/blob/v8.4.0/lib/linter/linter.js#L964
|
|
121
130
|
function removeParent(ast) {
|
|
@@ -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
|
},
|
|
@@ -103,6 +104,7 @@ module.exports = [
|
|
|
103
104
|
|
|
104
105
|
function convertPaddingLines([state, ...lines]) {
|
|
105
106
|
const newLines = [];
|
|
107
|
+
|
|
106
108
|
for (const line of lines) {
|
|
107
109
|
let {prev, next} = line;
|
|
108
110
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-putout",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.6.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",
|