putout 24.2.1 → 24.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.
package/ChangeLog CHANGED
@@ -1,3 +1,48 @@
1
+ 2022.01.26, v24.5.0
2
+
3
+ fix:
4
+ - (putout) rm unused thread-it
5
+
6
+ feature:
7
+ - (package) @putout/plugin-strict-mode v3.0.0
8
+ - (package) @putout/compare v8.7.0
9
+ - (@putout/compare) add findUp option
10
+ - (@putout/compare) add support of findUp
11
+ - (@putout/plugin-strict-mode) drop support of putout < 24
12
+ - (@putout/plugin-strict-mode) commonjs -> CommonJS
13
+ - (@putout/plugin-strict-mode) is esm -> in ESM
14
+
15
+
16
+ 2022.01.25, v24.4.0
17
+
18
+ feature:
19
+ - (putout) cli: move out runner
20
+ - (@putout/eslint-config) padding-line-between-statements: add import
21
+ - (@putout/eslint-config) padding-line-between-statements: add export
22
+ - (@putout/eslint-config) enable operator-linebreak
23
+ - (@putout/test) add ESLint support
24
+
25
+
26
+ 2022.01.24, v24.3.0
27
+
28
+ feature:
29
+ - (putout) eslint: add ability to enable putout/putout rule with a flag
30
+ - (putout/eslint) add ability to enable putout
31
+
32
+
33
+ 2022.01.24, v24.2.2
34
+
35
+ fix:
36
+ - (@putout/plugin-declare-undefined-variables) node-js: exclude "promises" as it is to general
37
+ - (@putout/engine-runner) avoid duplication of plugins
38
+
39
+ feature:
40
+ - (package) @putout/plugin-convert-esm-to-commonjs v4.0.0
41
+ - (@putout/plugin-convert-esm-to-commonjs) drop support of putout < 24
42
+ - (@putout/plugin-convert-esm-to-commonjs) Commonjs -> CommonJS
43
+ - (@putout/engine-runner) add ability to debug with "putout:runner:replace"
44
+
45
+
1
46
  2022.01.21, v24.2.1
2
47
 
3
48
  fix:
@@ -49,7 +49,7 @@ const getESLint = ({fix, config}) => {
49
49
  };
50
50
  };
51
51
 
52
- module.exports = async ({name, code, fix, config}) => {
52
+ module.exports = async ({name, code, fix, config, putout = false}) => {
53
53
  const noChanges = [
54
54
  code,
55
55
  [],
@@ -81,7 +81,7 @@ module.exports = async ({name, code, fix, config}) => {
81
81
  ];
82
82
  }
83
83
 
84
- disablePutout(finalConfig);
84
+ !putout && disablePutout(finalConfig);
85
85
 
86
86
  // that's right, we disabled "putout" rules in "config"
87
87
  // and now it located in eslint's cache
package/lib/cli/index.js CHANGED
@@ -1,50 +1,39 @@
1
1
  'use strict';
2
2
 
3
- const {resolve} = require('path');
4
- const {readFileSync} = require('fs');
5
-
6
3
  const {red} = require('chalk');
7
4
  const yargsParser = require('yargs-parser');
8
5
  const {isCI} = require('ci-info');
9
6
  const memo = require('nano-memoize');
10
- const fullstore = require('fullstore');
11
7
  const tryCatch = require('try-catch');
12
- const tryToCatch = require('try-to-catch');
13
8
  const wraptile = require('wraptile');
9
+ const fullstore = require('fullstore');
10
+
11
+ const keyPress = require('@putout/cli-keypress');
14
12
  const {version} = require('../../package.json');
15
13
  const {simpleImport} = require('./simple-import');
16
-
17
- const {env} = process;
18
- const isIDE = /JetBrains/.test(env.TERMINAL_EMULATOR) || env.TERM_PROGRAM === 'vscode';
19
- const chooseName = (name, resolvedName) => !isIDE ? name : resolvedName;
14
+ const {run} = require('./runner/runner.js');
20
15
 
21
16
  const {
22
- runProcessors,
23
17
  getFilePatterns,
24
18
  getProcessorRunners,
25
19
  defaultProcessors,
26
20
  } = require('@putout/engine-processor');
27
21
 
28
22
  const merge = require('../merge');
29
- const ignores = require('../ignores');
30
23
 
31
- const initProcessFile = require('./process-file');
32
24
  const getFiles = require('./get-files');
33
25
  const {createCache} = require('@putout/cli-cache');
34
26
  const supportedFiles = require('./supported-files');
35
27
  const getFormatter = memo(require('./formatter').getFormatter);
36
28
  const getOptions = require('./get-options');
37
- const report = require('./report')();
38
- const keyPress = require('@putout/cli-keypress');
29
+
39
30
  const validateArgs = require('@putout/cli-validate-args');
40
- const parseError = require('./parse-error');
41
31
 
42
32
  const {
43
33
  OK,
44
34
  PLACE,
45
35
  STAGE,
46
36
  NO_FILES,
47
- NO_PROCESSORS,
48
37
  CANNOT_LOAD_PROCESSOR,
49
38
  WAS_STOP,
50
39
  INVALID_OPTION,
@@ -64,20 +53,6 @@ const getExitCode = (wasStop) => wasStop() ? WAS_STOP : OK;
64
53
 
65
54
  const isStr = (a) => typeof a === 'string';
66
55
  const {isArray} = Array;
67
- const isParser = (rule) => /^parser/.test(rule);
68
- const isParsingError = ({rule}) => isParser(rule);
69
-
70
- const createFormatterProxy = (options) => {
71
- return new Proxy(options, {
72
- get(target, name) {
73
- if (target[name])
74
- return target[name];
75
-
76
- if (name === 'source')
77
- return readFileSync(target.name, 'utf8');
78
- },
79
- });
80
- };
81
56
 
82
57
  module.exports = async ({argv, halt, log, write, logError, readFile, writeFile}) => {
83
58
  const {isStop} = keyPress();
@@ -299,114 +274,29 @@ module.exports = async ({argv, halt, log, write, logError, readFile, writeFile})
299
274
  plugins,
300
275
  };
301
276
 
302
- const rawPlaces = [];
277
+ const {rawPlaces, exited} = await run({
278
+ fix,
279
+ exit,
280
+ readFile,
281
+ writeFile,
282
+ raw,
283
+ rulesdir,
284
+ names,
285
+ options,
286
+ fileCache,
287
+ currentFormat,
288
+ formatterOptions,
289
+ write,
290
+ log,
291
+ isStop,
292
+ wasStop,
293
+ noConfig,
294
+ plugins,
295
+ transform,
296
+ });
303
297
 
304
- const processFile = initProcessFile(options);
305
- const {length} = names;
306
-
307
- for (let index = 0; index < length; index++) {
308
- if (wasStop())
309
- break;
310
-
311
- wasStop(isStop());
312
-
313
- const currentIndex = isStop() ? length - 1 : index;
314
- const name = names[index];
315
- const resolvedName = resolve(name)
316
- .replace(/^\./, cwd);
317
-
318
- const [configError, options] = tryCatch(getOptions, {
319
- name: resolvedName,
320
- rulesdir,
321
- noConfig,
322
- transform,
323
- plugins,
324
- });
325
-
326
- if (configError)
327
- return exit(INVALID_CONFIG, configError);
328
-
329
- const {dir} = options;
330
-
331
- if (fileCache.canUseCache(name, options)) {
332
- const places = fileCache.getPlaces(name);
333
- const formatterProxy = createFormatterProxy({
334
- report,
335
- formatterOptions,
336
- name: chooseName(name, resolvedName),
337
- places,
338
- index: currentIndex,
339
- count: length,
340
- });
341
-
342
- const line = await report(currentFormat, formatterProxy);
343
-
344
- write(line || '');
345
- rawPlaces.push(places);
346
- continue;
347
- }
348
-
349
- let isProcessed = true;
350
- let places = [];
351
- let rawSource = '';
352
- let processedSource = '';
353
-
354
- if (!ignores(dir, resolvedName, options)) {
355
- rawSource = await readFile(resolvedName, 'utf8');
356
-
357
- const [error, result] = await tryToCatch(runProcessors, {
358
- name: resolvedName,
359
- fix,
360
- processFile,
361
- options,
362
- rawSource,
363
- processorRunners,
364
- });
365
-
366
- if (error) {
367
- places = parseError(error);
368
-
369
- isProcessed = true;
370
- processedSource = rawSource;
371
-
372
- if (raw)
373
- log(error);
374
- } else {
375
- ({
376
- isProcessed,
377
- places,
378
- processedSource,
379
- } = result);
380
- }
381
- }
382
-
383
- const line = await report(currentFormat, {
384
- report,
385
- formatterOptions,
386
- name: chooseName(name, resolvedName),
387
- source: rawSource,
388
- places,
389
- index: currentIndex,
390
- count: length,
391
- });
392
-
393
- write(line || '');
394
-
395
- if (!isProcessed)
396
- return exit(NO_PROCESSORS, Error(`No processors found for ${name}`));
397
-
398
- if (rawSource !== processedSource) {
399
- fileCache.removeEntry(name);
400
- await writeFile(name, processedSource);
401
- }
402
-
403
- const fixable = !places.filter(isParsingError).length;
404
-
405
- if (fixable)
406
- fileCache.setInfo(name, places, options);
407
-
408
- rawPlaces.push(places);
409
- }
298
+ if (exited)
299
+ return;
410
300
 
411
301
  const mergedPlaces = merge(...rawPlaces);
412
302
 
@@ -445,6 +335,10 @@ const getExit = ({halt, raw, logError}) => (code, e) => {
445
335
 
446
336
  logError(message);
447
337
  halt(code);
338
+
339
+ return {
340
+ exited: true,
341
+ };
448
342
  };
449
343
 
450
344
  module.exports._addOnce = addOnce;
@@ -452,4 +346,3 @@ function addOnce(emitter, name, fn) {
452
346
  if (!emitter.listenerCount(name))
453
347
  emitter.on(name, fn);
454
348
  }
455
-
@@ -3,13 +3,12 @@
3
3
  const tryCatch = require('try-catch');
4
4
 
5
5
  const putout = require('../..');
6
+ const merge = require('../merge');
7
+ const parseMatch = require('../parse-options/parse-match');
6
8
 
7
9
  const eslint = require('./eslint');
8
10
  const parseError = require('./parse-error');
9
11
 
10
- const merge = require('../merge');
11
- const parseMatch = require('../parse-options/parse-match');
12
-
13
12
  const getMatchedOptions = (name, options) => {
14
13
  if (!name.includes('{'))
15
14
  return options;
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ const runWorker = require('./worker.js');
4
+ const initProcessFile = require('../process-file.js');
5
+ const Report = require('../report.js');
6
+
7
+ const report = Report();
8
+
9
+ module.exports.run = async ({transform, plugins, noConfig, readFile, writeFile, exit, isStop, wasStop, names, write, log, rulesdir, fix, processorRunners, fileCache, currentFormat, formatterOptions, options, raw}) => {
10
+ const processFile = initProcessFile(options);
11
+ const {length} = names;
12
+ const rawPlaces = [];
13
+
14
+ for (let index = 0; index < length; index++) {
15
+ if (wasStop())
16
+ break;
17
+
18
+ const {exited} = await runWorker({
19
+ readFile,
20
+ writeFile,
21
+ exit,
22
+ isStop,
23
+ wasStop,
24
+ fix,
25
+ processorRunners,
26
+ rulesdir,
27
+ currentFormat,
28
+ formatterOptions,
29
+ index,
30
+ names,
31
+ length,
32
+ rawPlaces,
33
+ processFile,
34
+ fileCache,
35
+ raw,
36
+ write,
37
+ log,
38
+ report,
39
+ noConfig,
40
+ plugins,
41
+ transform,
42
+ });
43
+
44
+ if (exited)
45
+ return {exited, rawPlaces};
46
+ }
47
+
48
+ return {rawPlaces};
49
+ };
@@ -0,0 +1,146 @@
1
+ 'use strict';
2
+
3
+ const {resolve} = require('path');
4
+ const {
5
+ cwd,
6
+ env,
7
+ } = require('process');
8
+ const tryCatch = require('try-catch');
9
+ const {readFileSync} = require('fs');
10
+ const tryToCatch = require('try-to-catch');
11
+ const {runProcessors} = require('@putout/engine-processor');
12
+
13
+ const parseError = require('../parse-error.js');
14
+ const getOptions = require('../get-options.js');
15
+ const {
16
+ INVALID_CONFIG,
17
+ NO_PROCESSORS,
18
+ } = require('../exit-codes.js');
19
+ const ignores = require('../../ignores.js');
20
+
21
+ const isParser = (rule) => /^parser/.test(rule);
22
+ const isParsingError = ({rule}) => isParser(rule);
23
+ const chooseName = (name, resolvedName) => !isIDE ? name : resolvedName;
24
+ const isIDE = /JetBrains/.test(env.TERMINAL_EMULATOR) || env.TERM_PROGRAM === 'vscode';
25
+
26
+ const createFormatterProxy = (options) => {
27
+ return new Proxy(options, {
28
+ get(target, name) {
29
+ if (target[name])
30
+ return target[name];
31
+
32
+ if (name === 'source')
33
+ return readFileSync(target.name, 'utf8');
34
+ },
35
+ });
36
+ };
37
+
38
+ module.exports = async ({readFile, report, writeFile, exit, raw, write, log, currentFormat, rulesdir, formatterOptions, noConfig, transform, plugins, index, fix, processFile, processorRunners, fileCache, rawPlaces, wasStop, isStop, names, length}) => {
39
+ wasStop(isStop());
40
+
41
+ const currentIndex = isStop() ? length - 1 : index;
42
+ const name = names[index];
43
+ const resolvedName = resolve(name)
44
+ .replace(/^\./, cwd);
45
+
46
+ const [configError, options] = tryCatch(getOptions, {
47
+ name: resolvedName,
48
+ rulesdir,
49
+ noConfig,
50
+ transform,
51
+ plugins,
52
+ });
53
+
54
+ if (configError)
55
+ return exit(INVALID_CONFIG, configError);
56
+
57
+ const {dir} = options;
58
+
59
+ if (fileCache.canUseCache(name, options)) {
60
+ const places = fileCache.getPlaces(name);
61
+ const formatterProxy = createFormatterProxy({
62
+ report,
63
+ formatterOptions,
64
+ name: chooseName(name, resolvedName),
65
+ places,
66
+ index: currentIndex,
67
+ count: length,
68
+ });
69
+
70
+ const line = await report(currentFormat, formatterProxy);
71
+
72
+ write(line || '');
73
+ rawPlaces.push(places);
74
+
75
+ return {
76
+ success: true,
77
+ };
78
+ }
79
+
80
+ let isProcessed = true;
81
+ let places = [];
82
+ let rawSource = '';
83
+ let processedSource = '';
84
+
85
+ if (!ignores(dir, resolvedName, options)) {
86
+ rawSource = await readFile(resolvedName, 'utf8');
87
+
88
+ const [error, result] = await tryToCatch(runProcessors, {
89
+ name: resolvedName,
90
+ fix,
91
+ processFile,
92
+ options,
93
+ rawSource,
94
+ processorRunners,
95
+ });
96
+
97
+ if (error) {
98
+ places = parseError(error);
99
+
100
+ isProcessed = true;
101
+ processedSource = rawSource;
102
+
103
+ if (raw)
104
+ log(error);
105
+ } else {
106
+ ({
107
+ isProcessed,
108
+ places,
109
+ processedSource,
110
+ } = result);
111
+ }
112
+ }
113
+
114
+ const line = await report(currentFormat, {
115
+ report,
116
+ formatterOptions,
117
+ name: chooseName(name, resolvedName),
118
+ source: rawSource,
119
+ places,
120
+ index: currentIndex,
121
+ count: length,
122
+ });
123
+
124
+ write(line || '');
125
+
126
+ if (!isProcessed)
127
+ return exit(NO_PROCESSORS, Error(`No processors found for ${name}`));
128
+
129
+ if (rawSource !== processedSource) {
130
+ fileCache.removeEntry(name);
131
+ await writeFile(name, processedSource);
132
+ }
133
+
134
+ const fixable = !places.filter(isParsingError).length;
135
+
136
+ if (fixable)
137
+ fileCache.setInfo(name, places, options);
138
+
139
+ rawPlaces.push(places);
140
+
141
+ return {
142
+ rawPlaces,
143
+ success: true,
144
+ };
145
+ };
146
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "putout",
3
- "version": "24.2.1",
3
+ "version": "24.5.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊 Pluggable and configurable code transformer with built-in eslint and babel plugins support of js, jsx typescript, flow files, markdown, yaml and json",
@@ -16,6 +16,7 @@
16
16
  "./process-file": "./lib/cli/process-file.js",
17
17
  "./exit-codes": "./lib/cli/exit-codes.mjs",
18
18
  "./cli": "./lib/cli/index.js",
19
+ "./cli/run": "./lib/cli/runner/work",
19
20
  "./loader": "./lib/loader.mjs",
20
21
  "./eslint": "./lib/cli/eslint/index.js",
21
22
  "./package.json": "./package.json"
@@ -51,7 +52,7 @@
51
52
  "@putout/cli-match": "^1.0.0",
52
53
  "@putout/cli-ruler": "^2.0.0",
53
54
  "@putout/cli-validate-args": "^1.0.0",
54
- "@putout/compare": "^8.0.0",
55
+ "@putout/compare": "^8.7.0",
55
56
  "@putout/engine-loader": "^5.0.0",
56
57
  "@putout/engine-parser": "^4.0.0",
57
58
  "@putout/engine-processor": "^4.0.0",
@@ -86,7 +87,7 @@
86
87
  "@putout/plugin-convert-comparison-to-boolean": "^2.0.0",
87
88
  "@putout/plugin-convert-concat-to-flat": "^1.0.0",
88
89
  "@putout/plugin-convert-equal-to-strict-equal": "^1.0.0",
89
- "@putout/plugin-convert-esm-to-commonjs": "^3.0.0",
90
+ "@putout/plugin-convert-esm-to-commonjs": "^4.0.0",
90
91
  "@putout/plugin-convert-for-each-to-for-of": "^7.0.0",
91
92
  "@putout/plugin-convert-for-in-to-for-of": "^2.0.0",
92
93
  "@putout/plugin-convert-for-to-for-of": "^3.0.0",
@@ -158,7 +159,7 @@
158
159
  "@putout/plugin-simplify-ternary": "^2.0.0",
159
160
  "@putout/plugin-split-nested-destructuring": "^1.0.0",
160
161
  "@putout/plugin-split-variable-declarations": "^2.0.0",
161
- "@putout/plugin-strict-mode": "^2.0.0",
162
+ "@putout/plugin-strict-mode": "^3.0.0",
162
163
  "@putout/plugin-tape": "^8.0.0",
163
164
  "@putout/plugin-typescript": "^1.0.0",
164
165
  "@putout/plugin-webpack": "^1.0.0",