eslint-plugin-putout 14.1.0 → 14.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
@@ -81,6 +81,10 @@ Then configure the rules you want to use under the rules section.
81
81
 
82
82
  - ✅ [Add newlines between types in union](/packages/eslint-plugin-putout/lib/add-newlines-between-types-in-union#readme)
83
83
 
84
+ ### ESM
85
+
86
+ - ✅ [No unresolved](/packages/eslint-plugin-putout/lib/no-unresolved#readme)
87
+
84
88
  ### Formatting
85
89
 
86
90
  - ✅ [Add newline before function call](/packages/eslint-plugin-putout/lib/add-newline-before-function-call#readme)
@@ -104,7 +108,7 @@ Then configure the rules you want to use under the rules section.
104
108
  - ✅ [Remove empty specifiers](/packages/eslint-plugin-putout/lib/remove-empty-specifiers#readme)
105
109
  - ✅ [Objects braces inside array](/packages/eslint-plugin-putout/lib/objects-braces-inside-array#readme)
106
110
  - ✅ [Object init](/packages/eslint-plugin-putout/lib/object-init#readme)
107
- - ✅ [No unresolved](/packages/eslint-plugin-putout/lib/no-unresolved#readme)
111
+ - ✅ [Nonblock statement body newline](/packages/eslint-plugin-putout/lib/non-block-statement-body-newline#readme)
108
112
 
109
113
  ### Safe mode
110
114
 
@@ -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}) => {
package/lib/index.js CHANGED
@@ -42,6 +42,7 @@ module.exports.rules = {
42
42
  ...getWrapRule('tape-add-newline-before-assertion'),
43
43
  ...getWrapRule('tape-add-newline-between-tests'),
44
44
  ...getWrapRule('tape-remove-newline-before-t-end'),
45
+ ...getWrapRule('nonblock-statement-body-newline'),
45
46
  ...getRule('putout'),
46
47
  ...getRule('remove-empty-newline-after-import'),
47
48
  };
@@ -83,6 +84,7 @@ const recommended = {
83
84
  'putout/tape-add-newline-before-assertion': 'error',
84
85
  'putout/tape-add-newline-between-tests': 'error',
85
86
  'putout/tape-remove-newline-before-t-end': 'error',
87
+ 'putout/nonblock-statement-body-newline': 'error',
86
88
  'putout/putout': 'error',
87
89
 
88
90
  'node/no-unsupported-features/es-syntax': 'off',
@@ -1,24 +1,22 @@
1
- # Use spaces around `catch` (`keyword-spacing`)
1
+ # keyword-spacing
2
2
 
3
- When `putout` removes unused variable in `catch` [eslint keyword spacing](https://eslint.org/docs/rules/keyword-spacing) can't handle [optional catch binding](https://github.com/tc39/proposal-optional-catch-binding) correctly.
3
+ When 🐊[**Putout**](https://github.com/coderaiser/putout) removes unused variable in `catch` [eslint keyword spacing](https://eslint.org/docs/rules/keyword-spacing) can't handle [optional catch binding](https://github.com/tc39/proposal-optional-catch-binding) correctly. This rule adds spaces around `catch`.
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
- This rule aims to add spaces around `catch`
8
-
9
- Examples of **incorrect** code for this rule:
7
+ ## Example of incorrect code
10
8
 
11
9
  ```js
12
- try {
13
- } catch {
10
+ try{
11
+ } catch{
14
12
  }
15
13
 
16
14
  try {
17
- } catch {
15
+ }catch{
18
16
  }
19
17
 
20
18
  try {
21
- } catch(error) {
19
+ }catch(error) {
22
20
  }
23
21
 
24
22
  if(a) {
@@ -33,7 +31,7 @@ async () => {
33
31
  };
34
32
  ```
35
33
 
36
- Examples of **correct** code for this rule:
34
+ ## ✅ Example of correct code
37
35
 
38
36
  ```js
39
37
  try {
@@ -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';
@@ -0,0 +1,39 @@
1
+ # nonblock-statement-body-newline
2
+
3
+ Remove newline inside statement body. Part of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
4
+
5
+ ## ❌ Example of incorrect code
6
+
7
+ ```js
8
+ if (a)
9
+
10
+ b();
11
+
12
+ for (a of b)
13
+
14
+ a();
15
+
16
+ while (a)
17
+
18
+ b();
19
+
20
+ for (;;)
21
+
22
+ a();
23
+ ```
24
+
25
+ ## ✅ Example of correct code
26
+
27
+ ```js
28
+ if (a)
29
+ b();
30
+
31
+ for (a of b)
32
+ a();
33
+
34
+ while (a)
35
+ b();
36
+
37
+ for (;;)
38
+ a();
39
+ ```
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+
3
+ const {types} = require('putout');
4
+ const {
5
+ isBlockStatement,
6
+ isIfStatement,
7
+ isExpressionStatement,
8
+ } = types;
9
+
10
+ const reg = /\)\n(\s+)?\n/;
11
+
12
+ module.exports.report = () => `Remove useless newline`;
13
+
14
+ module.exports.fix = ({text}) => {
15
+ const result = text.replace(reg, ')\n');
16
+ return result;
17
+ };
18
+
19
+ module.exports.include = () => [
20
+ 'IfStatement',
21
+ 'ForOfStatement',
22
+ 'ForStatement',
23
+ 'WhileStatement',
24
+ ];
25
+
26
+ module.exports.filter = ({text, node}) => {
27
+ if (isIf(text, node))
28
+ return true;
29
+
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))
43
+ return false;
44
+
45
+ return reg.test(text);
46
+ }
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
+ }
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',
@@ -68,6 +69,7 @@ const ts = {
68
69
  files: '*.ts',
69
70
  parser: '@typescript-eslint/parser',
70
71
  parserOptions: {
72
+ warnOnUnsupportedTypeScriptVersion,
71
73
  ecmaFeatures: {
72
74
  jsx: false,
73
75
  },
@@ -94,6 +96,7 @@ module.exports = [
94
96
  ...ts,
95
97
  files: '*.tsx',
96
98
  parserOptions: {
99
+ warnOnUnsupportedTypeScriptVersion,
97
100
  ecmaFeatures: {
98
101
  jsx: true,
99
102
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-putout",
3
- "version": "14.1.0",
3
+ "version": "14.4.0",
4
4
  "type": "commonjs",
5
5
  "description": "eslint plugin for putout",
6
6
  "release": false,