putout 22.2.1 → 22.3.3
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 +29 -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 +51 -0
- package/lib/parse-options/validate-options/schema.json +92 -0
- package/package.json +2 -1
- package/putout.json +0 -3
package/ChangeLog
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
+
2021.11.30, v22.3.3
|
|
2
|
+
|
|
3
|
+
fix:
|
|
4
|
+
- (putout) validate-options: add support of optional message
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
2021.11.30, v22.3.2
|
|
8
|
+
|
|
9
|
+
fix:
|
|
10
|
+
- (putout) validate-options: rm rule names: has no sense for validation as any rule provided by plugin supported
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
2021.11.30, v22.3.1
|
|
14
|
+
|
|
15
|
+
feature:
|
|
16
|
+
- validate-options: improve support of rules, match
|
|
17
|
+
- (putout) validate-options: improve validations: ignore, processors
|
|
18
|
+
- (putout) validate-options: add descriptions
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
2021.11.30, v22.3.0
|
|
22
|
+
|
|
23
|
+
feature:
|
|
24
|
+
- (putout) add config validation
|
|
25
|
+
- (@putout/plugin-remove-empty-pattern) improve support of nested destructuring
|
|
26
|
+
- (@putout/plugin-tape) add-stop-all: add support of mockRequire
|
|
27
|
+
- (@putout/plugin-remove-unused-variables) improve support of nested destructuring
|
|
28
|
+
|
|
29
|
+
|
|
1
30
|
2021.11.28, v22.2.1
|
|
2
31
|
|
|
3
32
|
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,51 @@
|
|
|
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)}${parseAllowed(error)}`);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function parseAllowed(error) {
|
|
23
|
+
const {allowedValues} = error.params;
|
|
24
|
+
|
|
25
|
+
if (!allowedValues)
|
|
26
|
+
return '';
|
|
27
|
+
|
|
28
|
+
return ` (${allowedValues.join('/')})`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function parseMessage(error) {
|
|
32
|
+
return error.message.replace(',', ' or ');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const parseAdditional = (error) => {
|
|
36
|
+
const {additionalProperty} = error.params;
|
|
37
|
+
|
|
38
|
+
if (!additionalProperty)
|
|
39
|
+
return '';
|
|
40
|
+
|
|
41
|
+
return `${additionalProperty}: `;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const parsePath = (error) => {
|
|
45
|
+
const {instancePath} = error;
|
|
46
|
+
|
|
47
|
+
if (!instancePath)
|
|
48
|
+
return '';
|
|
49
|
+
|
|
50
|
+
return `${error.instancePath.slice(1)}: `;
|
|
51
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"additionalProperties": false,
|
|
5
|
+
"definitions": {
|
|
6
|
+
"rule": {
|
|
7
|
+
"oneOf": [{
|
|
8
|
+
"description": "🐊Putout rule\n\n\"off\" means rule is off\n\"on\" means it is a on\n",
|
|
9
|
+
"enum": [ "on", "off"]
|
|
10
|
+
}, {
|
|
11
|
+
"type": "array",
|
|
12
|
+
"items": [{
|
|
13
|
+
"enum": [ "on", "off"]
|
|
14
|
+
}, {
|
|
15
|
+
"type": "object"
|
|
16
|
+
}],
|
|
17
|
+
"minItems": 2,
|
|
18
|
+
"additionalItems": false
|
|
19
|
+
}, {
|
|
20
|
+
"type": "array",
|
|
21
|
+
"items": [{
|
|
22
|
+
"enum": [ "on", "off"]
|
|
23
|
+
}, {
|
|
24
|
+
"type": "string"
|
|
25
|
+
}, {
|
|
26
|
+
"type": "object"
|
|
27
|
+
}],
|
|
28
|
+
"minItems": 3,
|
|
29
|
+
"additionalItems": false
|
|
30
|
+
}, {
|
|
31
|
+
"type": "array",
|
|
32
|
+
"items": [{
|
|
33
|
+
"enum": [ "on", "off"]
|
|
34
|
+
}, {
|
|
35
|
+
"type": "string"
|
|
36
|
+
}],
|
|
37
|
+
"minItems": 2,
|
|
38
|
+
"additionalItems": false
|
|
39
|
+
}]
|
|
40
|
+
},
|
|
41
|
+
"rules": {
|
|
42
|
+
"description": "🐊Putout comes with a large number of rules. You can modify which rules your project uses.",
|
|
43
|
+
"type": "object",
|
|
44
|
+
"patternProperties": {
|
|
45
|
+
"^.*$": {
|
|
46
|
+
"$ref": "#/definitions/rule"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"properties": {
|
|
52
|
+
"parser": {
|
|
53
|
+
"description": "Tell 🐊Putout which parser to use",
|
|
54
|
+
"type": "string"
|
|
55
|
+
},
|
|
56
|
+
"formatter": {
|
|
57
|
+
"description": "Choose the way to show information about errors found",
|
|
58
|
+
"type": ["string", "array"]
|
|
59
|
+
},
|
|
60
|
+
"processors": {
|
|
61
|
+
"description": "Tell 🐊Putout which processors to use to support file types other then JavaScript",
|
|
62
|
+
"type": "array",
|
|
63
|
+
"uniqueItems": true,
|
|
64
|
+
"items": {
|
|
65
|
+
"type": "string"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"ignore": {
|
|
69
|
+
"description": "Tell 🐊Putout to ignore specific files and directories.",
|
|
70
|
+
"type": "array",
|
|
71
|
+
"uniqueItems": true,
|
|
72
|
+
"items": {
|
|
73
|
+
"type": "string"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"match": {
|
|
77
|
+
"description": "Allows to match rules for files and folders, specified by glob patterns.",
|
|
78
|
+
"type": "object",
|
|
79
|
+
"patternProperties": {
|
|
80
|
+
"^.*$": {
|
|
81
|
+
"$ref": "#/definitions/rules"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"plugins": {
|
|
86
|
+
"description": "Tell 🐊Putout which plugins to load",
|
|
87
|
+
"type": "array",
|
|
88
|
+
"uniqueItems": true
|
|
89
|
+
},
|
|
90
|
+
"rules": {"$ref": "#/definitions/rules"}
|
|
91
|
+
}
|
|
92
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "putout",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.3.3",
|
|
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",
|