eslint-plugin-putout 13.0.0 → 13.3.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)
@@ -115,7 +117,7 @@ Disabled 🐊`Putout` rules:
115
117
  - [`remove-empty`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-remove-empty);
116
118
  - [`nodejs/remove-process-exit`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-nodejs#remove-process-exit);
117
119
  - [`remove-unused-variables`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-unused-variables);
118
- - [`remove-unused-types`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-unused-types);
120
+ - [`typescript/remove-unused-types`](https://github.com/coderaiser/putout/tree/v24.0.2/packages/plugin-typescript#remove-unused-types);
119
121
  - [`remove-unused-for-of-variables`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/remove-unused-for-of-variables);
120
122
  - [`remove-unused-expressions`](https://github.com/coderaiser/putout/tree/v24.0.0/packages);
121
123
  - [`remove-useless-return`](https://github.com/coderaiser/putout/tree/master/remove-useless-return);
@@ -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',
@@ -104,7 +106,7 @@ const safe = {
104
106
  rules: {
105
107
  'remove-empty': 'off',
106
108
  'nodejs/remove-process-exit': 'off',
107
- 'remove-unused-types': 'off',
109
+ 'typescript/remove-unused-types': 'off',
108
110
  'remove-unused-variables': 'off',
109
111
  'remove-unused-expressions': 'off',
110
112
  'remove-unused-for-of-variables': '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.0",
3
+ "version": "13.3.0",
4
4
  "type": "commonjs",
5
5
  "description": "eslint plugin for putout",
6
6
  "release": false,