eslint-plugin-putout 12.5.0 → 12.7.1

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
@@ -103,6 +103,7 @@ When using 🐊`Putout` in IDE with `--fix` on save, or when you want to disable
103
103
 
104
104
  List of disabled 🐊`Putout` rules:
105
105
 
106
+ - [no-useless-return](https://eslint.org/docs/rules/no-useless-return)
106
107
  - [remove-empty](https://github.com/coderaiser/putout/tree/v22.0.0/packages/plugin-remove-empty);
107
108
  - [remove-unused-variables](https://github.com/coderaiser/putout/tree/v22.0.0/packages/remove-unused-variables);
108
109
  - [remove-unused-types](https://github.com/coderaiser/putout/tree/v22.0.0/packages/remove-unused-types);
@@ -15,7 +15,7 @@ const regExp = /^;?\n( +)?\n +$/;
15
15
  module.exports.category = 'layout';
16
16
  module.exports.report = () => 'Add newline after function call';
17
17
 
18
- module.exports.filter = ({text, node, getText, getCommentsAfter}) => {
18
+ module.exports.filter = ({text, node, getText, getCommentsAfter, getSpacesAfterNode}) => {
19
19
  if (!isExpressionStatement(node.parent))
20
20
  return false;
21
21
 
@@ -33,7 +33,7 @@ module.exports.filter = ({text, node, getText, getCommentsAfter}) => {
33
33
  if (n < 3)
34
34
  return false;
35
35
 
36
- const spaces = getSpacesAfterNode(node, {text, getText});
36
+ const spaces = getSpacesAfterNode(node, {text});
37
37
 
38
38
  if (regExp.test(spaces))
39
39
  return false;
@@ -84,14 +84,3 @@ module.exports.include = () => [
84
84
  'CallExpression',
85
85
  ];
86
86
 
87
- function getSpacesAfterNode(node, {getText, text = getText(node)}) {
88
- let spaces = '';
89
- let i = 0;
90
-
91
- while (!spaces || /^[ \n;]+$/.test(spaces))
92
- spaces = getText(node, 0, ++i)
93
- .replace(text, '');
94
-
95
- return spaces.slice(0, -1);
96
- }
97
-
package/lib/index.js CHANGED
@@ -97,6 +97,7 @@ const safe = {
97
97
  ...recommended,
98
98
  rules: {
99
99
  ...recommended.rules,
100
+ 'no-useless-return': 'off',
100
101
  'putout/align-spaces': 'off',
101
102
  'putout/putout': ['error', {
102
103
  rules: {
@@ -6,9 +6,10 @@ const {
6
6
  transform,
7
7
  print,
8
8
  parse,
9
- traverse,
10
9
  } = require('putout');
11
10
 
11
+ const traverse = require('@babel/traverse').default;
12
+
12
13
  const v8 = require('v8');
13
14
 
14
15
  const parseOptions = require('putout/parse-options');
@@ -22,6 +23,8 @@ const getContextOptions = ({options}) => {
22
23
  const copyAST = (a) => v8.deserialize(v8.serialize(a));
23
24
  const returns = (a) => () => a;
24
25
 
26
+ const EMPTY_VISITORS = {};
27
+
25
28
  module.exports = {
26
29
  meta: {
27
30
  type: 'suggestion',
@@ -34,45 +37,44 @@ module.exports = {
34
37
  },
35
38
 
36
39
  create(context) {
37
- return {
38
- Program(node) {
39
- const name = context.getFilename();
40
- const options = getContextOptions(context);
41
- const resultOptions = parseOptions({
42
- name,
43
- options,
44
- });
45
-
46
- if (ignores(cwd, name, resultOptions))
47
- return;
48
-
49
- const source = context.getSourceCode();
50
- const {text} = source;
51
-
52
- const ast = parse(text, {
53
- parser: createParser(node),
54
- });
55
-
56
- const places = findPlaces(ast, text, resultOptions);
57
-
58
- for (const {rule, message, position} of places) {
59
- context.report({
60
- message: `${message} (${rule})`,
61
- fix: fix({
62
- ast,
63
- text,
64
- node,
65
- source,
66
- resultOptions,
67
- }),
68
- loc: {
69
- start: position,
70
- end: position,
71
- },
72
- });
73
- }
74
- },
75
- };
40
+ const name = context.getFilename();
41
+ const options = getContextOptions(context);
42
+ const resultOptions = parseOptions({
43
+ name,
44
+ options,
45
+ });
46
+
47
+ if (ignores(cwd, name, resultOptions))
48
+ return EMPTY_VISITORS;
49
+
50
+ const source = context.getSourceCode();
51
+ const {text} = source;
52
+ const node = source.ast;
53
+
54
+ const ast = parse(text, {
55
+ parser: createParser(node),
56
+ });
57
+
58
+ const places = findPlaces(ast, text, resultOptions);
59
+
60
+ for (const {rule, message, position} of places) {
61
+ context.report({
62
+ message: `${message} (${rule})`,
63
+ fix: fix({
64
+ ast,
65
+ text,
66
+ node,
67
+ source,
68
+ resultOptions,
69
+ }),
70
+ loc: {
71
+ start: position,
72
+ end: position,
73
+ },
74
+ });
75
+ }
76
+
77
+ return EMPTY_VISITORS;
76
78
  },
77
79
  };
78
80
 
package/lib/wrap.js CHANGED
@@ -8,10 +8,15 @@ const prepare = (plugin, context, options) => (node) => {
8
8
  const getText = source.getText.bind(source);
9
9
  const getCommentsBefore = source.getCommentsBefore.bind(source);
10
10
  const getCommentsAfter = source.getCommentsAfter.bind(source);
11
+
11
12
  const getSpacesBeforeNode = createGetSpacesBeforeNode({
12
13
  getText,
13
14
  });
14
15
 
16
+ const getSpacesAfterNode = createGetSpacesAfterNode({
17
+ getText,
18
+ });
19
+
15
20
  const text = getText(node);
16
21
 
17
22
  const result = filter({
@@ -22,6 +27,7 @@ const prepare = (plugin, context, options) => (node) => {
22
27
  getCommentsBefore,
23
28
  getCommentsAfter,
24
29
  getSpacesBeforeNode,
30
+ getSpacesAfterNode,
25
31
  filename,
26
32
  });
27
33
 
@@ -106,3 +112,14 @@ const createGetSpacesBeforeNode = ({getText}) => (node, text = getText(node)) =>
106
112
  return spaces.slice(1);
107
113
  };
108
114
 
115
+ const createGetSpacesAfterNode = ({getText}) => (node, {text = getText(node)}) => {
116
+ let spaces = '';
117
+ let i = 0;
118
+
119
+ while (!spaces || /^[ \n;]+$/.test(spaces))
120
+ spaces = getText(node, 0, ++i)
121
+ .replace(text, '');
122
+
123
+ return spaces.slice(0, -1);
124
+ };
125
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-putout",
3
- "version": "12.5.0",
3
+ "version": "12.7.1",
4
4
  "description": "eslint plugin for putout",
5
5
  "release": false,
6
6
  "tag": false,
@@ -36,13 +36,13 @@
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/traverse": "^7.16.3",
39
40
  "@putout/engine-parser": "^4.6.0",
40
41
  "@putout/eslint-config": "^6.0.0",
41
42
  "@typescript-eslint/eslint-plugin": "^5.5.0",
42
43
  "@typescript-eslint/parser": "^5.4.0",
43
44
  "align-spaces": "^1.0.0",
44
45
  "eslint-plugin-node": "^11.0.0",
45
- "estree-to-babel": "^4.0.1",
46
46
  "try-catch": "^3.0.0",
47
47
  "typescript": "^4.5.2"
48
48
  },