eslint-plugin-putout 11.4.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,6 +48,7 @@ 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",
52
53
  "putout/remove-newline-from-empty-object": "error",
53
54
  "putout/remove-empty-newline-after-last-specifier": "error",
@@ -69,6 +70,7 @@ Then configure the rules you want to use under the rules section.
69
70
  - [Keyword spacing](/packages/eslint-plugin-putout/lib/keyword-spacing)
70
71
  - [Newline function call arguments](/packages/eslint-plugin-putout/lib/newline-function-call-arguments)
71
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)
72
74
  - [Remove newline after default import](/packages/eslint-plugin-putout/lib/remove-newline-after-default-import)
73
75
  - [Remove newline from empty object](/packages/eslint-plugin-putout/lib/remove-newline-from-empty-object)
74
76
  - [Remove empty newline after last specifier](/packages/eslint-plugin-putout/lib/remove-empty-newline-after-last-specifier)
@@ -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,6 +25,7 @@ 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'),
29
30
  ...getWrapRule('remove-newline-from-empty-object'),
30
31
  ...getWrapRule('remove-empty-newline-after-last-specifier'),
@@ -56,6 +57,7 @@ const recommended = {
56
57
  'putout/keyword-spacing': 'error',
57
58
  'putout/newline-function-call-arguments': 'error',
58
59
  'putout/function-declaration-paren-newline': 'error',
60
+ 'putout/add-newlines-between-types-in-union': 'error',
59
61
  'putout/remove-newline-after-default-import': 'error',
60
62
  'putout/remove-newline-from-empty-object': 'error',
61
63
  'putout/remove-empty-newline-after-last-specifier': 'error',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-putout",
3
- "version": "11.4.0",
3
+ "version": "11.5.0",
4
4
  "description": "eslint plugin for putout",
5
5
  "release": false,
6
6
  "tag": false,