eslint-plugin-putout 14.10.0 → 15.0.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
@@ -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-init": "error",
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
+
@@ -12,6 +12,9 @@ module.exports.report = () => 'Add newlines between array elements';
12
12
  const regexp = /['\da-zA-Z]+, ['\da-zA-Z]/;
13
13
 
14
14
  const isSupportedNode = (a) => {
15
+ if (!a)
16
+ return false;
17
+
15
18
  if (a.type === 'Literal')
16
19
  return true;
17
20
 
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-init'),
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-init': 'error',
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,23 @@
1
- # object-init
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
- ```js
9
+ ```ts
10
10
  const user = {name};
11
11
 
12
12
  module.exports = {lint: 'putout lint'};
13
+
14
+ type User = {name: string};
15
+ interface Place {message: string}
13
16
  ```
14
17
 
15
18
  ## ✅ Example of correct code
16
19
 
17
- ```js
20
+ ```ts
18
21
  const user = {
19
22
  name,
20
23
  };
@@ -22,4 +25,12 @@ const user = {
22
25
  module.exports = {
23
26
  lint: 'putout lint',
24
27
  };
28
+
29
+ type User = {
30
+ name: string,
31
+ };
32
+
33
+ interface Place {
34
+ message: string;
35
+ }
25
36
  ```
@@ -3,7 +3,11 @@
3
3
  const {types} = require('putout');
4
4
  const {isCorrectLoc} = require('../common');
5
5
 
6
- const {isVariableDeclarator} = types;
6
+ const {
7
+ isVariableDeclarator,
8
+ isAssignmentExpression,
9
+ isTSTypeAliasDeclaration,
10
+ } = types;
7
11
 
8
12
  module.exports.category = 'destructuring';
9
13
  module.exports.report = () => 'Keep each property on separate line';
@@ -11,6 +15,8 @@ module.exports.report = () => 'Keep each property on separate line';
11
15
  module.exports.include = () => [
12
16
  `VariableDeclarator[init.type="ObjectExpression"]`,
13
17
  `AssignmentExpression[right.type="ObjectExpression"]`,
18
+ `TSTypeAliasDeclaration[typeAnnotation.type="TSTypeLiteral"]`,
19
+ `TSInterfaceDeclaration`,
14
20
  ];
15
21
 
16
22
  module.exports.filter = ({node}) => {
@@ -27,16 +33,30 @@ module.exports.filter = ({node}) => {
27
33
  return !isCorrectLoc(line, properties);
28
34
  }
29
35
 
30
- const {properties} = right;
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;
31
51
  const {line} = loc.start;
32
52
 
33
- return !isCorrectLoc(line, properties);
53
+ return !isCorrectLoc(line, body);
34
54
  };
35
55
 
36
56
  module.exports.fix = ({text}) => {
37
57
  return text
38
- .replace(/,/g, ',\n')
39
- .replace(/{/g, '{\n')
58
+ .replace(/,/g, ',\n ')
59
+ .replace(/{/g, '{\n ')
40
60
  .replace(/}/g, '\n}');
41
61
  };
42
62
 
package/lib/ts.js CHANGED
@@ -7,8 +7,8 @@ const extensionRules = {
7
7
  'no-undef': 'off',
8
8
  'no-var': 'off',
9
9
 
10
- 'brace-style': 'off',
11
- '@typescript-eslint/brace-style': ['error'],
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": "14.10.0",
3
+ "version": "15.0.0",
4
4
  "type": "commonjs",
5
- "description": "eslint plugin for putout",
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",