eslint-plugin-putout 12.3.0 → 12.5.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.
@@ -11,7 +11,7 @@ module.exports.include = () => [
11
11
 
12
12
  const badStart = /^\[\n(\s+)?{/;
13
13
  const badEndReg = /},?\n(\s+)?]/;
14
- const badMiddle = /\},\n(s+)?\{/;
14
+ const badMiddle = /\},\n(\s+)?\{/;
15
15
 
16
16
  module.exports.filter = ({node, text}) => {
17
17
  const {elements} = node;
@@ -8,8 +8,9 @@ const {
8
8
  parse,
9
9
  } = require('putout');
10
10
 
11
+ const traverse = require('@babel/traverse').default;
12
+
11
13
  const v8 = require('v8');
12
- const toBabel = require('estree-to-babel');
13
14
 
14
15
  const parseOptions = require('putout/parse-options');
15
16
 
@@ -20,6 +21,7 @@ const getContextOptions = ({options}) => {
20
21
  };
21
22
 
22
23
  const copyAST = (a) => v8.deserialize(v8.serialize(a));
24
+ const returns = (a) => () => a;
23
25
 
24
26
  module.exports = {
25
27
  meta: {
@@ -49,9 +51,7 @@ module.exports = {
49
51
  const {text} = source;
50
52
 
51
53
  const ast = parse(text, {
52
- parser: {
53
- parse: () => toBabel(copyAST(node)),
54
- },
54
+ parser: createParser(node),
55
55
  });
56
56
 
57
57
  const places = findPlaces(ast, text, resultOptions);
@@ -91,3 +91,28 @@ const fix = ({ast, text, node, source, resultOptions}) => (fixer) => {
91
91
  return fixer.replaceTextRange([0, last], code);
92
92
  };
93
93
 
94
+ const createParser = (node) => {
95
+ const ast = copyAST(node);
96
+ removeParent(ast);
97
+
98
+ const parser = {
99
+ parse: returns(ast),
100
+ };
101
+
102
+ return parser;
103
+ };
104
+
105
+ // ESLint adds parent to each node
106
+ // it makes recase go crazy
107
+ // so we better drop them
108
+ //
109
+ // https://github.com/eslint/eslint/blob/v8.4.0/lib/linter/linter.js#L964
110
+ function removeParent(ast) {
111
+ traverse(ast, {
112
+ noScope: true,
113
+ enter(path) {
114
+ delete path.node.parent;
115
+ },
116
+ });
117
+ }
118
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-putout",
3
- "version": "12.3.0",
3
+ "version": "12.5.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
  },