@putout/engine-runner 16.1.0 → 17.0.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
@@ -167,14 +167,9 @@ module.exports.fix = (path) => {
167
167
  path.remove();
168
168
  };
169
169
 
170
- module.exports.include = () => [
171
- 'debugger',
172
- ];
173
-
170
+ module.exports.include = () => ['debugger'];
174
171
  // optional
175
- module.exports.exclude = () => {
176
- };
177
-
172
+ module.exports.exclude = () => {};
178
173
  // optional
179
174
  module.exports.filter = (path) => {
180
175
  return true;
@@ -246,6 +241,7 @@ const plugins = [{
246
241
  }];
247
242
 
248
243
  const ast = parse('const m = "hi"; debugger');
244
+
249
245
  const places = runPlugins({
250
246
  ast,
251
247
  shebang: false, // default
@@ -293,7 +289,12 @@ module.exports.traverse = ({listStore}) => ({
293
289
  exit() {
294
290
  console.log(listStore());
295
291
  // returns
296
- [{type: 'DebuggerStatement'}, {type: 'DebuggerStatement'}];
292
+ [{
293
+ type: 'DebuggerStatement',
294
+ }, {
295
+ type: 'DebuggerStatement',
296
+ }];
297
+
297
298
  // for code
298
299
  'debugger; debugger';
299
300
  },
package/lib/declare.js CHANGED
@@ -20,4 +20,3 @@ function validateDeclare(declare) {
20
20
  if (!isFn(declare))
21
21
  throw Error(`☝️ Looks like 'declare' property value is not a 'function', but '${typeof declare}' with value '${stringify(declare)}'.`);
22
22
  }
23
-
@@ -17,10 +17,7 @@ module.exports.getPosition = (path, shebang) => {
17
17
  column: 0,
18
18
  };
19
19
 
20
- const {
21
- line,
22
- column,
23
- } = node.loc.start;
20
+ const {line, column} = node.loc.start;
24
21
 
25
22
  return {
26
23
  line: shebang ? line + 1 : line,
package/lib/include.js CHANGED
@@ -51,6 +51,7 @@ const prePush = ({rule, filter, push, options}) => (path) => {
51
51
 
52
52
  const getTraverse = (include, filter, rule) => ({push, options}) => {
53
53
  const result = {};
54
+
54
55
  const visitor = prePush({
55
56
  rule,
56
57
  filter,
package/lib/index.js CHANGED
@@ -11,10 +11,7 @@ const include = require('./include');
11
11
  const replace = require('./replace');
12
12
  const declare = require('./declare');
13
13
 
14
- const {
15
- getPath,
16
- getPosition,
17
- } = require('./get-position');
14
+ const {getPath, getPosition} = require('./get-position');
18
15
 
19
16
  const isRemoved = (a) => a?.removed;
20
17
 
@@ -22,6 +19,7 @@ module.exports.runPlugins = ({ast, shebang, fix, fixCount, plugins, template = r
22
19
  let places = [];
23
20
 
24
21
  const merge = once(mergeVisitors);
22
+
25
23
  const {
26
24
  pluginsFind,
27
25
  pluginsTraverse,
@@ -51,17 +49,21 @@ module.exports.getPosition = getPosition;
51
49
 
52
50
  function run({ast, fix, shebang, pluginsFind, pluginsTraverse, template, merge}) {
53
51
  return [
54
- ...runWithoutMerge({ast,
52
+ ...runWithoutMerge({
53
+ ast,
55
54
  fix,
56
55
  shebang,
57
56
  template,
58
- pluginsFind}),
59
- ...runWithMerge({ast,
57
+ pluginsFind,
58
+ }),
59
+ ...runWithMerge({
60
+ ast,
60
61
  fix,
61
62
  shebang,
62
63
  template,
63
64
  pluginsTraverse,
64
- merge}),
65
+ merge,
66
+ }),
65
67
  ];
66
68
  }
67
69
 
@@ -96,10 +98,8 @@ function runWithoutMerge({ast, fix, shebang, template, pluginsFind}) {
96
98
 
97
99
  for (const {rule, plugin, msg, options} of pluginsFind) {
98
100
  debug(`find: ${rule}`);
99
- const {
100
- report,
101
- find,
102
- } = plugin;
101
+
102
+ const {report, find} = plugin;
103
103
 
104
104
  const items = superFind({
105
105
  rule,
@@ -178,4 +178,3 @@ function splitPlugins(plugins) {
178
178
  pluginsTraverse,
179
179
  };
180
180
  }
181
-
@@ -9,4 +9,3 @@ module.exports = (a) => {
9
9
 
10
10
  return maybeArray(a);
11
11
  };
12
-
@@ -6,6 +6,7 @@ const {generate} = require('@putout/engine-parser');
6
6
  const runFix = require('./run-fix');
7
7
  const {getPosition} = require('./get-position');
8
8
  const maybeArray = require('./maybe-array');
9
+
9
10
  const {
10
11
  listStore,
11
12
  mapStore,
@@ -18,6 +19,7 @@ const shouldSkip = (a) => !a.parent;
18
19
  const {merge} = traverse.visitors;
19
20
 
20
21
  const {assign} = Object;
22
+
21
23
  const parse = (name, plugin, options) => {
22
24
  const list = [];
23
25
 
@@ -80,6 +82,7 @@ module.exports = (pluginsToMerge, {fix, shebang, template}) => {
80
82
  }
81
83
 
82
84
  const entries = Object.entries(pushed);
85
+
83
86
  const visitor = {
84
87
  shouldSkip,
85
88
  ...merge(mergeItems),
@@ -136,4 +139,3 @@ function getStore(plugin, {fix, rule, shebang, msg, options}) {
136
139
  pathStore: paths,
137
140
  };
138
141
  }
139
-
@@ -7,6 +7,7 @@ module.exports = (parentPath) => {
7
7
  let current = {
8
8
  parentPath,
9
9
  };
10
+
10
11
  const path = [];
11
12
 
12
13
  while (current = current.parentPath) {
@@ -32,4 +33,3 @@ function findKey(path, parent) {
32
33
  return key;
33
34
  }
34
35
  }
35
-
@@ -8,10 +8,7 @@ const {
8
8
  isExpressionStatement,
9
9
  } = require('@babel/types');
10
10
 
11
- const {
12
- remove,
13
- replaceWith,
14
- } = require('@putout/operate');
11
+ const {remove, replaceWith} = require('@putout/operate');
15
12
 
16
13
  const {
17
14
  compare,
@@ -31,6 +28,7 @@ const log = (from, path) => {
31
28
  };
32
29
 
33
30
  const {keys, entries} = Object;
31
+
34
32
  const {stringify} = JSON;
35
33
 
36
34
  const stub = () => [];
@@ -46,7 +44,10 @@ module.exports = ({rule, plugin, msg, options}) => {
46
44
  filter = getFilter(plugin.match, options),
47
45
  } = plugin;
48
46
 
49
- const replaceItems = replace({options});
47
+ const replaceItems = replace({
48
+ options,
49
+ });
50
+
50
51
  const fix = getFix(replaceItems);
51
52
  const include = packKeys(replaceItems);
52
53
 
@@ -116,7 +117,10 @@ const fix = (from, to, path) => {
116
117
  });
117
118
 
118
119
  mark.add();
119
- path.scope.getBlockParent().crawl();
120
+ path
121
+ .scope
122
+ .getBlockParent()
123
+ .crawl();
120
124
 
121
125
  log(from, newPath);
122
126
  };
@@ -127,7 +131,9 @@ const getFix = (items) => (path) => {
127
131
  };
128
132
 
129
133
  const getFilter = (match = stubMatch, options) => (path) => {
130
- const all = entries(match({options}));
134
+ const all = entries(match({
135
+ options,
136
+ }));
131
137
 
132
138
  for (const [from, matchProperty] of all) {
133
139
  const nodeFrom = template.ast(from);
@@ -193,4 +199,3 @@ function checkExpressionStatement(nodeFrom, nodeTo, path) {
193
199
 
194
200
  throw Error(`☝️ Looks like try to put Statement in place of Expression, use 'match' to filter out such cases`);
195
201
  }
196
-
@@ -9,10 +9,7 @@ const name = '__putout_runner_replace';
9
9
  const hasWatermark = (watermark) => (path) => path.node?.[name]?.has(watermark);
10
10
 
11
11
  module.exports = (from, to, path) => {
12
- const {
13
- watermark,
14
- highWatermark,
15
- } = create(from, to, path);
12
+ const {watermark, highWatermark} = create(from, to, path);
16
13
 
17
14
  const program = path.findParent(isProgram) || path;
18
15
 
@@ -54,7 +51,10 @@ function init({path, program}) {
54
51
 
55
52
  module.exports.add = add;
56
53
  function add({path, program, watermark, highWatermark}) {
57
- init({path, program});
54
+ init({
55
+ path,
56
+ program,
57
+ });
58
58
 
59
59
  path?.node[name].add(watermark);
60
60
  program.node[name].add(highWatermark);
@@ -65,9 +65,5 @@ function has({path, program, watermark, highWatermark}) {
65
65
  if (path.node?.[name].has(watermark) || path.findParent(hasWatermark(watermark)))
66
66
  return true;
67
67
 
68
- if (program.node[name].has(highWatermark))
69
- return true;
70
-
71
- return false;
68
+ return program.node[name].has(highWatermark);
72
69
  }
73
-
package/lib/run-fix.js CHANGED
@@ -9,11 +9,16 @@ const isFn = (a) => typeof a === 'function';
9
9
  const getPath = (path) => path.path || path;
10
10
 
11
11
  const tryToFix = (fix, {path, position, options}) => {
12
- const [e] = tryCatch(fix, path, {options});
12
+ const [e] = tryCatch(fix, path, {
13
+ options,
14
+ });
15
+
13
16
  const {scope} = path.path || path;
14
17
 
15
18
  if (!e && scope)
16
- scope.getProgramParent().crawl();
19
+ scope
20
+ .getProgramParent()
21
+ .crawl();
17
22
 
18
23
  if (!e) {
19
24
  return;
@@ -44,4 +49,3 @@ function validate(name, fn) {
44
49
  if (!isFn(fn))
45
50
  throw Error(`☝️ Looks like '${name}' is not a 'function' but '${typeof fn}' with value: '${stringify(fn)}'. More on writing 🐊Putout Plugins: https://git.io/JqcMn`);
46
51
  }
47
-
package/lib/store.js CHANGED
@@ -81,6 +81,7 @@ function createListStore(returns = id) {
81
81
 
82
82
  fn.clear = () => {
83
83
  const a = list;
84
+
84
85
  list = new Set();
85
86
 
86
87
  return returns(toArray(a));
package/lib/super-find.js CHANGED
@@ -8,12 +8,17 @@ const {merge} = babelTraverse.visitors;
8
8
 
9
9
  module.exports = function superFind({rule, find, ast, options, template}) {
10
10
  const pushItems = [];
11
+
11
12
  const push = (a) => {
12
13
  pushItems.push(a);
13
14
  };
14
15
 
15
16
  const returnItems = find(ast, {
16
- traverse: traverse({rule, options, template}),
17
+ traverse: traverse({
18
+ rule,
19
+ options,
20
+ template,
21
+ }),
17
22
  generate,
18
23
  types,
19
24
  push,
@@ -61,6 +61,7 @@ module.exports = ({rule, visitor, options}) => {
61
61
  }
62
62
 
63
63
  const [node, type] = parseTemplate(tmpl);
64
+
64
65
  const visit = wrapWithCheck({
65
66
  rule,
66
67
  fn,
@@ -102,4 +103,3 @@ function wrapWithCheck({rule, nodesInclude, nodesExclude, fn}) {
102
103
  }
103
104
  };
104
105
  }
105
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/engine-runner",
3
- "version": "16.1.0",
3
+ "version": "17.0.1",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Run 🐊Putout plugins",
@@ -26,10 +26,10 @@
26
26
  "dependencies": {
27
27
  "@babel/traverse": "^7.12.7",
28
28
  "@babel/types": "^7.12.7",
29
- "@putout/compare": "^10.0.0",
30
- "@putout/engine-parser": "^6.0.0",
29
+ "@putout/compare": "^11.0.0",
30
+ "@putout/engine-parser": "^7.0.0",
31
31
  "@putout/operate": "^8.0.0",
32
- "@putout/operator-declare": "^5.0.0",
32
+ "@putout/operator-declare": "^6.0.1",
33
33
  "debug": "^4.1.1",
34
34
  "jessy": "^3.0.0",
35
35
  "nessy": "^4.0.0",
@@ -44,7 +44,7 @@
44
44
  "devDependencies": {
45
45
  "@babel/plugin-codemod-optional-catch-binding": "^7.7.4",
46
46
  "@putout/plugin-minify": "*",
47
- "c8": "^7.5.0",
47
+ "c8": "^8.0.0",
48
48
  "eslint": "^8.0.1",
49
49
  "eslint-plugin-n": "^16.0.0",
50
50
  "eslint-plugin-putout": "^17.0.0",