eslint-plugin-putout 14.11.0 → 15.1.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 +4 -2
- package/lib/add-newlines-between-specifiers/README.md +36 -0
- package/lib/add-newlines-between-specifiers/index.js +27 -0
- package/lib/index.js +4 -2
- package/lib/{object-init → object-property-newline}/README.md +23 -6
- package/lib/object-property-newline/index.js +63 -0
- package/lib/ts.js +2 -2
- package/package.json +2 -2
- package/lib/object-init/index.js +0 -42
package/README.md
CHANGED
|
@@ -36,6 +36,7 @@ Then configure the rules you want to use under the rules section.
|
|
|
36
36
|
{
|
|
37
37
|
"rules": {
|
|
38
38
|
"putout/add-newlines-between-types-in-union": "error",
|
|
39
|
+
"putout/add-newlines-between-specifiers": "error",
|
|
39
40
|
"putout/add-newline-before-function-call": "error",
|
|
40
41
|
"putout/add-newline-after-function-call": "error",
|
|
41
42
|
"putout/putout": "error",
|
|
@@ -56,7 +57,7 @@ Then configure the rules you want to use under the rules section.
|
|
|
56
57
|
"putout/remove-empty-newline-after-import": "error",
|
|
57
58
|
"putout/remove-empty-specifiers": "error",
|
|
58
59
|
"putout/objects-braces-inside-array": "error",
|
|
59
|
-
"putout/object-
|
|
60
|
+
"putout/object-property-newline": "error",
|
|
60
61
|
"putout/tape-add-newline-between-tests": "error",
|
|
61
62
|
"putout/tape-add-newline-before-assertion": "error",
|
|
62
63
|
"putout/tape-remove-newline-before-t-end": "error"
|
|
@@ -80,11 +81,13 @@ Then configure the rules you want to use under the rules section.
|
|
|
80
81
|
### TypeScript
|
|
81
82
|
|
|
82
83
|
- ✅ [Add newlines between types in union](/packages/eslint-plugin-putout/lib/add-newlines-between-types-in-union#readme)
|
|
84
|
+
- ✅ [Object property newline](/packages/eslint-plugin-putout/lib/object-property-newline#readme)
|
|
83
85
|
|
|
84
86
|
### ESM
|
|
85
87
|
|
|
86
88
|
- ✅ [No unresolved](/packages/eslint-plugin-putout/lib/no-unresolved#readme)
|
|
87
89
|
- ✅ [Remove duplicate extension](/packages/eslint-plugin-putout/lib/remove-duplicate-extensions#readme)
|
|
90
|
+
- ✅ [Add newlines between specifiers](/packages/eslint-plugin-putout/lib/add-newlines-between-specifiers#readme)
|
|
88
91
|
|
|
89
92
|
### Formatting
|
|
90
93
|
|
|
@@ -108,7 +111,6 @@ Then configure the rules you want to use under the rules section.
|
|
|
108
111
|
- ✅ [Remove empty newline after import](/packages/eslint-plugin-putout/lib/remove-empty-newline-after-import#readme)
|
|
109
112
|
- ✅ [Remove empty specifiers](/packages/eslint-plugin-putout/lib/remove-empty-specifiers#readme)
|
|
110
113
|
- ✅ [Objects braces inside array](/packages/eslint-plugin-putout/lib/objects-braces-inside-array#readme)
|
|
111
|
-
- ✅ [Object init](/packages/eslint-plugin-putout/lib/object-init#readme)
|
|
112
114
|
- ✅ [Nonblock statement body newline](/packages/eslint-plugin-putout/lib/non-block-statement-body-newline#readme)
|
|
113
115
|
|
|
114
116
|
### Safe mode
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# add-newlines-between-specifiers
|
|
2
|
+
|
|
3
|
+
This rule aims to add newlines between specifiers.
|
|
4
|
+
|
|
5
|
+
## ❌ Example of incorrect code
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
let a;
|
|
9
|
+
let b;
|
|
10
|
+
let c;
|
|
11
|
+
let d;
|
|
12
|
+
let e;
|
|
13
|
+
let f;
|
|
14
|
+
|
|
15
|
+
export {a, b, c, d, e, f};
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## ✅ Example of correct code
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
let a;
|
|
22
|
+
let b;
|
|
23
|
+
let c;
|
|
24
|
+
let d;
|
|
25
|
+
let e;
|
|
26
|
+
let f;
|
|
27
|
+
|
|
28
|
+
export {
|
|
29
|
+
a,
|
|
30
|
+
b,
|
|
31
|
+
c,
|
|
32
|
+
d,
|
|
33
|
+
e,
|
|
34
|
+
f,
|
|
35
|
+
};
|
|
36
|
+
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.category = 'layout';
|
|
4
|
+
module.exports.report = () => 'Add newlines between specifiers';
|
|
5
|
+
|
|
6
|
+
module.exports.include = () => [
|
|
7
|
+
'ExportNamedDeclaration',
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
module.exports.fix = ({text}) => {
|
|
11
|
+
return text
|
|
12
|
+
.replace(/,\s+/g, ',\n ')
|
|
13
|
+
.replace(/{/g, '{\n')
|
|
14
|
+
.replace(/}/g, '\n}')
|
|
15
|
+
.replace(/{\n+/g, '{\n')
|
|
16
|
+
.replace(/\n+}/g, '\n}');
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
module.exports.filter = ({text, node}) => {
|
|
20
|
+
const regExp = /, +?[a-zA-Z]/g;
|
|
21
|
+
|
|
22
|
+
if (node.specifiers.length < 4)
|
|
23
|
+
return false;
|
|
24
|
+
|
|
25
|
+
return regExp.test(text);
|
|
26
|
+
};
|
|
27
|
+
|
package/lib/index.js
CHANGED
|
@@ -27,6 +27,7 @@ module.exports.rules = {
|
|
|
27
27
|
...getWrapRule('newline-function-call-arguments'),
|
|
28
28
|
...getWrapRule('function-declaration-paren-newline'),
|
|
29
29
|
...getWrapRule('add-newlines-between-types-in-union'),
|
|
30
|
+
...getWrapRule('add-newlines-between-specifiers'),
|
|
30
31
|
...getWrapRule('add-newline-before-function-call'),
|
|
31
32
|
...getWrapRule('add-newline-after-function-call'),
|
|
32
33
|
...getWrapRule('remove-newline-after-default-import'),
|
|
@@ -36,7 +37,7 @@ module.exports.rules = {
|
|
|
36
37
|
...getWrapRule('remove-empty-newline-after-last-element'),
|
|
37
38
|
...getWrapRule('remove-empty-specifiers'),
|
|
38
39
|
...getWrapRule('objects-braces-inside-array'),
|
|
39
|
-
...getWrapRule('object-
|
|
40
|
+
...getWrapRule('object-property-newline'),
|
|
40
41
|
...getWrapRule('no-unresolved'),
|
|
41
42
|
...getWrapRule('remove-duplicate-extensions'),
|
|
42
43
|
...getWrapRule('evaluate'),
|
|
@@ -69,6 +70,7 @@ const recommended = {
|
|
|
69
70
|
'putout/newline-function-call-arguments': 'error',
|
|
70
71
|
'putout/function-declaration-paren-newline': 'error',
|
|
71
72
|
'putout/add-newlines-between-types-in-union': 'error',
|
|
73
|
+
'putout/add-newlines-between-specifiers': 'error',
|
|
72
74
|
'putout/add-newline-before-function-call': 'error',
|
|
73
75
|
'putout/add-newline-after-function-call': 'error',
|
|
74
76
|
'putout/remove-newline-after-default-import': 'error',
|
|
@@ -79,7 +81,7 @@ const recommended = {
|
|
|
79
81
|
'putout/remove-empty-newline-after-import': 'error',
|
|
80
82
|
'putout/remove-empty-specifiers': 'error',
|
|
81
83
|
'putout/objects-braces-inside-array': 'error',
|
|
82
|
-
'putout/object-
|
|
84
|
+
'putout/object-property-newline': 'error',
|
|
83
85
|
'putout/no-unresolved': 'error',
|
|
84
86
|
'putout/remove-duplicate-extensions': 'error',
|
|
85
87
|
'putout/evaluate': 'error',
|
|
@@ -1,20 +1,29 @@
|
|
|
1
|
-
# object-
|
|
1
|
+
# object-property-newline
|
|
2
2
|
|
|
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)
|
|
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) or using `type` and `interface` keywords in **TypeScript**.
|
|
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
|
-
```
|
|
10
|
-
const user = {
|
|
9
|
+
```ts
|
|
10
|
+
const user = {
|
|
11
|
+
name,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
module.exports = {
|
|
15
|
+
lint: 'putout lint',
|
|
16
|
+
};
|
|
11
17
|
|
|
12
|
-
|
|
18
|
+
type User = {name: string};
|
|
19
|
+
interface Place {
|
|
20
|
+
message: string
|
|
21
|
+
}
|
|
13
22
|
```
|
|
14
23
|
|
|
15
24
|
## ✅ Example of correct code
|
|
16
25
|
|
|
17
|
-
```
|
|
26
|
+
```ts
|
|
18
27
|
const user = {
|
|
19
28
|
name,
|
|
20
29
|
};
|
|
@@ -22,4 +31,12 @@ const user = {
|
|
|
22
31
|
module.exports = {
|
|
23
32
|
lint: 'putout lint',
|
|
24
33
|
};
|
|
34
|
+
|
|
35
|
+
type User = {
|
|
36
|
+
name: string,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
interface Place {
|
|
40
|
+
message: string;
|
|
41
|
+
}
|
|
25
42
|
```
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types} = require('putout');
|
|
4
|
+
const {isCorrectLoc} = require('../common');
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
isVariableDeclarator,
|
|
8
|
+
isAssignmentExpression,
|
|
9
|
+
isTSTypeAliasDeclaration,
|
|
10
|
+
} = types;
|
|
11
|
+
|
|
12
|
+
module.exports.category = 'destructuring';
|
|
13
|
+
module.exports.report = () => 'Keep each property on separate line';
|
|
14
|
+
|
|
15
|
+
module.exports.include = () => [
|
|
16
|
+
`VariableDeclarator[init.type="ObjectExpression"]`,
|
|
17
|
+
`AssignmentExpression[right.type="ObjectExpression"]`,
|
|
18
|
+
`TSTypeAliasDeclaration[typeAnnotation.type="TSTypeLiteral"]`,
|
|
19
|
+
`TSInterfaceDeclaration`,
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
module.exports.filter = ({node}) => {
|
|
23
|
+
const {
|
|
24
|
+
loc,
|
|
25
|
+
right,
|
|
26
|
+
} = node;
|
|
27
|
+
|
|
28
|
+
if (isVariableDeclarator(node)) {
|
|
29
|
+
const {init} = node;
|
|
30
|
+
const {properties} = init;
|
|
31
|
+
const {line} = loc.start;
|
|
32
|
+
|
|
33
|
+
return !isCorrectLoc(line, properties);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (isAssignmentExpression(node)) {
|
|
37
|
+
const {properties} = right;
|
|
38
|
+
const {line} = loc.start;
|
|
39
|
+
|
|
40
|
+
return !isCorrectLoc(line, properties);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (isTSTypeAliasDeclaration(node)) {
|
|
44
|
+
const {members} = node.typeAnnotation;
|
|
45
|
+
const {line} = loc.start;
|
|
46
|
+
|
|
47
|
+
return !isCorrectLoc(line, members);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const {body} = node.body;
|
|
51
|
+
const {line} = loc.start;
|
|
52
|
+
|
|
53
|
+
return !isCorrectLoc(line, body);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
module.exports.fix = ({text}) => {
|
|
57
|
+
return text
|
|
58
|
+
.replace(/,/g, ',\n ')
|
|
59
|
+
.replace(/{/g, '{\n ')
|
|
60
|
+
.replace(/}/g, '\n}')
|
|
61
|
+
.replace(/\n(\s+)?\n/g, '\n');
|
|
62
|
+
};
|
|
63
|
+
|
package/lib/ts.js
CHANGED
|
@@ -7,8 +7,8 @@ const extensionRules = {
|
|
|
7
7
|
'no-undef': 'off',
|
|
8
8
|
'no-var': 'off',
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
'@typescript-eslint/brace-style':
|
|
10
|
+
// putout/object-property-newline instead
|
|
11
|
+
'@typescript-eslint/brace-style': 'off',
|
|
12
12
|
|
|
13
13
|
'comma-dangle': 'off',
|
|
14
14
|
'@typescript-eslint/comma-dangle': rules['comma-dangle'],
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-putout",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "15.1.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "ESLint plugin for 🐊Putout",
|
|
6
6
|
"release": false,
|
|
7
7
|
"tag": false,
|
|
8
8
|
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#readme",
|
package/lib/object-init/index.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {types} = require('putout');
|
|
4
|
-
const {isCorrectLoc} = require('../common');
|
|
5
|
-
|
|
6
|
-
const {isVariableDeclarator} = types;
|
|
7
|
-
|
|
8
|
-
module.exports.category = 'destructuring';
|
|
9
|
-
module.exports.report = () => 'Keep each property on separate line';
|
|
10
|
-
|
|
11
|
-
module.exports.include = () => [
|
|
12
|
-
`VariableDeclarator[init.type="ObjectExpression"]`,
|
|
13
|
-
`AssignmentExpression[right.type="ObjectExpression"]`,
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
module.exports.filter = ({node}) => {
|
|
17
|
-
const {
|
|
18
|
-
loc,
|
|
19
|
-
right,
|
|
20
|
-
} = node;
|
|
21
|
-
|
|
22
|
-
if (isVariableDeclarator(node)) {
|
|
23
|
-
const {init} = node;
|
|
24
|
-
const {properties} = init;
|
|
25
|
-
const {line} = loc.start;
|
|
26
|
-
|
|
27
|
-
return !isCorrectLoc(line, properties);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const {properties} = right;
|
|
31
|
-
const {line} = loc.start;
|
|
32
|
-
|
|
33
|
-
return !isCorrectLoc(line, properties);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
module.exports.fix = ({text}) => {
|
|
37
|
-
return text
|
|
38
|
-
.replace(/,/g, ',\n')
|
|
39
|
-
.replace(/{/g, '{\n')
|
|
40
|
-
.replace(/}/g, '\n}');
|
|
41
|
-
};
|
|
42
|
-
|