eslint-plugin-putout 14.2.0 → 14.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.
@@ -1,12 +1,11 @@
1
- # Keep curly braces in one line when you use destructuring as function argument (`destructuring-as-function-argument`)
1
+ # destructuring-as-function-argument
2
2
 
3
- When `putout` removes unused variable located in function argument object pattern, it formats in in a multiple lines.
3
+ When 🐊[**Putout**](https://github.com/coderaiser/putout) [removes unused variables](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-unused-variables#readme) located in function argument object pattern, it formats it in a multiple lines.
4
+ This rule aims keep curly braces in one line when you use destructuring as function argument.
4
5
 
5
- ## Rule Details
6
+ Part of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
6
7
 
7
- This rule aims to shorten destructuring of properties.
8
-
9
- Examples of **incorrect** code for this rule:
8
+ ## Example of incorrect code
10
9
 
11
10
  ```js
12
11
  const login = ({
@@ -16,7 +15,7 @@ const login = ({
16
15
  };
17
16
  ```
18
17
 
19
- Examples of **correct** code for this rule:
18
+ ## ✅ Example of correct code
20
19
 
21
20
  ```js
22
21
  const login = ({username, password}) => {
@@ -87,13 +87,13 @@ function checkSwitch(text) {
87
87
 
88
88
  function fixCatch(text) {
89
89
  return text
90
- .replace(/catch{/g, 'catch {')
91
- .replace(/}catch/g, '} catch')
92
- .replace(/catch \(/g, 'catch(');
90
+ .replaceAll('catch{', 'catch {')
91
+ .replaceAll('}catch', '} catch')
92
+ .replaceAll('catch (', 'catch(');
93
93
  }
94
94
 
95
95
  function fixSwitch(text) {
96
96
  return text
97
- .replace(/switch \(/g, 'switch(');
97
+ .replaceAll('switch (', 'switch(');
98
98
  }
99
99
 
@@ -1,12 +1,11 @@
1
- # Keep curly braces in one line when property is single (`newline-function-call-arguments`)
1
+ # newline-function-call-arguments
2
2
 
3
3
  Addition to eslint's [function-paren-newline](https://eslint.org/docs/rules/function-paren-newline)
4
+ This rule aims to fix eslint transform adding new line after opening brace.
4
5
 
5
- ## Rule Details
6
+ Part of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
6
7
 
7
- This rule aims to fix eslint transform.
8
-
9
- Examples of **incorrect** code for this rule:
8
+ ## Example of incorrect code
10
9
 
11
10
  ```js
12
11
  const onConnectError = squad(superFn(connect_error),
@@ -15,7 +14,7 @@ const onConnectError = squad(superFn(connect_error),
15
14
  getDescription);
16
15
  ```
17
16
 
18
- Examples of **correct** code for this rule:
17
+ ## ✅ Example of correct code
19
18
 
20
19
  ```js
21
20
  const onConnectError = squad(
@@ -1,13 +1,19 @@
1
- # Check if path can be resolved and fix if cannot (`no-unresolved`)
1
+ # no-unresolved
2
2
 
3
+ Check if path can be resolved and fix if cannot.
3
4
  Similar to [`no-unresolved`](https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-unresolved.md) from
4
- [`eslint-plugin-putout`](https://github.com/import-js/eslint-plugin-import). But supports only `ESM` and have `autofix`.
5
+ [`eslint-plugin-import`](https://github.com/import-js/eslint-plugin-import). But supports only `ESM` and have `autofix`.
5
6
 
6
- ## Rule Details
7
+ Part of [`eslint-plugin-putout`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
7
8
 
8
- This rule aims to fix `unresolved import`:
9
+ [File extension is mandatory](https://nodejs.org/api/esm.html#esm_mandatory_file_extensions) and will produce an error from `node.js`:
9
10
 
10
- Examples of **incorrect** code for this rule:
11
+ ```
12
+ Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/coderaiser/putout/y' imported from /Users/coderaiser/putout/x.mjs
13
+ Did you mean to import ../y.js?
14
+ ```
15
+
16
+ ## ❌ Example of incorrect code
11
17
 
12
18
  ```js
13
19
  import x from './y';
@@ -18,14 +24,7 @@ export * as dir from './dir';
18
24
  export {m} from './y';
19
25
  ```
20
26
 
21
- [File extension is mandatory](https://nodejs.org/api/esm.html#esm_mandatory_file_extensions) and will produce an error from `node.js`:
22
-
23
- ```
24
- Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/coderaiser/putout/y' imported from /Users/coderaiser/putout/x.mjs
25
- Did you mean to import ../y.js?
26
- ```
27
-
28
- Examples of **correct** code for this rule:
27
+ ## Example of correct code
29
28
 
30
29
  ```js
31
30
  import x from './y.js';
@@ -8,6 +8,18 @@ Remove newline inside statement body. Part of [**eslint-plugin-putout**](https:/
8
8
  if (a)
9
9
 
10
10
  b();
11
+
12
+ for (a of b)
13
+
14
+ a();
15
+
16
+ while (a)
17
+
18
+ b();
19
+
20
+ for (;;)
21
+
22
+ a();
11
23
  ```
12
24
 
13
25
  ## ✅ Example of correct code
@@ -15,4 +27,13 @@ if (a)
15
27
  ```js
16
28
  if (a)
17
29
  b();
30
+
31
+ for (a of b)
32
+ a();
33
+
34
+ while (a)
35
+ b();
36
+
37
+ for (;;)
38
+ a();
18
39
  ```
@@ -1,26 +1,55 @@
1
1
  'use strict';
2
2
 
3
3
  const {types} = require('putout');
4
- const {isExpressionStatement} = types;
4
+ const {
5
+ isBlockStatement,
6
+ isIfStatement,
7
+ isExpressionStatement,
8
+ } = types;
5
9
 
6
10
  const reg = /\)\n(\s+)?\n/;
7
11
 
8
- module.exports.report = () => `Remove newline`;
12
+ module.exports.report = () => `Remove useless newline`;
9
13
 
10
14
  module.exports.fix = ({text}) => {
11
- return text.replace(reg, ')\n');
15
+ const result = text.replace(reg, ')\n');
16
+ return result;
12
17
  };
13
18
 
14
19
  module.exports.include = () => [
15
20
  'IfStatement',
21
+ 'ForOfStatement',
22
+ 'ForStatement',
23
+ 'WhileStatement',
16
24
  ];
17
25
 
18
- module.exports.filter = ({node, text}) => {
19
- const {consequent} = node;
26
+ module.exports.filter = ({text, node}) => {
27
+ if (isIf(text, node))
28
+ return true;
20
29
 
21
- if (!isExpressionStatement(consequent))
30
+ if (isBody(text, node))
31
+ return true;
32
+
33
+ return false;
34
+ };
35
+
36
+ function isIf(text, node) {
37
+ if (!isIfStatement(node))
38
+ return false;
39
+
40
+ const {consequent, alternate} = node;
41
+
42
+ if (!isExpressionStatement(alternate) && !isExpressionStatement(consequent))
22
43
  return false;
23
44
 
24
45
  return reg.test(text);
25
- };
46
+ }
26
47
 
48
+ function isBody(text, node) {
49
+ const {body} = node;
50
+
51
+ if (isBlockStatement(body))
52
+ return false;
53
+
54
+ return reg.test(text);
55
+ }
@@ -1,10 +1,10 @@
1
- # Keep each property on separate line when initializing an object(`object-init`)
1
+ # object-init
2
2
 
3
- In the same way as eslint [object-property-newline](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout/lib/multiple-properties-destructuring) but for initializing variables with `object expression`.
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).
4
4
 
5
- ## Rule Details
5
+ Part of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
6
6
 
7
- Examples of **incorrect** code for this rule:
7
+ ## ❌ Example of incorrect code
8
8
 
9
9
  ```js
10
10
  const user = {name};
@@ -12,7 +12,7 @@ const user = {name};
12
12
  module.exports = {lint: 'putout lint'};
13
13
  ```
14
14
 
15
- Examples of **correct** code for this rule:
15
+ ## ✅ Example of correct code
16
16
 
17
17
  ```js
18
18
  const user = {
@@ -1,8 +1,9 @@
1
- # Keep braces on the same line as brackets (`object-braces-inside-array`)
1
+ # object-braces-inside-array
2
2
 
3
- ## Rule Details
3
+ Keep braces on the same line as brackets.
4
+ Part of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
4
5
 
5
- Examples of **incorrect** code for this rule:
6
+ ## ❌ Example of incorrect code
6
7
 
7
8
  ```js
8
9
  const expected = [
@@ -15,7 +16,7 @@ const expected = [
15
16
  ];
16
17
  ```
17
18
 
18
- Examples of **correct** code for this rule:
19
+ ## ✅ Example of correct code
19
20
 
20
21
  ```js
21
22
  const expected = [{
@@ -1,10 +1,8 @@
1
- # Remove empty newline after import (`remove-empty-newline-after-import`)
1
+ # remove-empty-newline-after-import
2
2
 
3
- ## Rule Details
3
+ This rule aims to remove empty newline after [`import` statement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import). Part of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
4
4
 
5
- This rule aims to remove empty newline after `import`.
6
-
7
- Examples of **incorrect** code for this rule:
5
+ ## Example of incorrect code
8
6
 
9
7
  ```js
10
8
  import {readFile} from 'fs';
@@ -14,7 +12,7 @@ import {promisify} from 'util';
14
12
  import index from './index.js';
15
13
  ```
16
14
 
17
- Examples of **correct** code for this rule:
15
+ ## ✅ Example of correct code
18
16
 
19
17
  ```js
20
18
  import {readFile} from 'fs';
@@ -1,7 +1,7 @@
1
1
  # remove-empty-newline-after-last-element
2
2
 
3
3
  Remove empty newline after last element.
4
- Part of [`eslint-plugin-putout`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
4
+ Part of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
5
5
 
6
6
  ## ❌ Example of incorrect code
7
7
 
@@ -1,10 +1,9 @@
1
- # Remove empty new line before first specifier (`remove-empty-newline-before-first-specifier`)
2
-
3
- ## Rule Details
1
+ # remove-empty-newline-before-first-specifier
4
2
 
5
3
  This rule aims to remove empty newline before first specifier.
4
+ Part of [`eslint-plugin-putout`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
6
5
 
7
- Examples of **incorrect** code for this rule:
6
+ ## ❌ Example of incorrect code
8
7
 
9
8
  ```js
10
9
  import {
@@ -20,7 +19,7 @@ push({
20
19
  });
21
20
  ```
22
21
 
23
- Examples of **correct** code for this rule:
22
+ ## ✅ Example of correct code
24
23
 
25
24
  ```js
26
25
  import {
@@ -1,16 +1,15 @@
1
- # Remove empty specifiers(`remove-empty-specifiers`)
2
-
3
- ## Rule Details
1
+ # remove-empty-specifiers
4
2
 
5
3
  This rule aims to remove empty specifiers.
4
+ Part of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
6
5
 
7
- Examples of **incorrect** code for this rule:
6
+ ## ❌ Example of incorrect code
8
7
 
9
8
  ```js
10
9
  import putout, {} from 'putout';
11
10
  ```
12
11
 
13
- Examples of **correct** code for this rule:
12
+ ## ✅ Example of correct code
14
13
 
15
14
  ```js
16
15
  import putout from 'putout';
@@ -1,17 +1,16 @@
1
- # Remove new line in empty object (`remove-newline-from-empty-object`)
2
-
3
- ## Rule Details
1
+ # remove-newline-from-empty-object
4
2
 
5
3
  This rule aims to remove newline from empty object.
4
+ Part of [`eslint-plugin-putout`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
6
5
 
7
- Examples of **incorrect** code for this rule:
6
+ ## ❌ Example of incorrect code
8
7
 
9
8
  ```js
10
9
  const a = {
11
10
  };
12
11
  ```
13
12
 
14
- Examples of **correct** code for this rule:
13
+ ## ✅ Example of correct code
15
14
 
16
15
  ```js
17
16
  const a = {};
package/lib/ts.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {rules} = require('@putout/eslint-config');
4
+ const warnOnUnsupportedTypeScriptVersion = false;
4
5
 
5
6
  const extensionRules = {
6
7
  'no-undef': 'off',
@@ -24,9 +25,7 @@ const extensionRules = {
24
25
  // broken
25
26
  '@typescript-eslint/indent': 'off',
26
27
 
27
- 'lines-between-class-members': 'off',
28
- '@typescript-eslint/lines-between-class-members': 'error',
29
-
28
+ '@typescript-eslint/lines-between-class-members': 'off',
30
29
  '@typescript-eslint/no-array-constructor': 'off',
31
30
 
32
31
  'no-extra-parens': 'off',
@@ -68,6 +67,7 @@ const ts = {
68
67
  files: '*.ts',
69
68
  parser: '@typescript-eslint/parser',
70
69
  parserOptions: {
70
+ warnOnUnsupportedTypeScriptVersion,
71
71
  ecmaFeatures: {
72
72
  jsx: false,
73
73
  },
@@ -94,6 +94,7 @@ module.exports = [
94
94
  ...ts,
95
95
  files: '*.tsx',
96
96
  parserOptions: {
97
+ warnOnUnsupportedTypeScriptVersion,
97
98
  ecmaFeatures: {
98
99
  jsx: true,
99
100
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-putout",
3
- "version": "14.2.0",
3
+ "version": "14.5.0",
4
4
  "type": "commonjs",
5
5
  "description": "eslint plugin for putout",
6
6
  "release": false,