eslint-plugin-putout 14.9.1 → 14.12.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",
@@ -84,6 +85,8 @@ Then configure the rules you want to use under the rules section.
84
85
  ### ESM
85
86
 
86
87
  - ✅ [No unresolved](/packages/eslint-plugin-putout/lib/no-unresolved#readme)
88
+ - ✅ [Remove duplicate extension](/packages/eslint-plugin-putout/lib/remove-duplicate-extensions#readme)
89
+ - ✅ [Add newlines between specifiers](/packages/eslint-plugin-putout/lib/add-newlines-between-specifiers#readme)
87
90
 
88
91
  ### Formatting
89
92
 
@@ -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
+ const regExp = /, +?[A-z]/g;
4
+
5
+ module.exports.category = 'layout';
6
+ module.exports.report = () => 'Add newlines between specifiers';
7
+
8
+ module.exports.include = () => [
9
+ 'ExportNamedDeclaration',
10
+ ];
11
+
12
+ module.exports.fix = ({text}) => {
13
+ return text
14
+ .replace(/,\s+/g, ',\n ')
15
+ .replace(/{/g, '{\n')
16
+ .replace(/}/g, '\n}')
17
+ .replace(/{\n+/g, '{\n')
18
+ .replace(/\n+}/g, '\n}');
19
+ };
20
+
21
+ module.exports.filter = ({text, node}) => {
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'),
@@ -38,6 +39,7 @@ module.exports.rules = {
38
39
  ...getWrapRule('objects-braces-inside-array'),
39
40
  ...getWrapRule('object-init'),
40
41
  ...getWrapRule('no-unresolved'),
42
+ ...getWrapRule('remove-duplicate-extensions'),
41
43
  ...getWrapRule('evaluate'),
42
44
  ...getWrapRule('tape-add-newline-before-assertion'),
43
45
  ...getWrapRule('tape-add-newline-between-tests'),
@@ -68,6 +70,7 @@ const recommended = {
68
70
  'putout/newline-function-call-arguments': 'error',
69
71
  'putout/function-declaration-paren-newline': 'error',
70
72
  'putout/add-newlines-between-types-in-union': 'error',
73
+ 'putout/add-newlines-between-specifiers': 'error',
71
74
  'putout/add-newline-before-function-call': 'error',
72
75
  'putout/add-newline-after-function-call': 'error',
73
76
  'putout/remove-newline-after-default-import': 'error',
@@ -80,6 +83,7 @@ const recommended = {
80
83
  'putout/objects-braces-inside-array': 'error',
81
84
  'putout/object-init': 'error',
82
85
  'putout/no-unresolved': 'error',
86
+ 'putout/remove-duplicate-extensions': 'error',
83
87
  'putout/evaluate': 'error',
84
88
  'putout/tape-add-newline-before-assertion': 'error',
85
89
  'putout/tape-add-newline-between-tests': 'error',
@@ -0,0 +1,24 @@
1
+ # remove-duplicate-extension
2
+
3
+ Check if path has duplicate extension `.js.js` can be resolved and fix if cannot.
4
+ Duplicates can happen when **IDE** like **WebStorm** inserts filename and mistakenly adds duplicate.
5
+
6
+ Part of [`eslint-plugin-putout`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
7
+
8
+ ## ❌ Example of incorrect code
9
+
10
+ ```js
11
+ import x from './y.js.js';
12
+ export * from './y.js.js';
13
+ export * as dir from './dir.js.js';
14
+ export {m} from './y.js.js';
15
+ ```
16
+
17
+ ## ✅ Example of correct code
18
+
19
+ ```js
20
+ import x from './y.js';
21
+ export * from './y.js';
22
+ export * as dir from './dir.js';
23
+ export {m} from './y.js';
24
+ ```
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ const getValue = ({source}) => source?.value;
4
+
5
+ module.exports.category = 'errors';
6
+ module.exports.report = () => 'Avoid duplicate extensions in relative imports';
7
+ module.exports.include = () => [
8
+ 'ImportDeclaration',
9
+ 'ImportExpression',
10
+ 'ExportAllDeclaration',
11
+ 'ExportNamedDeclaration',
12
+ ];
13
+
14
+ module.exports.fix = ({text}) => {
15
+ return text.replace('.js.js', '.js');
16
+ };
17
+
18
+ module.exports.filter = ({node}) => {
19
+ const value = getValue(node);
20
+ return /\.js\.js/.test(value);
21
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-putout",
3
- "version": "14.9.1",
3
+ "version": "14.12.0",
4
4
  "type": "commonjs",
5
5
  "description": "eslint plugin for putout",
6
6
  "release": false,