putout 22.1.0 → 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 CHANGED
@@ -1,3 +1,59 @@
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
+
10
+ 2021.11.28, v22.2.1
11
+
12
+ fix:
13
+ - (@putout/plugin-remove-constant-conditions) report: "constant condtions should not be used" -> "Avoid constant conditions"
14
+
15
+ feature:
16
+ - (package) @putout/plugin-madrun v11.0.0
17
+ - (putout) improve ability to test from IDE
18
+ - (@putout/plugin-madrun) drop support of putout < 22
19
+ - (@putout/plugin-madrun) add declare
20
+ - (eslint-plugin-putout) putout: add ability to preserve comments places
21
+
22
+
23
+ 2021.11.27, v22.2.0
24
+
25
+ fix:
26
+ - (@putout/plugin-remove-unused-variables) OptionalMemberExpression: computed property
27
+ - (eslint-plugin-putout) array-element-newline: minimum elements: 4 -> 5
28
+ - (eslint-plugin-putout) add-newlinew-before-function-call: trimed whitespaces on empty line
29
+ - (eslint-plugin-putout) add-newline-before-function-call: add support of comments
30
+ - (eslint-plugin-putout) add-newline-before-function-call: continue -> return
31
+
32
+ feature:
33
+ - (package) @putout/plugin-remove-constant-conditions v3.0.0
34
+ - (@putout/plugin-remove-constant-conditions) drop support of node < 14
35
+ - (@putout/plugin-remove-constant-conditions) add support of consequent not body
36
+ - (eslint-plugin-putout) safe: disable remove-unreachable-code
37
+ - (@putout/plugin-remove-unused-variables) improve support of OptionalMemberExpression
38
+ - (eslint-plugin-putout) add-newline-after-function-call: add support of ArrayExpression and ObjectExpression
39
+ - (eslint-plugin-putout) add add-newline-after-function-call
40
+ - (@putout/eslint-config) padding-line-between-statements: add support of while
41
+ - (eslint-plugin-putout) add add-newline-before-function-call
42
+ - (@putout/eslint-config) add func-call-spacing (https://eslint.org/docs/rules/func-call-spacing)
43
+ - (eslint-plugin-putout) plugin-tape-remove-newline-before-t-end: add support of trimed newline
44
+ - (eslint-plugin-putout) add add-newline-before-t-end
45
+ - (@putout/plugin-declare-undefined-variables) add maybeEmptyArray
46
+ - (eslint-plugin-putout) array-element-newline: add support of Identifier
47
+ - (@putout/eslint-config) padding-line-between-statements: add newline between for and return
48
+ - (@putout/plugin-remove-useless-spread) add support of logical expressions
49
+
50
+
51
+ 2021.11.21, v22.1.1
52
+
53
+ feature:
54
+ - (package) yargs-parser v21.0.0
55
+
56
+
1
57
  2021.11.21, v22.1.0
2
58
 
3
59
  fix:
@@ -6,7 +62,7 @@ fix:
6
62
 
7
63
  feature:
8
64
  - (putout) *.md: disable convert-quotes-to-backticks
9
- - (@putout/plugin-convert-quotes-to-backtics) add suport of newlines
65
+ - (@putout/plugin-convert-quotes-to-backtics) add support of newlines
10
66
  - (eslint-plugin-putout) objects-braces-inside-array: enable for json, disable for yaml
11
67
 
12
68
 
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ![putout](https://github.com/coderaiser/putout/blob/master/images/putout-logo.svg)
11
11
 
12
- 🐊[`Putout`](https://github.com/coderaiser/putout) find and fix problems in your `JavaScript`, `JSX`, `Typescript`, `Flow`, `Yaml, `Json` and `Markdown`. It can:
12
+ 🐊[`Putout`](https://github.com/coderaiser/putout) find and fix problems in your `JavaScript`, `JSX`, `Typescript`, `Flow`, `Yaml, `Json`and`Markdown`. It can:
13
13
 
14
14
  - remove unused `variables`;
15
15
  - remove unused `for-of variables`;
@@ -192,7 +192,7 @@ When you need to ignore some routes no metter what, you can use `ignore` section
192
192
 
193
193
  🐊`Putout` supports `plugins`, there is two types: with prefix official `@putout/plugin-` and user plugins with prefix `putout-plugin-`. To use your plugin create plugin as `npm` package with keywords `putout`, `putout-plugin` and add it to `.putout.json`.
194
194
 
195
- For example if you need to `remove-something` create `putout` plugin with name `putout-plugin-remove-something` and it to `package.json`:
195
+ For example if you need to `remove-something` create 🐊[`Putout`](https://github.com/coderaiser/putout) plugin with name `putout-plugin-remove-something` and it to `package.json`:
196
196
 
197
197
  ```json
198
198
  {
@@ -13,5 +13,6 @@ module.exports = {
13
13
  UNHANDLED: 9,
14
14
  RULLER_WITH_FIX: 10,
15
15
  RULLER_NO_FILES: 11,
16
+ INVALID_CONFIG: 12,
16
17
  };
17
18
 
@@ -10,4 +10,4 @@ export const CANNOT_LOAD_PROCESSOR = 8;
10
10
  export const UNHANDLED = 9;
11
11
  export const RULLER_WITH_FIX = 10;
12
12
  export const RULLER_NO_FILES = 11;
13
-
13
+ export const INVALID_CONFIG = 12;
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,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.1.0",
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",
@@ -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": "^10.0.0",
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",
@@ -122,7 +122,7 @@
122
122
  "@putout/plugin-remove-boolean-from-assertions": "^1.0.0",
123
123
  "@putout/plugin-remove-boolean-from-logical-expressions": "^4.0.0",
124
124
  "@putout/plugin-remove-console": "^3.0.0",
125
- "@putout/plugin-remove-constant-conditions": "^2.0.0",
125
+ "@putout/plugin-remove-constant-conditions": "^3.0.0",
126
126
  "@putout/plugin-remove-debugger": "^4.0.0",
127
127
  "@putout/plugin-remove-duplicate-case": "^1.0.0",
128
128
  "@putout/plugin-remove-duplicate-interface-keys": "^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",
@@ -196,7 +197,7 @@
196
197
  "try-catch": "^3.0.0",
197
198
  "try-to-catch": "^3.0.0",
198
199
  "wraptile": "^3.0.0",
199
- "yargs-parser": "^20.0.0"
200
+ "yargs-parser": "^21.0.0"
200
201
  },
201
202
  "keywords": [
202
203
  "ast",
package/putout.json CHANGED
@@ -108,9 +108,6 @@
108
108
  "**/build",
109
109
  "**/package-lock.json"
110
110
  ],
111
- "exclude": [
112
- ".md"
113
- ],
114
111
  "rules": {
115
112
  "apply-array-at": "off",
116
113
  "apply-as-type-assertions": "off",