putout 22.2.1 → 22.3.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 +9 -0
- package/lib/cli/exit-codes.js +1 -0
- package/lib/cli/exit-codes.mjs +1 -1
- package/lib/cli/index.js +15 -6
- package/lib/parse-options/index.js +3 -0
- package/lib/parse-options/validate-options/index.js +42 -0
- package/lib/parse-options/validate-options/schema.json +33 -0
- package/package.json +2 -1
- package/putout.json +0 -3
package/ChangeLog
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
2021.11.30, v22.3.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- (putout) add config validation
|
|
5
|
+
- (@putout/plugin-remove-empty-pattern) improve support of nested destructuring
|
|
6
|
+
- (@putout/plugin-tape) add-stop-all: add support of mockRequire
|
|
7
|
+
- (@putout/plugin-remove-unused-variables) improve support of nested destructuring
|
|
8
|
+
|
|
9
|
+
|
|
1
10
|
2021.11.28, v22.2.1
|
|
2
11
|
|
|
3
12
|
fix:
|
package/lib/cli/exit-codes.js
CHANGED
package/lib/cli/exit-codes.mjs
CHANGED
package/lib/cli/index.js
CHANGED
|
@@ -53,6 +53,7 @@ const {
|
|
|
53
53
|
UNHANDLED,
|
|
54
54
|
RULLER_WITH_FIX,
|
|
55
55
|
RULLER_NO_FILES,
|
|
56
|
+
INVALID_CONFIG,
|
|
56
57
|
} = require('./exit-codes');
|
|
57
58
|
|
|
58
59
|
const cwd = process.cwd();
|
|
@@ -217,11 +218,7 @@ module.exports = async ({argv, halt, log, write, logError, readFile, writeFile})
|
|
|
217
218
|
}
|
|
218
219
|
|
|
219
220
|
const noConfig = !args.config;
|
|
220
|
-
const {
|
|
221
|
-
formatter,
|
|
222
|
-
ignore,
|
|
223
|
-
processors = defaultProcessors,
|
|
224
|
-
} = getOptions({
|
|
221
|
+
const [configError, config] = tryCatch(getOptions, {
|
|
225
222
|
name: `${cwd}/*`,
|
|
226
223
|
rulesdir,
|
|
227
224
|
noConfig,
|
|
@@ -229,6 +226,15 @@ module.exports = async ({argv, halt, log, write, logError, readFile, writeFile})
|
|
|
229
226
|
plugins,
|
|
230
227
|
});
|
|
231
228
|
|
|
229
|
+
if (configError)
|
|
230
|
+
return exit(INVALID_CONFIG, configError);
|
|
231
|
+
|
|
232
|
+
const {
|
|
233
|
+
formatter,
|
|
234
|
+
ignore,
|
|
235
|
+
processors = defaultProcessors,
|
|
236
|
+
} = config;
|
|
237
|
+
|
|
232
238
|
const [currentFormat, formatterOptions] = getFormatter(format || formatter, exit);
|
|
233
239
|
const [error, processorRunners] = tryCatch(getProcessorRunners, processors);
|
|
234
240
|
|
|
@@ -311,7 +317,7 @@ module.exports = async ({argv, halt, log, write, logError, readFile, writeFile})
|
|
|
311
317
|
const resolvedName = resolve(name)
|
|
312
318
|
.replace(/^\./, cwd);
|
|
313
319
|
|
|
314
|
-
const options = getOptions
|
|
320
|
+
const [configError, options] = tryCatch(getOptions, {
|
|
315
321
|
name: resolvedName,
|
|
316
322
|
rulesdir,
|
|
317
323
|
noConfig,
|
|
@@ -319,6 +325,9 @@ module.exports = async ({argv, halt, log, write, logError, readFile, writeFile})
|
|
|
319
325
|
plugins,
|
|
320
326
|
});
|
|
321
327
|
|
|
328
|
+
if (configError)
|
|
329
|
+
return exit(INVALID_CONFIG, configError);
|
|
330
|
+
|
|
322
331
|
const {dir} = options;
|
|
323
332
|
|
|
324
333
|
if (fileCache.canUseCache(name, options)) {
|
|
@@ -16,6 +16,7 @@ const defaultOptions = require('../../putout.json');
|
|
|
16
16
|
const merge = require('../merge');
|
|
17
17
|
const recursiveRead = require('./recursive-read');
|
|
18
18
|
const applyModuleTypeRules = require('./apply-module-type-rules');
|
|
19
|
+
const {validateOptions} = require('./validate-options');
|
|
19
20
|
|
|
20
21
|
const home = homedir();
|
|
21
22
|
|
|
@@ -62,6 +63,8 @@ module.exports = (info = {}) => {
|
|
|
62
63
|
mergedMatch,
|
|
63
64
|
);
|
|
64
65
|
|
|
66
|
+
validateOptions(resultOptions);
|
|
67
|
+
|
|
65
68
|
return {
|
|
66
69
|
...resultOptions,
|
|
67
70
|
dir,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Ajv = require('ajv');
|
|
4
|
+
const schema = require('./schema.json');
|
|
5
|
+
|
|
6
|
+
const ajv = new Ajv({
|
|
7
|
+
strict: true,
|
|
8
|
+
allowUnionTypes: true,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const validate = ajv.compile(schema);
|
|
12
|
+
|
|
13
|
+
module.exports.validateOptions = (options) => {
|
|
14
|
+
validate(options);
|
|
15
|
+
|
|
16
|
+
const [error] = validate.errors || [];
|
|
17
|
+
|
|
18
|
+
if (error)
|
|
19
|
+
throw Error(`.putout.json: ${parsePath(error)}${parseAdditional(error)}${parseMessage(error)}`);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function parseMessage(error) {
|
|
23
|
+
return error.message.replace(',', ' or ');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const parseAdditional = (error) => {
|
|
27
|
+
const {additionalProperty} = error.params;
|
|
28
|
+
|
|
29
|
+
if (!additionalProperty)
|
|
30
|
+
return '';
|
|
31
|
+
|
|
32
|
+
return `${additionalProperty}: `;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const parsePath = (error) => {
|
|
36
|
+
const {instancePath} = error;
|
|
37
|
+
|
|
38
|
+
if (!instancePath)
|
|
39
|
+
return '';
|
|
40
|
+
|
|
41
|
+
return `${error.instancePath.slice(1)}: `;
|
|
42
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"additionalProperties": false,
|
|
5
|
+
"properties": {
|
|
6
|
+
"parser": {
|
|
7
|
+
"type": "string"
|
|
8
|
+
},
|
|
9
|
+
"formatter": {
|
|
10
|
+
"type": ["string", "array"]
|
|
11
|
+
},
|
|
12
|
+
"processors": {
|
|
13
|
+
"type": "array",
|
|
14
|
+
"uniqueItems": true
|
|
15
|
+
},
|
|
16
|
+
"ignore": {
|
|
17
|
+
"type": "array",
|
|
18
|
+
"uniqueItems": true
|
|
19
|
+
},
|
|
20
|
+
"match": {
|
|
21
|
+
"type": "object"
|
|
22
|
+
},
|
|
23
|
+
"plugins": {
|
|
24
|
+
"description": "List of plugins to load",
|
|
25
|
+
"type": "array",
|
|
26
|
+
"uniqueItems": true
|
|
27
|
+
},
|
|
28
|
+
"rules": {
|
|
29
|
+
"description": "Names list of rules",
|
|
30
|
+
"type": "object"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "putout",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.3.0",
|
|
4
4
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
5
5
|
"description": "🐊 Pluggable and configurable code transformer with built-in eslint, babel plugins and jscodeshift codemods support of js, jsx typescript, flow files, markdown, yaml and json",
|
|
6
6
|
"homepage": "http://github.com/coderaiser/putout",
|
|
@@ -178,6 +178,7 @@
|
|
|
178
178
|
"@putout/processor-markdown": "^5.0.0",
|
|
179
179
|
"@putout/processor-yaml": "^3.0.0",
|
|
180
180
|
"@putout/traverse": "^4.0.0",
|
|
181
|
+
"ajv": "^8.8.2",
|
|
181
182
|
"chalk": "^4.0.0",
|
|
182
183
|
"ci-info": "^3.1.1",
|
|
183
184
|
"debug": "^4.1.1",
|