putout 32.10.1 → 32.12.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,16 @@
1
+ 2023.11.01, v32.12.0
2
+
3
+ fix:
4
+ - 2a2fe438c putout: chooseFormatter: drop erro handling
5
+
6
+ feature:
7
+ - 9637661a8 putout: exit codes: INTERACTIVE_CANCELED: add
8
+
9
+ 2023.10.31, v32.11.0
10
+
11
+ feature:
12
+ - 2b1600e6b putout: -i: add support of interactive configuration of linting
13
+
1
14
  2023.10.30, v32.10.1
2
15
 
3
16
  feature:
package/README.md CHANGED
@@ -166,6 +166,7 @@ Options:
166
166
  -v, --version output version information and exit
167
167
  -f, --format [formatter] use a specific output format, the default is: 'progress-bar' locally and 'dump' on CI
168
168
  -s, --staged add staged files when in git repository
169
+ -i, --interactive set lint options using interactive menu
169
170
  --fix apply fixes of errors to code
170
171
  --fix-count [count = 10] count of fixes rounds
171
172
  --rulesdir use additional rules from directory
package/help.json CHANGED
@@ -3,6 +3,7 @@
3
3
  "-v, --version ": "output version information and exit",
4
4
  "-f, --format [formatter] ": "use a specific output format, the default is: 'progress-bar' locally and 'dump' on CI",
5
5
  "-s, --staged ": "add staged files when in git repository",
6
+ "-i, --interactive ": "set lint options using interactive menu",
6
7
  "--fix ": "apply fixes of errors to code",
7
8
  "--fix-count [count = 10] ": "count of fixes rounds",
8
9
  "--rulesdir ": "use additional rules from directory",
@@ -16,4 +16,5 @@ module.exports = {
16
16
  INVALID_CONFIG: 12,
17
17
  UNHANDLED: 13,
18
18
  CANNOT_LINT_STAGED: 14,
19
+ INTERACTIVE_CANCELED: 15,
19
20
  };
@@ -13,3 +13,4 @@ export const RULLER_NO_FILES = 11;
13
13
  export const INVALID_CONFIG = 12;
14
14
  export const UNHANDLED = 13;
15
15
  export const CANNOT_LINT_STAGED = 14;
16
+ export const INTERACTIVE_CANCELED = 15;
@@ -0,0 +1,31 @@
1
+ import {choose as customChoose} from '@putout/cli-choose';
2
+ import {readFile as customReadFile} from 'node:fs/promises';
3
+
4
+ const {keys} = Object;
5
+ const {parse} = JSON;
6
+ const PREFIX = '@putout/formatter-';
7
+
8
+ const infoPath = new URL('../../../package.json', import.meta.url).pathname;
9
+
10
+ export const chooseFormatter = async ({readFile = customReadFile, choose = customChoose} = {}) => {
11
+ const data = await readFile(infoPath, 'utf8');
12
+ const parsed = parse(data);
13
+
14
+ const formatters = getFormatters(parsed);
15
+
16
+ return await choose('Choose formatter', formatters);
17
+ };
18
+
19
+ function getFormatters({dependencies}) {
20
+ const formatters = [];
21
+
22
+ for (const name of keys(dependencies)) {
23
+ if (!name.startsWith(PREFIX))
24
+ continue;
25
+
26
+ const shortName = name.replace(PREFIX, '');
27
+ formatters.push(shortName);
28
+ }
29
+
30
+ return formatters;
31
+ }
@@ -2,12 +2,12 @@
2
2
 
3
3
  const tryToCatch = require('try-to-catch');
4
4
  const {createAsyncLoader} = require('@putout/engine-loader');
5
- const {simpleImport} = require('./simple-import');
5
+ const {simpleImport} = require('../simple-import');
6
6
 
7
7
  const {
8
8
  NO_FORMATTER,
9
9
  CANNOT_LOAD_FORMATTER,
10
- } = require('./exit-codes');
10
+ } = require('../exit-codes');
11
11
 
12
12
  const {isArray} = Array;
13
13
  const maybeArray = (a) => isArray(a) ? a : [a, {}];
package/lib/cli/index.js CHANGED
@@ -41,10 +41,11 @@ const {
41
41
  RULLER_NO_FILES,
42
42
  INVALID_CONFIG,
43
43
  CANNOT_LINT_STAGED,
44
+ INTERACTIVE_CANCELED,
44
45
  } = require('./exit-codes');
45
46
 
46
47
  const {isSupported} = supportedFiles;
47
- const getFormatter = nanomemoize(require('./formatter').getFormatter);
48
+ const getFormatter = nanomemoize(require('./formatter/formatter').getFormatter);
48
49
 
49
50
  const cwd = process.cwd();
50
51
  const {PUTOUT_FILES = '', PUTOUT_PRINTER} = process.env;
@@ -83,6 +84,7 @@ module.exports = async ({argv, halt, log, write, logError, readFile, writeFile})
83
84
  'flow',
84
85
  'config',
85
86
  'staged',
87
+ 'interactive',
86
88
  ],
87
89
  number: ['fix-count'],
88
90
  string: [
@@ -100,6 +102,7 @@ module.exports = async ({argv, halt, log, write, logError, readFile, writeFile})
100
102
  format: 'f',
101
103
  staged: 's',
102
104
  transform: 't',
105
+ interactive: 'i',
103
106
  },
104
107
  default: {
105
108
  ci: true,
@@ -168,6 +171,17 @@ module.exports = async ({argv, halt, log, write, logError, readFile, writeFile})
168
171
  return exit();
169
172
  }
170
173
 
174
+ let newFormatter;
175
+
176
+ if (args.interactive) {
177
+ const {chooseFormatter} = await simpleImport('./formatter/choose-formatter.mjs');
178
+
179
+ newFormatter = await chooseFormatter();
180
+
181
+ if (!newFormatter)
182
+ return exit(INTERACTIVE_CANCELED);
183
+ }
184
+
171
185
  if (args.help) {
172
186
  const help = require('./help');
173
187
  log(help());
@@ -221,7 +235,7 @@ module.exports = async ({argv, halt, log, write, logError, readFile, writeFile})
221
235
  processors = defaultProcessors,
222
236
  } = config;
223
237
 
224
- const [currentFormat, formatterOptions] = await getFormatter(format || formatter, exit);
238
+ const [currentFormat, formatterOptions] = await getFormatter(newFormatter || format || formatter, exit);
225
239
  const [error, processorRunners] = await tryToCatch(getProcessorRunners, processors, simpleImport);
226
240
 
227
241
  if (error)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "putout",
3
- "version": "32.10.1",
3
+ "version": "32.12.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, Babel and support of js, jsx, typescript, flow, markdown, yaml and json",
@@ -45,6 +45,7 @@
45
45
  "dependencies": {
46
46
  "@putout/babel": "^1.0.0",
47
47
  "@putout/cli-cache": "^2.0.1",
48
+ "@putout/cli-choose": "^1.0.0",
48
49
  "@putout/cli-keypress": "^2.0.0",
49
50
  "@putout/cli-match": "^2.0.0",
50
51
  "@putout/cli-ruler": "^3.0.0",