eslint-plugin-putout 14.0.1 → 14.3.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 +10 -6
- package/lib/add-newline-after-function-call/README.md +3 -5
- package/lib/align-spaces/README.md +4 -8
- package/lib/array-element-newline/README.md +6 -8
- package/lib/evaluate/README.md +3 -4
- package/lib/for-of-multiple-properties-destructuring/README.md +9 -10
- package/lib/index.js +2 -0
- package/lib/keyword-spacing/README.md +9 -11
- package/lib/long-properties-destructuring/README.md +5 -7
- package/lib/markdown.js +0 -2
- package/lib/multiple-properties-destructuring/README.md +7 -6
- package/lib/nonblock-statement-body-newline/README.md +39 -0
- package/lib/nonblock-statement-body-newline/index.js +55 -0
- package/lib/single-property-destructuring/README.md +6 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[CoverageURL]: https://coveralls.io/github/coderaiser/putout?branch=master
|
|
6
6
|
[CoverageIMGURL]: https://coveralls.io/repos/coderaiser/putout/badge.svg?branch=master&service=github
|
|
7
7
|
|
|
8
|
-
[
|
|
8
|
+
[**ESLint**](https://eslint.org) plugin for 🐊[**Putout**](https://github.com/coderaiser/putout) with built-in rules from [**@putout/eslint-config**](https://github.com/coderaiser/putout/tree/master/packages/eslint-config#readme).
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
npm i putout eslint eslint-plugin-putout -D
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
☝️*If you installed `eslint` globally (using the `-g` flag) then you must also install `putout` and `eslint-plugin-putout` globally.*
|
|
17
17
|
|
|
18
18
|
## Usage
|
|
19
19
|
|
|
@@ -81,6 +81,10 @@ Then configure the rules you want to use under the rules section.
|
|
|
81
81
|
|
|
82
82
|
- ✅ [Add newlines between types in union](/packages/eslint-plugin-putout/lib/add-newlines-between-types-in-union#readme)
|
|
83
83
|
|
|
84
|
+
### ESM
|
|
85
|
+
|
|
86
|
+
- ✅ [No unresolved](/packages/eslint-plugin-putout/lib/no-unresolved#readme)
|
|
87
|
+
|
|
84
88
|
### Formatting
|
|
85
89
|
|
|
86
90
|
- ✅ [Add newline before function call](/packages/eslint-plugin-putout/lib/add-newline-before-function-call#readme)
|
|
@@ -104,11 +108,11 @@ Then configure the rules you want to use under the rules section.
|
|
|
104
108
|
- ✅ [Remove empty specifiers](/packages/eslint-plugin-putout/lib/remove-empty-specifiers#readme)
|
|
105
109
|
- ✅ [Objects braces inside array](/packages/eslint-plugin-putout/lib/objects-braces-inside-array#readme)
|
|
106
110
|
- ✅ [Object init](/packages/eslint-plugin-putout/lib/object-init#readme)
|
|
107
|
-
- ✅ [
|
|
111
|
+
- ✅ [Nonblock statement body newline](/packages/eslint-plugin-putout/lib/non-block-statement-body-newline#readme)
|
|
108
112
|
|
|
109
113
|
### Safe mode
|
|
110
114
|
|
|
111
|
-
When using
|
|
115
|
+
When using 🐊**Putout** in IDE with `--fix` on save, or when you want to disable the most dangerous rules, use:
|
|
112
116
|
|
|
113
117
|
```json
|
|
114
118
|
{
|
|
@@ -121,12 +125,12 @@ When using 🐊`Putout` in IDE with `--fix` on save, or when you want to disable
|
|
|
121
125
|
}
|
|
122
126
|
```
|
|
123
127
|
|
|
124
|
-
Disabled
|
|
128
|
+
Disabled **ESLint** rules:
|
|
125
129
|
|
|
126
130
|
- [`no-useless-return`](https://eslint.org/docs/rules/no-useless-return#readme)
|
|
127
131
|
- [`putout/remove-newline-from-empty-object`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout/lib/remove-newline-from-empty-object#readme)
|
|
128
132
|
|
|
129
|
-
Disabled
|
|
133
|
+
Disabled 🐊**Putout** rules:
|
|
130
134
|
|
|
131
135
|
- 🐲[`remove-empty`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-remove-empty#readme);
|
|
132
136
|
- 🐲[`nodejs/remove-process-exit`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-nodejs#remove-process-exit#readme);
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Rule Details
|
|
1
|
+
# add-newline-after-function-call
|
|
4
2
|
|
|
5
3
|
This rule aims to add newline after function call.
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
## ❌ Example of incorrect code
|
|
8
6
|
|
|
9
7
|
```js
|
|
10
8
|
export function parse() {
|
|
@@ -15,7 +13,7 @@ export function parse() {
|
|
|
15
13
|
}
|
|
16
14
|
```
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
## ✅ Example of correct code
|
|
19
17
|
|
|
20
18
|
```js
|
|
21
19
|
export function parse() {
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# aling-spaces
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
When 🐊**Putout** processes files it can remove spaces from empty line, this `rule` fixes it.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
This rule aims to shorten destricturing of one property.
|
|
8
|
-
|
|
9
|
-
Examples of **incorrect** code for this rule:
|
|
5
|
+
## ❌ Example of incorrect code
|
|
10
6
|
|
|
11
7
|
```js
|
|
12
8
|
function hello() {
|
|
@@ -18,7 +14,7 @@ function hello() {
|
|
|
18
14
|
}
|
|
19
15
|
```
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
## ✅ Example of correct code
|
|
22
18
|
|
|
23
19
|
```js
|
|
24
20
|
function hello() {
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
Because [`array-element-newline`](https://eslint.org/docs/rules/array-element-newline) requires [`array-bracket-newline`](https://eslint.org/docs/rules/array-bracket-newline).
|
|
4
|
-
And `array-bracket-newline` and conflicts with [`object-braces-inside-array`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout/lib/objects-braces-inside-array).
|
|
5
|
-
|
|
6
|
-
## Rule Details
|
|
1
|
+
# array-elements-newline
|
|
7
2
|
|
|
8
3
|
This rule aims to add newlines between array elements.
|
|
4
|
+
It exists because [`array-element-newline`](https://eslint.org/docs/rules/array-element-newline) requires [`array-bracket-newline`](https://eslint.org/docs/rules/array-bracket-newline) which conflicts with [`object-braces-inside-array`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout/lib/objects-braces-inside-array#readme).
|
|
5
|
+
|
|
6
|
+
Part of [`eslint-plugin-putout`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
## ❌ Example of incorrect code
|
|
11
9
|
|
|
12
10
|
```js
|
|
13
11
|
const a = [1, 2, 3, 4, 5, 6, 7];
|
|
14
12
|
```
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
## ✅ Example of correct code
|
|
17
15
|
|
|
18
16
|
```js
|
|
19
17
|
const a = [
|
package/lib/evaluate/README.md
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
# Evaluate
|
|
2
2
|
|
|
3
|
-
Evaluate expression started with `__putout_evaluate: `. Part of [`eslint-plugin-putout`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules)
|
|
4
|
-
|
|
3
|
+
Evaluate expression started with `__putout_evaluate: `. Part of [`eslint-plugin-putout`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
|
|
5
4
|
Provided code is processed with [`@putout/plugin-declare-undefined-variables`](https://github.com/coderaiser/putout/tree/master/packages/plugin-declare-undefined-variables):
|
|
6
5
|
|
|
7
6
|
```js
|
|
8
|
-
__putout_evaluate: join(
|
|
7
|
+
__putout_evaluate: join('hello', ' ', 'world');
|
|
9
8
|
```
|
|
10
9
|
|
|
11
10
|
and converted to:
|
|
@@ -13,7 +12,7 @@ and converted to:
|
|
|
13
12
|
```js
|
|
14
13
|
const fn = (__filename, __dirname, require) => {
|
|
15
14
|
const {join} = require('path');
|
|
16
|
-
return join(
|
|
15
|
+
return join('hello', ' ', 'world');
|
|
17
16
|
};
|
|
18
17
|
```
|
|
19
18
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# for-of-multiple-properties-destructuring
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This rule aims to shorten destructuring in `for-of` statements, keeping all properties in one line.
|
|
4
|
+
Part of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Examples of **incorrect** code for this rule:
|
|
6
|
+
## ❌ Example of incorrect code
|
|
8
7
|
|
|
9
8
|
```js
|
|
10
9
|
for ({
|
|
@@ -14,13 +13,13 @@ for ({
|
|
|
14
13
|
}
|
|
15
14
|
```
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
## Options
|
|
20
|
-
|
|
21
|
-
`maxProperties` - maximum properties count to work with.
|
|
16
|
+
## ✅ Example of correct code
|
|
22
17
|
|
|
23
18
|
```js
|
|
24
19
|
for ({username, password} of users) {
|
|
25
20
|
}
|
|
26
21
|
```
|
|
22
|
+
|
|
23
|
+
## Options
|
|
24
|
+
|
|
25
|
+
`maxProperties` - maximum properties count to work with, defaults to **8**.
|
package/lib/index.js
CHANGED
|
@@ -42,6 +42,7 @@ module.exports.rules = {
|
|
|
42
42
|
...getWrapRule('tape-add-newline-before-assertion'),
|
|
43
43
|
...getWrapRule('tape-add-newline-between-tests'),
|
|
44
44
|
...getWrapRule('tape-remove-newline-before-t-end'),
|
|
45
|
+
...getWrapRule('nonblock-statement-body-newline'),
|
|
45
46
|
...getRule('putout'),
|
|
46
47
|
...getRule('remove-empty-newline-after-import'),
|
|
47
48
|
};
|
|
@@ -83,6 +84,7 @@ const recommended = {
|
|
|
83
84
|
'putout/tape-add-newline-before-assertion': 'error',
|
|
84
85
|
'putout/tape-add-newline-between-tests': 'error',
|
|
85
86
|
'putout/tape-remove-newline-before-t-end': 'error',
|
|
87
|
+
'putout/nonblock-statement-body-newline': 'error',
|
|
86
88
|
'putout/putout': 'error',
|
|
87
89
|
|
|
88
90
|
'node/no-unsupported-features/es-syntax': 'off',
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
#
|
|
1
|
+
# keyword-spacing
|
|
2
2
|
|
|
3
|
-
When
|
|
3
|
+
When 🐊[**Putout**](https://github.com/coderaiser/putout) removes unused variable in `catch` [eslint keyword spacing](https://eslint.org/docs/rules/keyword-spacing) can't handle [optional catch binding](https://github.com/tc39/proposal-optional-catch-binding) correctly. This rule adds spaces around `catch`.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Part of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Examples of **incorrect** code for this rule:
|
|
7
|
+
## ❌ Example of incorrect code
|
|
10
8
|
|
|
11
9
|
```js
|
|
12
|
-
try
|
|
13
|
-
} catch
|
|
10
|
+
try{
|
|
11
|
+
} catch{
|
|
14
12
|
}
|
|
15
13
|
|
|
16
14
|
try {
|
|
17
|
-
}
|
|
15
|
+
}catch{
|
|
18
16
|
}
|
|
19
17
|
|
|
20
18
|
try {
|
|
21
|
-
}
|
|
19
|
+
}catch(error) {
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
if(a) {
|
|
@@ -33,7 +31,7 @@ async () => {
|
|
|
33
31
|
};
|
|
34
32
|
```
|
|
35
33
|
|
|
36
|
-
|
|
34
|
+
## ✅ Example of correct code
|
|
37
35
|
|
|
38
36
|
```js
|
|
39
37
|
try {
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
#
|
|
1
|
+
# long-properties-destructuring
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Keep each property on separate line when destructuring properties with name length **15** characters and more.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Part of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Examples of **incorrect** code for this rule:
|
|
7
|
+
## ❌ Example of incorrect code
|
|
10
8
|
|
|
11
9
|
```js
|
|
12
10
|
const {isIdentifier} = user;
|
|
13
11
|
```
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
## ✅ Example of correct code
|
|
16
14
|
|
|
17
15
|
```js
|
|
18
16
|
const {
|
package/lib/markdown.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# multiple-properties-destructuring
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Keep each property on separate line when using multiple destructuring properties
|
|
4
|
+
In the same way as **ESLint** [object-property-newline](https://eslint.org/docs/rules/object-property-newline), but for destructuring.
|
|
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
|
+
## ❌ Example of incorrect code
|
|
8
9
|
|
|
9
10
|
```js
|
|
10
11
|
const {a, b, c} = user;
|
|
@@ -14,7 +15,7 @@ const {a, b, c} = user;
|
|
|
14
15
|
import {a, b, c} from 'user';
|
|
15
16
|
```
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
## ✅ Example of correct code
|
|
18
19
|
|
|
19
20
|
```js
|
|
20
21
|
const {
|
|
@@ -34,7 +35,7 @@ import {
|
|
|
34
35
|
|
|
35
36
|
## Options
|
|
36
37
|
|
|
37
|
-
`minProperties` - minimum properties count to work with
|
|
38
|
+
`minProperties` - minimum properties count to work with, defaults: `2`.
|
|
38
39
|
|
|
39
40
|
```js
|
|
40
41
|
const {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# nonblock-statement-body-newline
|
|
2
|
+
|
|
3
|
+
Remove newline inside statement body. Part of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
|
|
4
|
+
|
|
5
|
+
## ❌ Example of incorrect code
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
if (a)
|
|
9
|
+
|
|
10
|
+
b();
|
|
11
|
+
|
|
12
|
+
for (a of b)
|
|
13
|
+
|
|
14
|
+
a();
|
|
15
|
+
|
|
16
|
+
while (a)
|
|
17
|
+
|
|
18
|
+
b();
|
|
19
|
+
|
|
20
|
+
for (;;)
|
|
21
|
+
|
|
22
|
+
a();
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## ✅ Example of correct code
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
if (a)
|
|
29
|
+
b();
|
|
30
|
+
|
|
31
|
+
for (a of b)
|
|
32
|
+
a();
|
|
33
|
+
|
|
34
|
+
while (a)
|
|
35
|
+
b();
|
|
36
|
+
|
|
37
|
+
for (;;)
|
|
38
|
+
a();
|
|
39
|
+
```
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types} = require('putout');
|
|
4
|
+
const {
|
|
5
|
+
isBlockStatement,
|
|
6
|
+
isIfStatement,
|
|
7
|
+
isExpressionStatement,
|
|
8
|
+
} = types;
|
|
9
|
+
|
|
10
|
+
const reg = /\)\n(\s+)?\n/;
|
|
11
|
+
|
|
12
|
+
module.exports.report = () => `Remove useless newline`;
|
|
13
|
+
|
|
14
|
+
module.exports.fix = ({text}) => {
|
|
15
|
+
const result = text.replace(reg, ')\n');
|
|
16
|
+
return result;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
module.exports.include = () => [
|
|
20
|
+
'IfStatement',
|
|
21
|
+
'ForOfStatement',
|
|
22
|
+
'ForStatement',
|
|
23
|
+
'WhileStatement',
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
module.exports.filter = ({text, node}) => {
|
|
27
|
+
if (isIf(text, node))
|
|
28
|
+
return true;
|
|
29
|
+
|
|
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))
|
|
43
|
+
return false;
|
|
44
|
+
|
|
45
|
+
return reg.test(text);
|
|
46
|
+
}
|
|
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,12 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# single-property-destructuring
|
|
2
2
|
|
|
3
|
-
When 🐊[
|
|
3
|
+
When 🐊[**Putout**](https://github.com/coderaiser/putout) removes unused variables declared as destructured properties, it keeps one property to take 3 lines, instead of 1.
|
|
4
|
+
This rule aims to shorten destructuring of one property, keeping curly braces in one line.
|
|
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
|
import {
|
|
@@ -19,7 +18,7 @@ const {
|
|
|
19
18
|
|
|
20
19
|
```
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
## ✅ Example of correct code
|
|
23
22
|
|
|
24
23
|
```js
|
|
25
24
|
import {password} from './user.js';
|