eslint-plugin-putout 14.12.0 → 15.1.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 +2 -2
- package/lib/add-newlines-between-specifiers/index.js +2 -2
- package/lib/index.js +2 -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
|
@@ -57,7 +57,7 @@ Then configure the rules you want to use under the rules section.
|
|
|
57
57
|
"putout/remove-empty-newline-after-import": "error",
|
|
58
58
|
"putout/remove-empty-specifiers": "error",
|
|
59
59
|
"putout/objects-braces-inside-array": "error",
|
|
60
|
-
"putout/object-
|
|
60
|
+
"putout/object-property-newline": "error",
|
|
61
61
|
"putout/tape-add-newline-between-tests": "error",
|
|
62
62
|
"putout/tape-add-newline-before-assertion": "error",
|
|
63
63
|
"putout/tape-remove-newline-before-t-end": "error"
|
|
@@ -81,6 +81,7 @@ Then configure the rules you want to use under the rules section.
|
|
|
81
81
|
### TypeScript
|
|
82
82
|
|
|
83
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)
|
|
84
85
|
|
|
85
86
|
### ESM
|
|
86
87
|
|
|
@@ -110,7 +111,6 @@ Then configure the rules you want to use under the rules section.
|
|
|
110
111
|
- ✅ [Remove empty newline after import](/packages/eslint-plugin-putout/lib/remove-empty-newline-after-import#readme)
|
|
111
112
|
- ✅ [Remove empty specifiers](/packages/eslint-plugin-putout/lib/remove-empty-specifiers#readme)
|
|
112
113
|
- ✅ [Objects braces inside array](/packages/eslint-plugin-putout/lib/objects-braces-inside-array#readme)
|
|
113
|
-
- ✅ [Object init](/packages/eslint-plugin-putout/lib/object-init#readme)
|
|
114
114
|
- ✅ [Nonblock statement body newline](/packages/eslint-plugin-putout/lib/non-block-statement-body-newline#readme)
|
|
115
115
|
|
|
116
116
|
### Safe mode
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const regExp = /, +?[A-z]/g;
|
|
4
|
-
|
|
5
3
|
module.exports.category = 'layout';
|
|
6
4
|
module.exports.report = () => 'Add newlines between specifiers';
|
|
7
5
|
|
|
@@ -19,6 +17,8 @@ module.exports.fix = ({text}) => {
|
|
|
19
17
|
};
|
|
20
18
|
|
|
21
19
|
module.exports.filter = ({text, node}) => {
|
|
20
|
+
const regExp = /, +?[a-zA-Z]/g;
|
|
21
|
+
|
|
22
22
|
if (node.specifiers.length < 4)
|
|
23
23
|
return false;
|
|
24
24
|
|
package/lib/index.js
CHANGED
|
@@ -37,7 +37,7 @@ module.exports.rules = {
|
|
|
37
37
|
...getWrapRule('remove-empty-newline-after-last-element'),
|
|
38
38
|
...getWrapRule('remove-empty-specifiers'),
|
|
39
39
|
...getWrapRule('objects-braces-inside-array'),
|
|
40
|
-
...getWrapRule('object-
|
|
40
|
+
...getWrapRule('object-property-newline'),
|
|
41
41
|
...getWrapRule('no-unresolved'),
|
|
42
42
|
...getWrapRule('remove-duplicate-extensions'),
|
|
43
43
|
...getWrapRule('evaluate'),
|
|
@@ -81,7 +81,7 @@ const recommended = {
|
|
|
81
81
|
'putout/remove-empty-newline-after-import': 'error',
|
|
82
82
|
'putout/remove-empty-specifiers': 'error',
|
|
83
83
|
'putout/objects-braces-inside-array': 'error',
|
|
84
|
-
'putout/object-
|
|
84
|
+
'putout/object-property-newline': 'error',
|
|
85
85
|
'putout/no-unresolved': 'error',
|
|
86
86
|
'putout/remove-duplicate-extensions': 'error',
|
|
87
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(/,(\s+)?/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.1",
|
|
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
|
-
|