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