eslint-plugin-putout 13.0.1 → 13.4.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
@@ -52,6 +52,7 @@ Then configure the rules you want to use under the rules section.
52
52
  "putout/remove-newline-from-empty-object": "error",
53
53
  "putout/remove-empty-newline-before-first-specifier": "error",
54
54
  "putout/remove-empty-newline-after-last-specifier": "error",
55
+ "putout/remove-empty-specifiers": "error",
55
56
  "putout/objects-braces-inside-array": "error",
56
57
  "putout/object-init": "error"
57
58
  }
@@ -79,6 +80,7 @@ Then configure the rules you want to use under the rules section.
79
80
  - [Remove newline from empty object](/packages/eslint-plugin-putout/lib/remove-newline-from-empty-object)
80
81
  - [Remove empty newline before first specifier](/packages/eslint-plugin-putout/lib/remove-empty-newline-before-first-specifier)
81
82
  - [Remove empty newline after last specifier](/packages/eslint-plugin-putout/lib/remove-empty-newline-after-last-specifier)
83
+ - [Remove empty specifiers](/packages/eslint-plugin-putout/lib/remove-empty-specifiers)
82
84
  - [Objects braces inside array](/packages/eslint-plugin-putout/lib/objects-braces-inside-array)
83
85
  - [Object init](/packages/eslint-plugin-putout/lib/object-init)
84
86
  - [No unresolved](/packages/eslint-plugin-putout/lib/no-unresolved)
@@ -101,10 +103,6 @@ When using 🐊`Putout` in IDE with `--fix` on save, or when you want to disable
101
103
  }
102
104
  ```
103
105
 
104
- ### safe+align
105
-
106
- When you want to enable ability to align spaces on empty lines, use `safe+align`.
107
-
108
106
  Disabled `ESLint` rules:
109
107
 
110
108
  - [`no-useless-return`](https://eslint.org/docs/rules/no-useless-return)
@@ -120,9 +118,15 @@ Disabled 🐊`Putout` rules:
120
118
  - [`remove-unused-expressions`](https://github.com/coderaiser/putout/tree/v24.0.0/packages);
121
119
  - [`remove-useless-return`](https://github.com/coderaiser/putout/tree/master/remove-useless-return);
122
120
  - [`remove-useless-arguments`](https://github.com/coderaiser/putout/tree/master/remove-useless-arguments);
121
+ - [`remove-useless-variables/rename`](https://github.com/coderaiser/putout/tree/master/remove-useless-arguments#rename);
123
122
  - [`remove-skip`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-skip);
124
123
  - [`remove-only`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-only);
125
124
  - [`remove-console`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-console);
126
125
  - [`remove-debugger`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-debugger);
127
126
  - [`remove-unreachable-code`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-unreachable-code);
128
127
  - [`convert-for-to-for-of`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/convert-for-to-for-of);
128
+
129
+ ### safe+align
130
+
131
+ When you want to enable ability to align spaces on empty lines, while have all benefits of `safe` preset: use `safe+align`.
132
+
@@ -33,6 +33,9 @@ module.exports.filter = ({text, node, getCommentsBefore, getSpacesBeforeNode}) =
33
33
 
34
34
  const spaces = getSpacesBeforeNode(node, text);
35
35
 
36
+ if (!spaces)
37
+ return false;
38
+
36
39
  if (regExp.test(spaces))
37
40
  return false;
38
41
 
@@ -43,7 +46,6 @@ module.exports.filter = ({text, node, getCommentsBefore, getSpacesBeforeNode}) =
43
46
  continue;
44
47
 
45
48
  const prevA = body[i - 1];
46
- const nextA = body[i + 1];
47
49
 
48
50
  if (!isVariableDeclaration(prevA))
49
51
  return false;
@@ -53,11 +55,7 @@ module.exports.filter = ({text, node, getCommentsBefore, getSpacesBeforeNode}) =
53
55
  if (regExp.test(spaces))
54
56
  return false;
55
57
 
56
- if (!nextA)
57
- return true;
58
-
59
- const nextSpaces = getSpacesBeforeNode(nextA);
60
- return !regExp.test(nextSpaces);
58
+ return true;
61
59
  }
62
60
 
63
61
  return false;
package/lib/index.js CHANGED
@@ -33,6 +33,7 @@ module.exports.rules = {
33
33
  ...getWrapRule('remove-newline-from-empty-object'),
34
34
  ...getWrapRule('remove-empty-newline-before-first-specifier'),
35
35
  ...getWrapRule('remove-empty-newline-after-last-specifier'),
36
+ ...getWrapRule('remove-empty-specifiers'),
36
37
  ...getWrapRule('objects-braces-inside-array'),
37
38
  ...getWrapRule('object-init'),
38
39
  ...getWrapRule('no-unresolved'),
@@ -70,6 +71,7 @@ const recommended = {
70
71
  'putout/remove-newline-from-empty-object': 'error',
71
72
  'putout/remove-empty-newline-before-first-specifier': 'error',
72
73
  'putout/remove-empty-newline-after-last-specifier': 'error',
74
+ 'putout/remove-empty-specifiers': 'error',
73
75
  'putout/objects-braces-inside-array': 'error',
74
76
  'putout/object-init': 'error',
75
77
  'putout/no-unresolved': 'error',
@@ -111,6 +113,7 @@ const safe = {
111
113
  'remove-unreachable-code': 'off',
112
114
  'remove-useless-return': 'off',
113
115
  'remove-useless-arguments': 'off',
116
+ 'remove-useless-variables/rename': 'off',
114
117
  'tape/remove-skip': 'off',
115
118
  'tape/remove-only': 'off',
116
119
  'remove-console': 'off',
@@ -0,0 +1,17 @@
1
+ # Remove empty specifiers(`remove-empty-specifiers`)
2
+
3
+ ## Rule Details
4
+
5
+ This rule aims to remove empty specifiers.
6
+
7
+ Examples of **incorrect** code for this rule:
8
+
9
+ ```js
10
+ import putout, {} from 'putout';
11
+ ```
12
+
13
+ Examples of **correct** code for this rule:
14
+
15
+ ```js
16
+ import putout from 'putout';
17
+ ```
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ module.exports.category = 'object';
4
+ module.exports.report = () => 'Remove empty import specifiers';
5
+
6
+ module.exports.filter = ({text, node, getCommentsInside}) => {
7
+ const comments = getCommentsInside(node);
8
+
9
+ if (comments.length)
10
+ return false;
11
+
12
+ return text.includes('{}');
13
+ };
14
+
15
+ module.exports.fix = ({text}) => {
16
+ return text
17
+ .replace('import {} from', 'import')
18
+ .replace(/,? {}/, '');
19
+ };
20
+
21
+ module.exports.include = () => [
22
+ 'ImportDeclaration',
23
+ ];
24
+
@@ -26,7 +26,10 @@ module.exports.include = () => [
26
26
  'ImportDeclaration[specifiers.length=1]',
27
27
  ];
28
28
 
29
- module.exports.filter = ({node, text, getText}) => {
29
+ module.exports.filter = ({node, text, getText, getCommentsInside}) => {
30
+ if (getCommentsInside(node).length)
31
+ return false;
32
+
30
33
  const parentText = getText(node.parent);
31
34
 
32
35
  if (isImportDeclaration(node) && !compare(node.specifiers[0].local, node.specifiers[0].imported))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-putout",
3
- "version": "13.0.1",
3
+ "version": "13.4.0",
4
4
  "type": "commonjs",
5
5
  "description": "eslint plugin for putout",
6
6
  "release": false,