eslint-plugin-putout 11.1.0 → 11.5.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
@@ -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)
@@ -97,6 +103,7 @@ List of disabled `putout` rules:
97
103
  - [remove-unused-types](https://github.com/coderaiser/putout/tree/v20.0.0/packages/remove-unused-types);
98
104
  - [remove-unused-for-of-variables](https://github.com/coderaiser/putout/tree/v20.0.0/packages/remove-unused-for-of-variables);
99
105
  - [remove-unused-expressions](https://github.com/coderaiser/putout/tree/v20.0.0/packages);
106
+ - [remove-useless-return](https://github.com/coderaiser/putout/tree/master/remove-useless-return);
100
107
  - [remove-skip](https://github.com/coderaiser/putout/tree/v20.0.0/packages/remove-skip);
101
108
  - [remove-only](https://github.com/coderaiser/putout/tree/v20.0.0/packages/remove-only);
102
109
  - [remove-console](https://github.com/coderaiser/putout/tree/v20.0.0/packages/remove-console);
@@ -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',
@@ -89,6 +95,7 @@ const safe = {
89
95
  'remove-unused-variables': 'off',
90
96
  'remove-unused-expressions': 'off',
91
97
  'remove-unused-for-of-variables': 'off',
98
+ 'remove-useless-return': 'off',
92
99
  'tape/remove-skip': 'off',
93
100
  'tape/remove-only': 'off',
94
101
  'remove-console': 'off',
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-putout",
3
- "version": "11.1.0",
3
+ "version": "11.5.0",
4
4
  "description": "eslint plugin for putout",
5
5
  "release": false,
6
6
  "tag": false,