eslint-plugin-putout 15.6.0 → 15.7.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
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",
|
|
@@ -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)
|
|
@@ -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,44 @@
|
|
|
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
|
+
for (let i = 2; i < n; i++) {
|
|
28
|
+
const prevA = body[i - 1];
|
|
29
|
+
const spaces = getSpacesBeforeNode(prevA);
|
|
30
|
+
|
|
31
|
+
if (regExp.test(spaces))
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return true;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
module.exports.fix = ({text}) => {
|
|
39
|
+
return `\n${text}`;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
module.exports.include = () => [
|
|
43
|
+
'ReturnStatement',
|
|
44
|
+
];
|
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',
|