putout 22.2.0 → 22.3.2
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 +36 -0
- package/lib/cli/exit-codes.js +1 -0
- package/lib/cli/exit-codes.mjs +1 -1
- package/lib/cli/index.js +16 -7
- 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 +72 -0
- package/package.json +3 -2
- package/putout.json +0 -3
package/ChangeLog
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
+
2021.11.30, v22.3.2
|
|
2
|
+
|
|
3
|
+
fix:
|
|
4
|
+
- (putout) validate-options: rm rule names: has no sense for validation as any rule provided by plugin supported
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
2021.11.30, v22.3.1
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- validate-options: improve support of rules, match
|
|
11
|
+
- (putout) validate-options: improve validations: ignore, processors
|
|
12
|
+
- (putout) validate-options: add descriptions
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
2021.11.30, v22.3.0
|
|
16
|
+
|
|
17
|
+
feature:
|
|
18
|
+
- (putout) add config validation
|
|
19
|
+
- (@putout/plugin-remove-empty-pattern) improve support of nested destructuring
|
|
20
|
+
- (@putout/plugin-tape) add-stop-all: add support of mockRequire
|
|
21
|
+
- (@putout/plugin-remove-unused-variables) improve support of nested destructuring
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
2021.11.28, v22.2.1
|
|
25
|
+
|
|
26
|
+
fix:
|
|
27
|
+
- (@putout/plugin-remove-constant-conditions) report: "constant condtions should not be used" -> "Avoid constant conditions"
|
|
28
|
+
|
|
29
|
+
feature:
|
|
30
|
+
- (package) @putout/plugin-madrun v11.0.0
|
|
31
|
+
- (putout) improve ability to test from IDE
|
|
32
|
+
- (@putout/plugin-madrun) drop support of putout < 22
|
|
33
|
+
- (@putout/plugin-madrun) add declare
|
|
34
|
+
- (eslint-plugin-putout) putout: add ability to preserve comments places
|
|
35
|
+
|
|
36
|
+
|
|
1
37
|
2021.11.27, v22.2.0
|
|
2
38
|
|
|
3
39
|
fix:
|
package/lib/cli/exit-codes.js
CHANGED
package/lib/cli/exit-codes.mjs
CHANGED
package/lib/cli/index.js
CHANGED
|
@@ -17,7 +17,7 @@ const {version} = require('../../package.json');
|
|
|
17
17
|
const simport = createSimport(__filename);
|
|
18
18
|
|
|
19
19
|
const {env} = process;
|
|
20
|
-
const isIDE = env.TERMINAL_EMULATOR || env.TERM_PROGRAM === 'vscode';
|
|
20
|
+
const isIDE = /JetBrains/.test(env.TERMINAL_EMULATOR) || env.TERM_PROGRAM === 'vscode';
|
|
21
21
|
const chooseName = (name, resolvedName) => !isIDE ? name : resolvedName;
|
|
22
22
|
|
|
23
23
|
const {
|
|
@@ -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,72 @@
|
|
|
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
|
+
},
|
|
21
|
+
"rules": {
|
|
22
|
+
"description": "🐊Putout comes with a large number of rules. You can modify which rules your project uses.",
|
|
23
|
+
"type": "object",
|
|
24
|
+
"patternProperties": {
|
|
25
|
+
"^.*$": {
|
|
26
|
+
"$ref": "#/definitions/rule"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"properties": {
|
|
32
|
+
"parser": {
|
|
33
|
+
"description": "Tell 🐊Putout which parser to use",
|
|
34
|
+
"type": "string"
|
|
35
|
+
},
|
|
36
|
+
"formatter": {
|
|
37
|
+
"description": "Choose the way to show information about errors found",
|
|
38
|
+
"type": ["string", "array"]
|
|
39
|
+
},
|
|
40
|
+
"processors": {
|
|
41
|
+
"description": "Tell 🐊Putout which processors to use to support file types other then JavaScript",
|
|
42
|
+
"type": "array",
|
|
43
|
+
"uniqueItems": true,
|
|
44
|
+
"items": {
|
|
45
|
+
"type": "string"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"ignore": {
|
|
49
|
+
"description": "Tell 🐊Putout to ignore specific files and directories.",
|
|
50
|
+
"type": "array",
|
|
51
|
+
"uniqueItems": true,
|
|
52
|
+
"items": {
|
|
53
|
+
"type": "string"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"match": {
|
|
57
|
+
"description": "Allows to match rules for files and folders, specified by glob patterns.",
|
|
58
|
+
"type": "object",
|
|
59
|
+
"patternProperties": {
|
|
60
|
+
"^.*$": {
|
|
61
|
+
"$ref": "#/definitions/rules"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"plugins": {
|
|
66
|
+
"description": "Tell 🐊Putout which plugins to load",
|
|
67
|
+
"type": "array",
|
|
68
|
+
"uniqueItems": true
|
|
69
|
+
},
|
|
70
|
+
"rules": {"$ref": "#/definitions/rules"}
|
|
71
|
+
}
|
|
72
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "putout",
|
|
3
|
-
"version": "22.2
|
|
3
|
+
"version": "22.3.2",
|
|
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",
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
"@putout/plugin-extract-sequence-expressions": "^2.0.0",
|
|
109
109
|
"@putout/plugin-github": "^2.0.0",
|
|
110
110
|
"@putout/plugin-gitignore": "^3.0.0",
|
|
111
|
-
"@putout/plugin-madrun": "^
|
|
111
|
+
"@putout/plugin-madrun": "^11.0.0",
|
|
112
112
|
"@putout/plugin-merge-destructuring-properties": "^5.0.0",
|
|
113
113
|
"@putout/plugin-merge-duplicate-imports": "^4.0.0",
|
|
114
114
|
"@putout/plugin-merge-if-statements": "^3.0.0",
|
|
@@ -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",
|