eslint-plugin-putout 14.0.0 → 14.2.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
@@ -5,7 +5,7 @@
5
5
  [CoverageURL]: https://coveralls.io/github/coderaiser/putout?branch=master
6
6
  [CoverageIMGURL]: https://coveralls.io/repos/coderaiser/putout/badge.svg?branch=master&service=github
7
7
 
8
- [`ESLint`](https://eslint.org) plugin for 🐊[`Putout`](https://github.com/coderaiser/putout) with built-in rules from [`@putout/eslint-config`](https://github.com/coderaiser/putout/tree/master/packages/eslint-config).
8
+ [**ESLint**](https://eslint.org) plugin for 🐊[**Putout**](https://github.com/coderaiser/putout) with built-in rules from [**@putout/eslint-config**](https://github.com/coderaiser/putout/tree/master/packages/eslint-config#readme).
9
9
 
10
10
  ## Installation
11
11
 
@@ -13,7 +13,7 @@
13
13
  npm i putout eslint eslint-plugin-putout -D
14
14
  ```
15
15
 
16
- **Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `putout` and `eslint-plugin-putout` globally.
16
+ ☝️*If you installed `eslint` globally (using the `-g` flag) then you must also install `putout` and `eslint-plugin-putout` globally.*
17
17
 
18
18
  ## Usage
19
19
 
@@ -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,11 +108,11 @@ 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
 
111
- When using 🐊`Putout` in IDE with `--fix` on save, or when you want to disable the most dangerous rules, use:
115
+ When using 🐊**Putout** in IDE with `--fix` on save, or when you want to disable the most dangerous rules, use:
112
116
 
113
117
  ```json
114
118
  {
@@ -121,12 +125,12 @@ When using 🐊`Putout` in IDE with `--fix` on save, or when you want to disable
121
125
  }
122
126
  ```
123
127
 
124
- Disabled `ESLint` rules:
128
+ Disabled **ESLint** rules:
125
129
 
126
130
  - [`no-useless-return`](https://eslint.org/docs/rules/no-useless-return#readme)
127
131
  - [`putout/remove-newline-from-empty-object`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout/lib/remove-newline-from-empty-object#readme)
128
132
 
129
- Disabled 🐊`Putout` rules:
133
+ Disabled 🐊**Putout** rules:
130
134
 
131
135
  - 🐲[`remove-empty`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-remove-empty#readme);
132
136
  - 🐲[`nodejs/remove-process-exit`](https://github.com/coderaiser/putout/tree/v24.0.0/packages/plugin-nodejs#remove-process-exit#readme);
@@ -1,10 +1,8 @@
1
- # Add new line after function call (`add-newline-after-function-call`)
2
-
3
- ## Rule Details
1
+ # add-newline-after-function-call
4
2
 
5
3
  This rule aims to add newline after function call.
6
4
 
7
- Examples of **incorrect** code for this rule:
5
+ ## ❌ Example of incorrect code
8
6
 
9
7
  ```js
10
8
  export function parse() {
@@ -15,7 +13,7 @@ export function parse() {
15
13
  }
16
14
  ```
17
15
 
18
- Examples of **correct** code for this rule:
16
+ ## ✅ Example of correct code
19
17
 
20
18
  ```js
21
19
  export function parse() {
@@ -1,10 +1,8 @@
1
- # Add new line before function call (`add-newline-before-function-call`)
1
+ # add-newline-before-function-call
2
2
 
3
- ## Rule Details
3
+ This rule aims to add newline before `function call` and `assignment`. Part of [`eslint-plugin-putout`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
4
4
 
5
- This rule aims to add newline before `function call` and `assignment`.
6
-
7
- Examples of **incorrect** code for this rule:
5
+ ## Example of incorrect code
8
6
 
9
7
  ```js
10
8
  export function parse() {
@@ -18,7 +16,7 @@ export function calc() {
18
16
  }
19
17
  ```
20
18
 
21
- Examples of **correct** code for this rule:
19
+ ## ✅ Example of correct code
22
20
 
23
21
  ```js
24
22
  export function parse() {
@@ -1,16 +1,14 @@
1
- # Add new lines between types in union (`add-newlines-between-types-in-union`)
1
+ # add-newlines-between-types-in-union
2
2
 
3
- ## Rule Details
3
+ This rule aims to add newlines between types in union. Part of [`eslint-plugin-putout`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
4
4
 
5
- This rule aims to add newlines between types in union.
6
-
7
- Examples of **incorrect** code for this rule:
5
+ ## Example of incorrect code
8
6
 
9
7
  ```js
10
8
  const a = string | number | object | boolean;
11
9
  ```
12
10
 
13
- Examples of **correct** code for this rule:
11
+ ## ✅ Example of correct code
14
12
 
15
13
  ```js
16
14
  const a = string
@@ -1,12 +1,8 @@
1
- # Spaces should be aligned (`aling-spaces`)
1
+ # aling-spaces
2
2
 
3
- After `putout` process files it can remove spaces from empty line, this `rule` fixes it.
3
+ When 🐊**Putout** processes files it can remove spaces from empty line, this `rule` fixes it.
4
4
 
5
- ## Rule Details
6
-
7
- This rule aims to shorten destricturing of one property.
8
-
9
- Examples of **incorrect** code for this rule:
5
+ ## Example of incorrect code
10
6
 
11
7
  ```js
12
8
  function hello() {
@@ -18,7 +14,7 @@ function hello() {
18
14
  }
19
15
  ```
20
16
 
21
- Examples of **correct** code for this rule:
17
+ ## ✅ Example of correct code
22
18
 
23
19
  ```js
24
20
  function hello() {
@@ -1,19 +1,17 @@
1
- # Add new lines between types in union (`add-newlines-between-types-in-union`)
2
-
3
- Because [`array-element-newline`](https://eslint.org/docs/rules/array-element-newline) requires [`array-bracket-newline`](https://eslint.org/docs/rules/array-bracket-newline).
4
- And `array-bracket-newline` and conflicts with [`object-braces-inside-array`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout/lib/objects-braces-inside-array).
5
-
6
- ## Rule Details
1
+ # array-elements-newline
7
2
 
8
3
  This rule aims to add newlines between array elements.
4
+ It exists because [`array-element-newline`](https://eslint.org/docs/rules/array-element-newline) requires [`array-bracket-newline`](https://eslint.org/docs/rules/array-bracket-newline) which conflicts with [`object-braces-inside-array`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout/lib/objects-braces-inside-array#readme).
5
+
6
+ Part of [`eslint-plugin-putout`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
9
7
 
10
- Examples of **incorrect** code for this rule:
8
+ ## ❌ Example of incorrect code
11
9
 
12
10
  ```js
13
11
  const a = [1, 2, 3, 4, 5, 6, 7];
14
12
  ```
15
13
 
16
- Examples of **correct** code for this rule:
14
+ ## ✅ Example of correct code
17
15
 
18
16
  ```js
19
17
  const a = [
@@ -1,11 +1,10 @@
1
1
  # Evaluate
2
2
 
3
- Evaluate expression started with `__putout_evaluate: `. Part of [`eslint-plugin-putout`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules)
4
-
3
+ Evaluate expression started with `__putout_evaluate: `. Part of [`eslint-plugin-putout`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
5
4
  Provided code is processed with [`@putout/plugin-declare-undefined-variables`](https://github.com/coderaiser/putout/tree/master/packages/plugin-declare-undefined-variables):
6
5
 
7
6
  ```js
8
- __putout_evaluate: join("hello", " ", "world");
7
+ __putout_evaluate: join('hello', ' ', 'world');
9
8
  ```
10
9
 
11
10
  and converted to:
@@ -13,7 +12,7 @@ and converted to:
13
12
  ```js
14
13
  const fn = (__filename, __dirname, require) => {
15
14
  const {join} = require('path');
16
- return join("hello", " ", "world");
15
+ return join('hello', ' ', 'world');
17
16
  };
18
17
  ```
19
18
 
@@ -1,10 +1,9 @@
1
- # Keep all properties in one line when using destructuring in `for-of` (`for-of-multiple-properties-destructuring`)
1
+ # for-of-multiple-properties-destructuring
2
2
 
3
- ## Rule Details
3
+ This rule aims to shorten destructuring in `for-of` statements, keeping all properties in one line.
4
+ Part of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
4
5
 
5
- This rule aims to shorten destructuring in `for-of` statements
6
-
7
- Examples of **incorrect** code for this rule:
6
+ ## Example of incorrect code
8
7
 
9
8
  ```js
10
9
  for ({
@@ -14,13 +13,13 @@ for ({
14
13
  }
15
14
  ```
16
15
 
17
- Examples of **correct** code for this rule:
18
-
19
- ## Options
20
-
21
- `maxProperties` - maximum properties count to work with.
16
+ ## ✅ Example of correct code
22
17
 
23
18
  ```js
24
19
  for ({username, password} of users) {
25
20
  }
26
21
  ```
22
+
23
+ ## Options
24
+
25
+ `maxProperties` - maximum properties count to work with, defaults to **8**.
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,18 +1,16 @@
1
- # Keep each property on separate line when destructuring long properties (`long-properties-destructuring`)
1
+ # long-properties-destructuring
2
2
 
3
- Always add new lines, when property name is longer then 15 characters.
3
+ Keep each property on separate line when destructuring properties with name length **15** characters and more.
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 shorten destricturing of one property.
8
-
9
- Examples of **incorrect** code for this rule:
7
+ ## Example of incorrect code
10
8
 
11
9
  ```js
12
10
  const {isIdentifier} = user;
13
11
  ```
14
12
 
15
- Examples of **correct** code for this rule:
13
+ ## ✅ Example of correct code
16
14
 
17
15
  ```js
18
16
  const {
package/lib/markdown.js CHANGED
@@ -8,8 +8,6 @@ const commonRules = {
8
8
  'no-multi-spaces': 'off',
9
9
  'no-empty': 'off',
10
10
  'eol-last': 'off',
11
- 'quotes': 'off',
12
- 'quote-props': 'off',
13
11
  'no-unreachable': 'off',
14
12
  'no-constant-condition': 'off',
15
13
  'node/no-extraneous-require': 'off',
@@ -1,10 +1,11 @@
1
- # Keep each property on separate line when using multiple destructuring properties (`multiple-properties-destructuring`)
1
+ # multiple-properties-destructuring
2
2
 
3
- In the same way as eslint [object-property-newline](https://eslint.org/docs/rules/object-property-newline), but for destructuring.
3
+ Keep each property on separate line when using multiple destructuring properties
4
+ In the same way as **ESLint** [object-property-newline](https://eslint.org/docs/rules/object-property-newline), but for destructuring.
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
- Examples of **incorrect** code for this rule:
8
+ ## ❌ Example of incorrect code
8
9
 
9
10
  ```js
10
11
  const {a, b, c} = user;
@@ -14,7 +15,7 @@ const {a, b, c} = user;
14
15
  import {a, b, c} from 'user';
15
16
  ```
16
17
 
17
- Examples of **correct** code for this rule:
18
+ ## ✅ Example of correct code
18
19
 
19
20
  ```js
20
21
  const {
@@ -34,7 +35,7 @@ import {
34
35
 
35
36
  ## Options
36
37
 
37
- `minProperties` - minimum properties count to work with.
38
+ `minProperties` - minimum properties count to work with, defaults: `2`.
38
39
 
39
40
  ```js
40
41
  const {
@@ -0,0 +1,18 @@
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
+
13
+ ## ✅ Example of correct code
14
+
15
+ ```js
16
+ if (a)
17
+ b();
18
+ ```
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ const {types} = require('putout');
4
+ const {isExpressionStatement} = types;
5
+
6
+ const reg = /\)\n(\s+)?\n/;
7
+
8
+ module.exports.report = () => `Remove newline`;
9
+
10
+ module.exports.fix = ({text}) => {
11
+ return text.replace(reg, ')\n');
12
+ };
13
+
14
+ module.exports.include = () => [
15
+ 'IfStatement',
16
+ ];
17
+
18
+ module.exports.filter = ({node, text}) => {
19
+ const {consequent} = node;
20
+
21
+ if (!isExpressionStatement(consequent))
22
+ return false;
23
+
24
+ return reg.test(text);
25
+ };
26
+
@@ -1,8 +1,8 @@
1
- # Putout (`putout`)
1
+ # Putout
2
2
 
3
- 🐊[`Putout`](https://github.com/coderaiser/putout) used as eslint plugin runs [putout rules](https://github.com/coderaiser/putout#built-in-transforms) in `eslint`.
3
+ Run 🐊[**Putout**](https://github.com/coderaiser/putout#built-in-transforms) rules from [**ESLint**](https://eslint.org/).
4
4
 
5
- And can be [configured](https://eslint.org/docs/user-guide/configuring#configuring-rules) according to [putout configuration](https://github.com/coderaiser/putout#configuration).
5
+ And can be [configured](https://eslint.org/docs/user-guide/configuring#configuring-rules) according to [**Putout** configuration](https://github.com/coderaiser/putout#configuration).
6
6
 
7
7
  For example, if you want to disable the rule [remove-unused-variables](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-unused-variables) you can use:
8
8
 
@@ -1,12 +1,11 @@
1
- # Keep curly braces in one line when property is single (`single-property-destructuring`)
1
+ # single-property-destructuring
2
2
 
3
- When 🐊[`Putout`](https://github.com/coderaiser/putout) removes unused variables declared as destructured properties, it keeps one property to take 3 lines, instead of 1.
3
+ When 🐊[**Putout**](https://github.com/coderaiser/putout) removes unused variables declared as destructured properties, it keeps one property to take 3 lines, instead of 1.
4
+ This rule aims to shorten destructuring of one property, keeping curly braces in one line.
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 one property.
8
-
9
- Examples of **incorrect** code for this rule:
8
+ ## Example of incorrect code
10
9
 
11
10
  ```js
12
11
  import {
@@ -19,7 +18,7 @@ const {
19
18
 
20
19
  ```
21
20
 
22
- Examples of **correct** code for this rule:
21
+ ## ✅ Example of correct code
23
22
 
24
23
  ```js
25
24
  import {password} from './user.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-putout",
3
- "version": "14.0.0",
3
+ "version": "14.2.0",
4
4
  "type": "commonjs",
5
5
  "description": "eslint plugin for putout",
6
6
  "release": false,
@@ -38,7 +38,7 @@
38
38
  "@babel/eslint-parser": "^7.15.0",
39
39
  "@babel/plugin-syntax-class-properties": "^7.12.1",
40
40
  "@babel/traverse": "^7.16.3",
41
- "@putout/engine-parser": "^4.6.0",
41
+ "@putout/engine-parser": "^5.0.0",
42
42
  "@putout/eslint-config": "^6.0.0",
43
43
  "@typescript-eslint/eslint-plugin": "^5.5.0",
44
44
  "@typescript-eslint/parser": "^5.4.0",