eslint-plugin-putout 15.6.0 → 15.8.1
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 +23 -21
- package/lib/add-newline-before-function-call/index.js +1 -3
- package/lib/add-newline-before-return/README.md +24 -0
- package/lib/add-newline-before-return/index.js +52 -0
- package/lib/index.js +2 -0
- package/lib/no-unresolved/index.js +1 -1
- package/lib/tape-remove-newline-before-t-end/README.md +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,6 +37,7 @@ Then configure the rules you want to use under the rules section.
|
|
|
37
37
|
"rules": {
|
|
38
38
|
"putout/add-newlines-between-types-in-union": "error",
|
|
39
39
|
"putout/add-newlines-between-specifiers": "error",
|
|
40
|
+
"putout/add-newline-before-return": "error",
|
|
40
41
|
"putout/add-newline-before-function-call": "error",
|
|
41
42
|
"putout/add-newline-after-function-call": "error",
|
|
42
43
|
"putout/putout": "error",
|
|
@@ -76,7 +77,7 @@ Then configure the rules you want to use under the rules section.
|
|
|
76
77
|
|
|
77
78
|
- ✅ [add newline before assertion](/packages/eslint-plugin-putout/lib/tape-add-newline-before-assertion#readme)
|
|
78
79
|
- ✅ [add newline between tests](/packages/eslint-plugin-putout/lib/tape-add-newline-between-tests#readme)
|
|
79
|
-
- ✅ [remove newline before t.end()](/packages/eslint-plugin-putout/lib/tape-remove-newline-before-t-end#readme)
|
|
80
|
+
- ✅ [remove newline before `t.end()`](/packages/eslint-plugin-putout/lib/tape-remove-newline-before-t-end#readme)
|
|
80
81
|
|
|
81
82
|
### TypeScript
|
|
82
83
|
|
|
@@ -91,6 +92,7 @@ Then configure the rules you want to use under the rules section.
|
|
|
91
92
|
|
|
92
93
|
### Formatting
|
|
93
94
|
|
|
95
|
+
- ✅ [Add newline before return](/packages/eslint-plugin-putout/lib/add-newline-before-return#readme)
|
|
94
96
|
- ✅ [Add newline before function call](/packages/eslint-plugin-putout/lib/add-newline-before-function-call#readme)
|
|
95
97
|
- ✅ [Add newline after function call](/packages/eslint-plugin-putout/lib/add-newline-after-function-call#readme)
|
|
96
98
|
- ✅ [Align spaces](/packages/eslint-plugin-putout/lib/align-spaces#readme)
|
|
@@ -130,29 +132,29 @@ When using 🐊**Putout** in IDE with `--fix` on save, or when you want to disab
|
|
|
130
132
|
|
|
131
133
|
Disabled **ESLint** rules:
|
|
132
134
|
|
|
133
|
-
- [`no-useless-return`](https://eslint.org/docs/rules/no-useless-return#readme)
|
|
134
|
-
- [`putout/remove-newline-from-empty-object`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout/lib/remove-newline-from-empty-object#readme)
|
|
135
|
+
- ❌ [`no-useless-return`](https://eslint.org/docs/rules/no-useless-return#readme)
|
|
136
|
+
- ❌ [`putout/remove-newline-from-empty-object`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout/lib/remove-newline-from-empty-object#readme)
|
|
135
137
|
|
|
136
138
|
Disabled 🐊**Putout** rules:
|
|
137
139
|
|
|
138
|
-
-
|
|
139
|
-
-
|
|
140
|
-
-
|
|
141
|
-
-
|
|
142
|
-
-
|
|
143
|
-
-
|
|
144
|
-
-
|
|
145
|
-
-
|
|
146
|
-
-
|
|
147
|
-
-
|
|
148
|
-
-
|
|
149
|
-
-
|
|
150
|
-
-
|
|
151
|
-
-
|
|
152
|
-
-
|
|
153
|
-
-
|
|
154
|
-
-
|
|
155
|
-
-
|
|
140
|
+
- ❌ [`remove-empty`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-remove-empty#readme);
|
|
141
|
+
- ❌ [`nodejs/remove-process-exit`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-nodejs#remove-process-exit#readme);
|
|
142
|
+
- ❌ [`remove-unused-variables`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-remove-unused-variables#readme);
|
|
143
|
+
- ❌ [`typescript/remove-unused-types`](https://github.com/coderaiser/putout/tree/v24.0.2/packages/plugin-typescript#remove-unused-types#readme);
|
|
144
|
+
- ❌ [`remove-unused-for-of-variables`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-remove-unused-for-of-variables#readme);
|
|
145
|
+
- ❌ [`remove-unused-expressions`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-removeunused-expressions#readme);
|
|
146
|
+
- ❌ [`remove-unreferenced-variables`](https://github.com/coderaiser/putout/tree/24.1.0/packages/plugin-remove-unreferenced-variables#readme);
|
|
147
|
+
- ❌ [`remove-useless-arguments`](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-arguments#readme);
|
|
148
|
+
- ❌ [`remove-useless-for-of`](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-for-of#readme);
|
|
149
|
+
- ❌ [`remove-useless-return`](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-return#readme);
|
|
150
|
+
- ❌ [`remove-useless-spread`](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-spread/#readme#readme);
|
|
151
|
+
- ❌ [`remove-useless-variables/rename`](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-arguments#rename#readme);
|
|
152
|
+
- ❌ [`remove-skip`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-tape#remove-skip);
|
|
153
|
+
- ❌ [`remove-only`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-tape#remove-only);
|
|
154
|
+
- ❌ [`remove-console`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-remove-console#readme);
|
|
155
|
+
- ❌ [`remove-debugger`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-remove-debugger#readme);
|
|
156
|
+
- ❌ [`remove-unreachable-code`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-remove-unreachable-code#readme);
|
|
157
|
+
- ❌ [`convert-for-to-for-of`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-convert-for-to-for-of#readme);
|
|
156
158
|
|
|
157
159
|
### safe+align
|
|
158
160
|
|
|
@@ -10,7 +10,6 @@ const {
|
|
|
10
10
|
|
|
11
11
|
const regExp = /^\n( +)?\n +$/;
|
|
12
12
|
|
|
13
|
-
module.exports.category = 'typescript';
|
|
14
13
|
module.exports.report = () => 'Add newline before expression';
|
|
15
14
|
|
|
16
15
|
module.exports.filter = ({text, node, getCommentsBefore, getSpacesBeforeNode}) => {
|
|
@@ -57,8 +56,6 @@ module.exports.filter = ({text, node, getCommentsBefore, getSpacesBeforeNode}) =
|
|
|
57
56
|
|
|
58
57
|
return true;
|
|
59
58
|
}
|
|
60
|
-
|
|
61
|
-
return false;
|
|
62
59
|
};
|
|
63
60
|
|
|
64
61
|
module.exports.fix = ({text}) => {
|
|
@@ -68,4 +65,5 @@ module.exports.fix = ({text}) => {
|
|
|
68
65
|
module.exports.include = () => [
|
|
69
66
|
'CallExpression',
|
|
70
67
|
'AssignmentExpression',
|
|
68
|
+
'ReturnStatement',
|
|
71
69
|
];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# add-newline-before-return
|
|
2
|
+
|
|
3
|
+
This rule aims to add newline before `return`. 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
|
+
export function sum() {
|
|
9
|
+
const a = 1;
|
|
10
|
+
const b = 2;
|
|
11
|
+
return a + b;
|
|
12
|
+
}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## ✅ Example of correct code
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
export function parse() {
|
|
19
|
+
const a = 1;
|
|
20
|
+
const b = 2;
|
|
21
|
+
|
|
22
|
+
return a + b;
|
|
23
|
+
}
|
|
24
|
+
```
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const regExp = /^\n( +)?\n +$/;
|
|
4
|
+
|
|
5
|
+
module.exports.report = () => `Add newline before 'return'`;
|
|
6
|
+
|
|
7
|
+
module.exports.filter = ({text, node, getCommentsBefore, getSpacesBeforeNode}) => {
|
|
8
|
+
if (getCommentsBefore(node).length)
|
|
9
|
+
return false;
|
|
10
|
+
|
|
11
|
+
const {parent} = node;
|
|
12
|
+
const {body} = parent;
|
|
13
|
+
|
|
14
|
+
if (!body)
|
|
15
|
+
return false;
|
|
16
|
+
|
|
17
|
+
const n = body.length;
|
|
18
|
+
|
|
19
|
+
if (n < 3)
|
|
20
|
+
return false;
|
|
21
|
+
|
|
22
|
+
const spaces = getSpacesBeforeNode(node, text);
|
|
23
|
+
|
|
24
|
+
if (regExp.test(spaces))
|
|
25
|
+
return false;
|
|
26
|
+
|
|
27
|
+
let i = n - 1;
|
|
28
|
+
let count = 0;
|
|
29
|
+
|
|
30
|
+
while(--i) {
|
|
31
|
+
const prevA = body[i];
|
|
32
|
+
const spaces = getSpacesBeforeNode(prevA);
|
|
33
|
+
|
|
34
|
+
if (regExp.test(spaces))
|
|
35
|
+
break;
|
|
36
|
+
|
|
37
|
+
++count;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (count < 1)
|
|
41
|
+
return false;
|
|
42
|
+
|
|
43
|
+
return true;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
module.exports.fix = ({text}) => {
|
|
47
|
+
return `\n${text}`;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
module.exports.include = () => [
|
|
51
|
+
'ReturnStatement',
|
|
52
|
+
];
|
package/lib/index.js
CHANGED
|
@@ -28,6 +28,7 @@ module.exports.rules = {
|
|
|
28
28
|
...getWrapRule('function-declaration-paren-newline'),
|
|
29
29
|
...getWrapRule('add-newlines-between-types-in-union'),
|
|
30
30
|
...getWrapRule('add-newlines-between-specifiers'),
|
|
31
|
+
...getWrapRule('add-newline-before-return'),
|
|
31
32
|
...getWrapRule('add-newline-before-function-call'),
|
|
32
33
|
...getWrapRule('add-newline-after-function-call'),
|
|
33
34
|
...getWrapRule('remove-newline-after-default-import'),
|
|
@@ -71,6 +72,7 @@ const recommended = {
|
|
|
71
72
|
'putout/function-declaration-paren-newline': 'error',
|
|
72
73
|
'putout/add-newlines-between-types-in-union': 'error',
|
|
73
74
|
'putout/add-newlines-between-specifiers': 'error',
|
|
75
|
+
'putout/add-newline-before-return': 'error',
|
|
74
76
|
'putout/add-newline-before-function-call': 'error',
|
|
75
77
|
'putout/add-newline-after-function-call': 'error',
|
|
76
78
|
'putout/remove-newline-after-default-import': 'error',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# remove-newline-before-t-end
|
|
2
2
|
|
|
3
|
-
Remove newline before `t.end()`, for [
|
|
3
|
+
Remove newline before `t.end()`, for 📼[**Supertape**](https://github.com/coderaiser/supertape).
|
|
4
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
|