eslint-plugin-putout 11.2.0 → 11.6.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 +6 -0
- package/lib/add-newlines-between-types-in-union/README.md +20 -0
- package/lib/add-newlines-between-types-in-union/index.js +32 -0
- package/lib/index.js +6 -0
- package/lib/markdown.js +2 -0
- package/lib/remove-empty-newline-after-last-specifier/README.md +24 -0
- package/lib/remove-empty-newline-after-last-specifier/index.js +20 -0
- package/lib/remove-newline-from-empty-object/README.md +19 -0
- package/lib/remove-newline-from-empty-object/index.js +26 -0
- package/lib/ts.js +3 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -48,7 +48,10 @@ Then configure the rules you want to use under the rules section.
|
|
|
48
48
|
"putout/keyword-spacing": "error",
|
|
49
49
|
"putout/newline-function-call-arguments": "error",
|
|
50
50
|
"putout/function-declaration-paren-newline": "error",
|
|
51
|
+
"putout/add-newlines-between-types-in-union": "error",
|
|
51
52
|
"putout/remove-newline-after-default-import": "error",
|
|
53
|
+
"putout/remove-newline-from-empty-object": "error",
|
|
54
|
+
"putout/remove-empty-newline-after-last-specifier": "error",
|
|
52
55
|
"putout/objects-braces-inside-array": "error",
|
|
53
56
|
"putout/object-init": "error"
|
|
54
57
|
}
|
|
@@ -67,7 +70,10 @@ Then configure the rules you want to use under the rules section.
|
|
|
67
70
|
- [Keyword spacing](/packages/eslint-plugin-putout/lib/keyword-spacing)
|
|
68
71
|
- [Newline function call arguments](/packages/eslint-plugin-putout/lib/newline-function-call-arguments)
|
|
69
72
|
- [Function declaration paren newline](/packages/eslint-plugin-putout/lib/function-declaration-paren-newline)
|
|
73
|
+
- [Add newlines between types in union](/packages/eslint-plugin-putout/lib/add-newlines-between-types-in-union)
|
|
70
74
|
- [Remove newline after default import](/packages/eslint-plugin-putout/lib/remove-newline-after-default-import)
|
|
75
|
+
- [Remove newline from empty object](/packages/eslint-plugin-putout/lib/remove-newline-from-empty-object)
|
|
76
|
+
- [Remove empty newline after last specifier](/packages/eslint-plugin-putout/lib/remove-empty-newline-after-last-specifier)
|
|
71
77
|
- [Objects braces inside array](/packages/eslint-plugin-putout/lib/objects-braces-inside-array)
|
|
72
78
|
- [Object init](/packages/eslint-plugin-putout/lib/object-init)
|
|
73
79
|
- [No unresolved](/packages/eslint-plugin-putout/lib/no-unresolved)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Add new lines between types in union (add-newlines-between-types-in-union)
|
|
2
|
+
|
|
3
|
+
## Rule Details
|
|
4
|
+
|
|
5
|
+
This rule aims to add newlines between types in union.
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
const a = string | number | object | boolean;
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Examples of **correct** code for this rule:
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
const a = string
|
|
17
|
+
| number
|
|
18
|
+
| object
|
|
19
|
+
| boolean;
|
|
20
|
+
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types} = require('putout');
|
|
4
|
+
|
|
5
|
+
const {isTSTypeAliasDeclaration} = types;
|
|
6
|
+
|
|
7
|
+
module.exports.category = 'typescript';
|
|
8
|
+
module.exports.report = () => 'Add newlines between types in union';
|
|
9
|
+
|
|
10
|
+
const regExp = /[^\n]\|\s[A-Za-z]/;
|
|
11
|
+
|
|
12
|
+
module.exports.filter = ({text, node}) => {
|
|
13
|
+
if (!isTSTypeAliasDeclaration(node.parent))
|
|
14
|
+
return false;
|
|
15
|
+
|
|
16
|
+
if (text.includes('\n'))
|
|
17
|
+
return false;
|
|
18
|
+
|
|
19
|
+
if (node.types.length <= 3)
|
|
20
|
+
return false;
|
|
21
|
+
|
|
22
|
+
return regExp.test(text);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
module.exports.fix = ({text}) => {
|
|
26
|
+
return text.replace(/\s\|/g, '\n |');
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
module.exports.include = () => [
|
|
30
|
+
'TSUnionType',
|
|
31
|
+
];
|
|
32
|
+
|
package/lib/index.js
CHANGED
|
@@ -25,7 +25,10 @@ module.exports.rules = {
|
|
|
25
25
|
...getWrapRule('keyword-spacing'),
|
|
26
26
|
...getWrapRule('newline-function-call-arguments'),
|
|
27
27
|
...getWrapRule('function-declaration-paren-newline'),
|
|
28
|
+
...getWrapRule('add-newlines-between-types-in-union'),
|
|
28
29
|
...getWrapRule('remove-newline-after-default-import'),
|
|
30
|
+
...getWrapRule('remove-newline-from-empty-object'),
|
|
31
|
+
...getWrapRule('remove-empty-newline-after-last-specifier'),
|
|
29
32
|
...getWrapRule('objects-braces-inside-array'),
|
|
30
33
|
...getWrapRule('object-init'),
|
|
31
34
|
...getWrapRule('no-unresolved'),
|
|
@@ -54,7 +57,10 @@ const recommended = {
|
|
|
54
57
|
'putout/keyword-spacing': 'error',
|
|
55
58
|
'putout/newline-function-call-arguments': 'error',
|
|
56
59
|
'putout/function-declaration-paren-newline': 'error',
|
|
60
|
+
'putout/add-newlines-between-types-in-union': 'error',
|
|
57
61
|
'putout/remove-newline-after-default-import': 'error',
|
|
62
|
+
'putout/remove-newline-from-empty-object': 'error',
|
|
63
|
+
'putout/remove-empty-newline-after-last-specifier': 'error',
|
|
58
64
|
'putout/objects-braces-inside-array': 'error',
|
|
59
65
|
'putout/object-init': 'error',
|
|
60
66
|
'putout/no-unresolved': 'error',
|
package/lib/markdown.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const parserOpts = require('@putout/engine-parser/babel/options');
|
|
3
4
|
const [ts] = require('./ts');
|
|
4
5
|
|
|
5
6
|
const commonRules = {
|
|
@@ -29,6 +30,7 @@ module.exports = [{
|
|
|
29
30
|
requireConfigFile: false,
|
|
30
31
|
babelOptions: {
|
|
31
32
|
sourceType: 'module',
|
|
33
|
+
parserOpts,
|
|
32
34
|
plugins: [
|
|
33
35
|
'@babel/plugin-syntax-class-properties',
|
|
34
36
|
'@babel/plugin-syntax-top-level-await',
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Remove empty new line after last specifier(remove-empty-newline-after-last-specifier)
|
|
2
|
+
|
|
3
|
+
## Rule Details
|
|
4
|
+
|
|
5
|
+
This rule aims to remove empty newline after last specifier.
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import {
|
|
11
|
+
a,
|
|
12
|
+
b,
|
|
13
|
+
|
|
14
|
+
} from 'y';
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Examples of **correct** code for this rule:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import {
|
|
21
|
+
a,
|
|
22
|
+
b,
|
|
23
|
+
} from 'y';
|
|
24
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.category = 'import';
|
|
4
|
+
module.exports.report = () => 'Remove newline after last specifier';
|
|
5
|
+
|
|
6
|
+
const regExp = /\n\s+}/;
|
|
7
|
+
|
|
8
|
+
module.exports.filter = ({text}) => {
|
|
9
|
+
return regExp.test(text);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
module.exports.fix = ({text}) => {
|
|
13
|
+
return text
|
|
14
|
+
.replace(regExp, '\n}');
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
module.exports.include = () => [
|
|
18
|
+
'ImportDeclaration',
|
|
19
|
+
];
|
|
20
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Remove new line in empty object (remove-newline-from-empty-object)
|
|
2
|
+
|
|
3
|
+
## Rule Details
|
|
4
|
+
|
|
5
|
+
This rule aims to remove newline from empty object.
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
const a = {
|
|
11
|
+
|
|
12
|
+
};
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Examples of **correct** code for this rule:
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
const a = {};
|
|
19
|
+
```
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types} = require('putout');
|
|
4
|
+
const {isArrayExpression} = types;
|
|
5
|
+
|
|
6
|
+
module.exports.category = 'object';
|
|
7
|
+
module.exports.report = () => 'Remove newline from empty object';
|
|
8
|
+
|
|
9
|
+
const regExp = /\n/;
|
|
10
|
+
|
|
11
|
+
module.exports.filter = ({text, node}) => {
|
|
12
|
+
if (isArrayExpression(node.parent))
|
|
13
|
+
return false;
|
|
14
|
+
|
|
15
|
+
if (node.properties.length)
|
|
16
|
+
return false;
|
|
17
|
+
|
|
18
|
+
return regExp.test(text);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
module.exports.fix = () => '{}';
|
|
22
|
+
|
|
23
|
+
module.exports.include = () => [
|
|
24
|
+
'ObjectExpression',
|
|
25
|
+
];
|
|
26
|
+
|
package/lib/ts.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const parserOpts = require('@putout/engine-parser/babel/options');
|
|
4
|
+
|
|
3
5
|
module.exports = [{
|
|
4
6
|
files: '*.ts',
|
|
5
7
|
parser: '@babel/eslint-parser/experimental-worker',
|
|
6
8
|
parserOptions: {
|
|
7
9
|
requireConfigFile: false,
|
|
8
10
|
babelOptions: {
|
|
11
|
+
parserOpts,
|
|
9
12
|
plugins: ['@babel/plugin-syntax-typescript'],
|
|
10
13
|
},
|
|
11
14
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-putout",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.6.0",
|
|
4
4
|
"description": "eslint plugin for putout",
|
|
5
5
|
"release": false,
|
|
6
6
|
"tag": false,
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@babel/plugin-syntax-class-properties": "^7.12.1",
|
|
38
38
|
"@babel/plugin-syntax-top-level-await": "^7.12.1",
|
|
39
39
|
"@babel/plugin-syntax-typescript": "^7.12.1",
|
|
40
|
+
"@putout/engine-parser": "^4.6.0",
|
|
40
41
|
"@putout/eslint-config": "^6.0.0",
|
|
41
42
|
"align-spaces": "^1.0.0",
|
|
42
43
|
"eslint-plugin-node": "^11.0.0",
|