eslint-plugin-putout 11.16.1 → 12.0.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.
Files changed (33) hide show
  1. package/README.md +15 -14
  2. package/lib/add-newline-after-function-call/README.md +1 -1
  3. package/lib/add-newline-after-function-call/index.js +9 -2
  4. package/lib/add-newline-before-function-call/README.md +1 -1
  5. package/lib/add-newline-before-function-call/index.js +6 -1
  6. package/lib/add-newlines-between-types-in-union/README.md +1 -1
  7. package/lib/align-spaces/README.md +1 -1
  8. package/lib/array-element-newline/README.md +1 -1
  9. package/lib/destructuring-as-function-argument/README.md +1 -1
  10. package/lib/evaluate/README.md +1 -1
  11. package/lib/for-of-multiple-properties-destructuring/README.md +1 -1
  12. package/lib/function-declaration-paren-newline/README.md +1 -1
  13. package/lib/index.js +1 -0
  14. package/lib/keyword-spacing/README.md +1 -1
  15. package/lib/long-properties-destructuring/README.md +1 -1
  16. package/lib/markdown.js +8 -2
  17. package/lib/multiple-properties-destructuring/README.md +1 -1
  18. package/lib/newline-function-call-arguments/README.md +1 -1
  19. package/lib/no-unresolved/README.md +1 -1
  20. package/lib/object-init/README.md +1 -1
  21. package/lib/objects-braces-inside-array/README.md +1 -1
  22. package/lib/putout/README.md +1 -1
  23. package/lib/putout/index.js +7 -1
  24. package/lib/remove-empty-newline-after-last-specifier/README.md +1 -1
  25. package/lib/remove-empty-newline-before-first-specifier/README.md +1 -1
  26. package/lib/remove-newline-after-default-import/README.md +2 -2
  27. package/lib/remove-newline-from-empty-object/README.md +1 -1
  28. package/lib/single-property-destructuring/README.md +2 -2
  29. package/lib/tape-add-newline-before-assertion/README.md +2 -2
  30. package/lib/tape-add-newline-between-tests/README.md +2 -2
  31. package/lib/tape-remove-newline-before-t-end/README.md +2 -2
  32. package/lib/ts.js +32 -9
  33. package/package.json +8 -6
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/eslint-plugin-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).
9
9
 
10
10
  ## Installation
11
11
 
@@ -17,7 +17,7 @@ $ npm i putout eslint eslint-plugin-putout -D
17
17
 
18
18
  ## Usage
19
19
 
20
- Add `putout` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
20
+ Add `putout` to the plugins section of your `.eslintrc.json` configuration file. You can omit the `eslint-plugin-` prefix:
21
21
 
22
22
  ```json
23
23
  {
@@ -88,7 +88,7 @@ Then configure the rules you want to use under the rules section.
88
88
 
89
89
  ### Safe mode
90
90
 
91
- When using `putout` in IDE with `--fix` on save, or when you want to disable the most dangerous rules, use:
91
+ When using 🐊`Putout` in IDE with `--fix` on save, or when you want to disable the most dangerous rules, use:
92
92
 
93
93
  ```json
94
94
  {
@@ -101,16 +101,17 @@ When using `putout` in IDE with `--fix` on save, or when you want to disable the
101
101
  }
102
102
  ```
103
103
 
104
- List of disabled `putout` rules:
104
+ List of disabled 🐊`Putout` rules:
105
105
 
106
- - [remove-empty](https://github.com/coderaiser/putout/tree/v20.0.0/packages/plugin-remove-empty);
107
- - [remove-unused-variables](https://github.com/coderaiser/putout/tree/v20.0.0/packages/remove-unused-variables);
108
- - [remove-unused-types](https://github.com/coderaiser/putout/tree/v20.0.0/packages/remove-unused-types);
109
- - [remove-unused-for-of-variables](https://github.com/coderaiser/putout/tree/v20.0.0/packages/remove-unused-for-of-variables);
110
- - [remove-unused-expressions](https://github.com/coderaiser/putout/tree/v20.0.0/packages);
106
+ - [remove-empty](https://github.com/coderaiser/putout/tree/v22.0.0/packages/plugin-remove-empty);
107
+ - [remove-unused-variables](https://github.com/coderaiser/putout/tree/v22.0.0/packages/remove-unused-variables);
108
+ - [remove-unused-types](https://github.com/coderaiser/putout/tree/v22.0.0/packages/remove-unused-types);
109
+ - [remove-unused-for-of-variables](https://github.com/coderaiser/putout/tree/v22.0.0/packages/remove-unused-for-of-variables);
110
+ - [remove-unused-expressions](https://github.com/coderaiser/putout/tree/v22.0.0/packages);
111
111
  - [remove-useless-return](https://github.com/coderaiser/putout/tree/master/remove-useless-return);
112
- - [remove-skip](https://github.com/coderaiser/putout/tree/v20.0.0/packages/remove-skip);
113
- - [remove-only](https://github.com/coderaiser/putout/tree/v20.0.0/packages/remove-only);
114
- - [remove-console](https://github.com/coderaiser/putout/tree/v20.0.0/packages/remove-console);
115
- - [remove-debugger](https://github.com/coderaiser/putout/tree/v20.0.0/packages/remove-debugger);
116
- - [convert-for-to-for-of](https://github.com/coderaiser/putout/tree/v20.0.0/packages/convert-for-to-for-of);
112
+ - [remove-skip](https://github.com/coderaiser/putout/tree/v22.0.0/packages/remove-skip);
113
+ - [remove-only](https://github.com/coderaiser/putout/tree/v22.0.0/packages/remove-only);
114
+ - [remove-console](https://github.com/coderaiser/putout/tree/v22.0.0/packages/remove-console);
115
+ - [remove-debugger](https://github.com/coderaiser/putout/tree/v22.0.0/packages/remove-debugger);
116
+ - [remove-unreachable-code](https://github.com/coderaiser/putout/tree/v22.0.0/packages/remove-unreachable-code);
117
+ - [convert-for-to-for-of](https://github.com/coderaiser/putout/tree/v22.0.0/packages/convert-for-to-for-of);
@@ -1,4 +1,4 @@
1
- # Add new line after function call (add-newline-after-function-call)
1
+ # Add new line after function call (`add-newline-after-function-call`)
2
2
 
3
3
  ## Rule Details
4
4
 
@@ -12,7 +12,7 @@ const {
12
12
 
13
13
  const regExp = /^;?\n( +)?\n +$/;
14
14
 
15
- module.exports.category = 'typescript';
15
+ module.exports.category = 'layout';
16
16
  module.exports.report = () => 'Add newline after function call';
17
17
 
18
18
  module.exports.filter = ({text, node, getText, getCommentsAfter}) => {
@@ -47,6 +47,7 @@ module.exports.filter = ({text, node, getText, getCommentsAfter}) => {
47
47
  if (i === n - 1)
48
48
  break;
49
49
 
50
+ const prev = body[i - 1];
50
51
  const next = body[i + 1];
51
52
 
52
53
  if (!isVariableDeclaration(next))
@@ -62,8 +63,14 @@ module.exports.filter = ({text, node, getText, getCommentsAfter}) => {
62
63
 
63
64
  const spacesAfterNext = getSpacesAfterNode(next, {getText});
64
65
 
65
- if (!regExp.test(spacesAfterNext))
66
+ if (regExp.test(spacesAfterNext))
67
+ break;
68
+
69
+ if (!prev)
66
70
  return true;
71
+
72
+ const spacesAfterPrev = getSpacesAfterNode(prev, {getText});
73
+ return !regExp.test(spacesAfterPrev);
67
74
  }
68
75
 
69
76
  return false;
@@ -1,4 +1,4 @@
1
- # Add new line before function call (add-newline-before-function-call)
1
+ # Add new line before function call (`add-newline-before-function-call`)
2
2
 
3
3
  ## Rule Details
4
4
 
@@ -43,6 +43,7 @@ module.exports.filter = ({text, node, getText, getCommentsBefore}) => {
43
43
  continue;
44
44
 
45
45
  const prevA = body[i - 1];
46
+ const nextA = body[i + 1];
46
47
 
47
48
  if (!isVariableDeclaration(prevA))
48
49
  return false;
@@ -52,7 +53,11 @@ module.exports.filter = ({text, node, getText, getCommentsBefore}) => {
52
53
  if (regExp.test(spaces))
53
54
  return false;
54
55
 
55
- return true;
56
+ if (!nextA)
57
+ return true;
58
+
59
+ const nextSpaces = getSpacesBeforeNode(nextA, {getText});
60
+ return !regExp.test(nextSpaces);
56
61
  }
57
62
 
58
63
  return false;
@@ -1,4 +1,4 @@
1
- # Add new lines between types in union (add-newlines-between-types-in-union)
1
+ # Add new lines between types in union (`add-newlines-between-types-in-union`)
2
2
 
3
3
  ## Rule Details
4
4
 
@@ -1,4 +1,4 @@
1
- # Spaces should be aligned (aling-spaces)
1
+ # Spaces should be aligned (`aling-spaces`)
2
2
 
3
3
  After `putout` process files it can remove spaces from empty line, this `rule` fixes it.
4
4
 
@@ -1,4 +1,4 @@
1
- # Add new lines between types in union (add-newlines-between-types-in-union)
1
+ # Add new lines between types in union (`add-newlines-between-types-in-union`)
2
2
 
3
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
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).
@@ -1,4 +1,4 @@
1
- # keep curly bracesin in one line when you use destructuring as function argument (destructuring-as-function-argument)
1
+ # Keep curly braces in one line when you use destructuring as function argument (`destructuring-as-function-argument`)
2
2
 
3
3
  When `putout` removes unused variable located in function argument object pattern, it formats in in a multiple lines.
4
4
 
@@ -1,4 +1,4 @@
1
- # evaluate expression (evaluate)
1
+ # evaluate expression (`evaluate`)
2
2
 
3
3
  Evaluate expression started with `__putout_evaluate: `.
4
4
  Provided code is processed with [`@putout/plugin-declare-undefined-variables`](https://github.com/coderaiser/putout/tree/master/packages/plugin-declare-undefined-variables). So next code:
@@ -1,4 +1,4 @@
1
- # Keep all properties in one line when using destructuring in for-of (for-of-multiple-properties-destructuring)
1
+ # Keep all properties in one line when using destructuring in `for-of` (`for-of-multiple-properties-destructuring`)
2
2
 
3
3
  ## Rule Details
4
4
 
@@ -1,4 +1,4 @@
1
- # Use spaces around "catch" (function-declaration-paren-newline)
1
+ # Remove newlines between parens in function declaration (`function-declaration-paren-newline`)
2
2
 
3
3
  Similar to `eslint` [function-paren-newline](https://eslint.org/docs/rules/function-declaration-paren-newline), but forbids new lines in function declarations and expressions arguments.
4
4
 
package/lib/index.js CHANGED
@@ -105,6 +105,7 @@ const safe = {
105
105
  'remove-unused-variables': 'off',
106
106
  'remove-unused-expressions': 'off',
107
107
  'remove-unused-for-of-variables': 'off',
108
+ 'remove-unreachable-code': 'off',
108
109
  'remove-useless-return': 'off',
109
110
  'tape/remove-skip': 'off',
110
111
  'tape/remove-only': 'off',
@@ -1,4 +1,4 @@
1
- # Use spaces around "catch" (keyword-spacing)
1
+ # Use spaces around `catch` (`keyword-spacing`)
2
2
 
3
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.
4
4
 
@@ -1,4 +1,4 @@
1
- # keep each property on separate line when destructuring long properties (long-properties-destructuring)
1
+ # Keep each property on separate line when destructuring long properties (`long-properties-destructuring`)
2
2
 
3
3
  Always add new lines, when property name is longer then 15 characters.
4
4
 
package/lib/markdown.js CHANGED
@@ -33,13 +33,19 @@ module.exports = [{
33
33
  parserOpts,
34
34
  plugins: [
35
35
  '@babel/plugin-syntax-class-properties',
36
- '@babel/plugin-syntax-top-level-await',
37
36
  ],
38
37
  },
39
38
  },
40
39
  }, {
41
40
  ...ts,
42
41
  files: '*.md{ts}',
43
- rules: commonRules,
42
+ rules: {
43
+ ...commonRules,
44
+ ...ts.rules,
45
+ '@typescript-eslint/no-unused-vars': 'off',
46
+ '@typescript-eslint/no-explicit-any': 'off',
47
+ '@typescript-eslint/no-inferrable-types': 'off',
48
+ '@typescript-eslint/array-type': 'off',
49
+ },
44
50
  }];
45
51
 
@@ -1,4 +1,4 @@
1
- # keep each property on separate line when using multiple destructuring properties (multiple-properties-destructuring)
1
+ # Keep each property on separate line when using multiple destructuring properties (`multiple-properties-destructuring`)
2
2
 
3
3
  In the same way as eslint [object-property-newline](https://eslint.org/docs/rules/object-property-newline), but for destructuring.
4
4
 
@@ -1,4 +1,4 @@
1
- # keep curly bracesin in one line when property is single (newline-function-call-arguments)
1
+ # Keep curly braces in one line when property is single (`newline-function-call-arguments`)
2
2
 
3
3
  Addition to eslint's [function-paren-newline](https://eslint.org/docs/rules/function-paren-newline)
4
4
 
@@ -1,4 +1,4 @@
1
- # check if path can be resolved and fix if cannot (no-unresolved)
1
+ # Check if path can be resolved and fix if cannot (`no-unresolved`)
2
2
 
3
3
  Similar to [`no-unresolved`](https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-unresolved.md) from
4
4
  [`eslint-plugin-putout`](https://github.com/import-js/eslint-plugin-import). But supports only `ESM` and have `autofix`.
@@ -1,4 +1,4 @@
1
- # keep each property on separate line when initializing an object(object-init)
1
+ # Keep each property on separate line when initializing an object(`object-init`)
2
2
 
3
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`.
4
4
 
@@ -1,4 +1,4 @@
1
- # keep braces on the same line as brackets (object-braces-inside-array)
1
+ # Keep braces on the same line as brackets (`object-braces-inside-array`)
2
2
 
3
3
  ## Rule Details
4
4
 
@@ -1,4 +1,4 @@
1
- # Putout (putout)
1
+ # Putout (`putout`)
2
2
 
3
3
  🐊[`Putout`](https://github.com/coderaiser/putout) used as eslint plugin.
4
4
 
@@ -5,6 +5,7 @@ const {
5
5
  findPlaces,
6
6
  transform,
7
7
  print,
8
+ parse,
8
9
  } = require('putout');
9
10
 
10
11
  const v8 = require('v8');
@@ -47,7 +48,12 @@ module.exports = {
47
48
  const source = context.getSourceCode();
48
49
  const {text} = source;
49
50
 
50
- const ast = toBabel(copyAST(node));
51
+ const ast = parse(text, {
52
+ parser: {
53
+ parse: () => toBabel(copyAST(node)),
54
+ },
55
+ });
56
+
51
57
  const places = findPlaces(ast, text, resultOptions);
52
58
 
53
59
  for (const {rule, message, position} of places) {
@@ -1,4 +1,4 @@
1
- # Remove empty new line after last specifier(remove-empty-newline-after-last-specifier)
1
+ # Remove empty new line after last specifier(`remove-empty-newline-after-last-specifier`)
2
2
 
3
3
  ## Rule Details
4
4
 
@@ -1,4 +1,4 @@
1
- # Remove empty new line before first specifier(remove-empty-newline-before-first-specifier)
1
+ # Remove empty new line before first specifier (`remove-empty-newline-before-first-specifier`)
2
2
 
3
3
  ## Rule Details
4
4
 
@@ -1,6 +1,6 @@
1
- # Keep opening curly brace on one line with default import (remove-newline-after-default-import)
1
+ # Keep opening curly brace on one line with default import (`remove-newline-after-default-import`)
2
2
 
3
- Fixes [object-curly-newline](https://eslint.org/docs/rules/object-curly-newline) + [eslint-plugin-modules-newline](https://github.com/gmsorrow/eslint-plugin-modules-newline).
3
+ Fixes [`object-curly-newline`](https://eslint.org/docs/rules/object-curly-newline) + [`eslint-plugin-modules-newline`](https://github.com/gmsorrow/eslint-plugin-modules-newline).
4
4
 
5
5
  ## Rule Details
6
6
 
@@ -1,4 +1,4 @@
1
- # Remove new line in empty object (remove-newline-from-empty-object)
1
+ # Remove new line in empty object (`remove-newline-from-empty-object`)
2
2
 
3
3
  ## Rule Details
4
4
 
@@ -1,6 +1,6 @@
1
- # keep curly bracesin in one line when property is single (single-property-destructuring)
1
+ # Keep curly braces in one line when property is single (`single-property-destructuring`)
2
2
 
3
- When `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
4
 
5
5
  ## Rule Details
6
6
 
@@ -1,6 +1,6 @@
1
- # Add newline before assertion (add-newline-before-assertion)
1
+ # Add newline before assertion (`add-newline-before-assertion`)
2
2
 
3
- Add newline before `t.equal()` etc, for [supertape](https://github.com/coderaiser/supertape).
3
+ Add newline before `t.equal()` etc, for [`supertape`](https://github.com/coderaiser/supertape).
4
4
 
5
5
  ## Rule Details
6
6
 
@@ -1,6 +1,6 @@
1
- # Add newline between tests (add-newline-between-tests)
1
+ # Add newline between tests (`add-newline-between-tests`)
2
2
 
3
- Add newline between tests, for [supertape](https://github.com/coderaiser/supertape).
3
+ Add newline between tests, for [`supertape`](https://github.com/coderaiser/supertape).
4
4
 
5
5
  ## Rule Details
6
6
 
@@ -1,6 +1,6 @@
1
- # Remove newline before `t.end()` (remove-newline-before-t-end)
1
+ # Remove newline before `t.end()` (`remove-newline-before-t-end`)
2
2
 
3
- Remove newline before `t.end()`, for [supertape](https://github.com/coderaiser/supertape).
3
+ Remove newline before `t.end()`, for [`supertape`](https://github.com/coderaiser/supertape).
4
4
 
5
5
  ## Rule Details
6
6
 
package/lib/ts.js CHANGED
@@ -1,21 +1,44 @@
1
1
  'use strict';
2
2
 
3
- const parserOpts = require('@putout/engine-parser/babel/options');
4
-
5
- module.exports = [{
3
+ const ts = {
6
4
  files: '*.ts',
7
- parser: '@babel/eslint-parser/experimental-worker',
5
+ parser: '@typescript-eslint/parser',
8
6
  parserOptions: {
9
- requireConfigFile: false,
10
- babelOptions: {
11
- parserOpts,
12
- plugins: ['@babel/plugin-syntax-typescript'],
7
+ ecmaFeatures: {
8
+ jsx: false,
13
9
  },
14
10
  },
11
+ plugins: [
12
+ '@typescript-eslint',
13
+ ],
14
+ extends: [
15
+ 'plugin:@typescript-eslint/recommended',
16
+ ],
15
17
  rules: {
16
18
  'no-undef': 'off',
17
19
  'no-var': 'off',
18
20
  'putout/no-unresolved': 'off',
21
+ 'semi': 'off',
22
+ '@typescript-eslint/semi': 'error',
23
+ '@typescript-eslint/array-type': 'error',
24
+ 'space-before-function-paren': 'off',
25
+ '@typescript-eslint/space-before-function-paren': ['error', {
26
+ anonymous: 'never',
27
+ named: 'never',
28
+ asyncArrow: 'always',
29
+ }],
30
+ },
31
+ };
32
+
33
+ module.exports = [
34
+ ts, {
35
+ ...ts,
36
+ files: '*.tsx',
37
+ parserOptions: {
38
+ ecmaFeatures: {
39
+ jsx: true,
40
+ },
41
+ },
19
42
  },
20
- }];
43
+ ];
21
44
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-putout",
3
- "version": "11.16.1",
3
+ "version": "12.0.0",
4
4
  "description": "eslint plugin for putout",
5
5
  "release": false,
6
6
  "tag": false,
@@ -36,14 +36,15 @@
36
36
  "@babel/core": "^7.12.3",
37
37
  "@babel/eslint-parser": "^7.15.0",
38
38
  "@babel/plugin-syntax-class-properties": "^7.12.1",
39
- "@babel/plugin-syntax-top-level-await": "^7.12.1",
40
- "@babel/plugin-syntax-typescript": "^7.12.1",
41
39
  "@putout/engine-parser": "^4.6.0",
42
40
  "@putout/eslint-config": "^6.0.0",
41
+ "@typescript-eslint/eslint-plugin": "^5.5.0",
42
+ "@typescript-eslint/parser": "^5.4.0",
43
43
  "align-spaces": "^1.0.0",
44
44
  "eslint-plugin-node": "^11.0.0",
45
45
  "estree-to-babel": "^4.0.1",
46
- "try-catch": "^3.0.0"
46
+ "try-catch": "^3.0.0",
47
+ "typescript": "^4.5.2"
47
48
  },
48
49
  "devDependencies": {
49
50
  "c8": "^7.5.0",
@@ -54,14 +55,15 @@
54
55
  "montag": "^1.0.0",
55
56
  "simport": "^1.2.0",
56
57
  "supertape": "^6.6.0",
57
- "try-to-catch": "^3.0.0"
58
+ "try-to-catch": "^3.0.0",
59
+ "@babel/plugin-syntax-typescript": "^7.12.1"
58
60
  },
59
61
  "engines": {
60
62
  "node": ">=14"
61
63
  },
62
64
  "peerDependencies": {
63
65
  "eslint": ">=8.0.0",
64
- "putout": ">=21"
66
+ "putout": ">=22"
65
67
  },
66
68
  "license": "MIT",
67
69
  "publishConfig": {