@putout/plugin-putout-config 1.2.2 β†’ 3.0.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/README.md CHANGED
@@ -1,11 +1,9 @@
1
- # @putout/plugin-putout-config [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL]
1
+ # @putout/plugin-putout-config [![NPM version][NPMIMGURL]][NPMURL]
2
2
 
3
3
  [NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-putout-config.svg?style=flat&longCache=true
4
4
  [NPMURL]: https://npmjs.org/package/@putout/plugin-putout-config"npm"
5
- [DependencyStatusURL]: https://david-dm.org/coderaiser/putout?path=packages/plugin-putout-config
6
- [DependencyStatusIMGURL]: https://david-dm.org/coderaiser/putout.svg?path=packages/plugin-putout-config
7
5
 
8
- `putout` plugin helps with `putout` plugins development.
6
+ 🐊[**Putout**](https://github.com/coderaiser/putout) plugin helps with 🐊[**Putout Config**](https://github.com/coderaiser/putout#-configuration).
9
7
 
10
8
  ## Install
11
9
 
@@ -26,7 +24,7 @@ npm i @putout/plugin-putout-config -D
26
24
 
27
25
  ## convert-boolean-to-string
28
26
 
29
- ### ❌ Incorrect code example
27
+ ### ❌ Example of incorrect code
30
28
 
31
29
  ```json
32
30
  {
@@ -37,7 +35,7 @@ npm i @putout/plugin-putout-config -D
37
35
  }
38
36
  ```
39
37
 
40
- ### βœ… Correct code Example
38
+ ### βœ… Example of correct code
41
39
 
42
40
  ```json
43
41
  {
@@ -50,7 +48,7 @@ npm i @putout/plugin-putout-config -D
50
48
 
51
49
  ## remove-empty
52
50
 
53
- ### ❌ Incorrect code example
51
+ ### ❌ Example of incorrect code
54
52
 
55
53
  ```json
56
54
  {
@@ -64,7 +62,7 @@ npm i @putout/plugin-putout-config -D
64
62
  }
65
63
  ```
66
64
 
67
- ### βœ… Correct code Example
65
+ ### βœ… Example of correct code
68
66
 
69
67
  ```json
70
68
  {
@@ -6,7 +6,6 @@ const {
6
6
  } = require('putout');
7
7
 
8
8
  const {replaceWith} = operator;
9
-
10
9
  const {StringLiteral} = types;
11
10
 
12
11
  module.exports.report = () => 'String should be used instead of Boolean';
@@ -18,4 +17,52 @@ module.exports.fix = (path) => {
18
17
  replaceWith(path, newValue);
19
18
  };
20
19
 
21
- module.exports.include = () => ['BooleanLiteral'];
20
+ module.exports.traverse = ({push}) => ({
21
+ '__putout_processor_json(__a)'(path) {
22
+ const objectPath = path.get('arguments.0');
23
+
24
+ const propPaths = [
25
+ ...getProperties('rules', objectPath),
26
+ ...getMatchProperties(objectPath),
27
+ ];
28
+
29
+ for (const propPath of propPaths) {
30
+ const valuePath = propPath.get('value');
31
+
32
+ if (valuePath.isBooleanLiteral()) {
33
+ push(valuePath);
34
+ continue;
35
+ }
36
+
37
+ if (valuePath.isArrayExpression()) {
38
+ const firstPath = valuePath.get('elements.0');
39
+
40
+ if (firstPath.isBooleanLiteral())
41
+ push(firstPath);
42
+
43
+ continue;
44
+ }
45
+ }
46
+ },
47
+ });
48
+
49
+ function getProperties(name, objectPath) {
50
+ for (const propPath of objectPath.get('properties')) {
51
+ const keyPath = propPath.get('key');
52
+
53
+ if (keyPath.node.value === name)
54
+ return propPath.get('value.properties');
55
+ }
56
+
57
+ return [];
58
+ }
59
+
60
+ function getMatchProperties(objectPath) {
61
+ const result = [];
62
+
63
+ for (const propPath of getProperties('match', objectPath)) {
64
+ result.push(...propPath.get('value.properties'));
65
+ }
66
+
67
+ return result;
68
+ }
package/lib/index.js CHANGED
@@ -8,4 +8,3 @@ module.exports.rules = {
8
8
  ...getRule('convert-boolean-to-string'),
9
9
  ...getRule('remove-empty'),
10
10
  };
11
-
@@ -6,10 +6,19 @@ module.exports.fix = (path) => {
6
6
  path.parentPath.remove();
7
7
  };
8
8
 
9
- module.exports.include = () => ['ObjectExpression', 'ArrayExpression'];
9
+ module.exports.include = () => [
10
+ 'ObjectExpression',
11
+ 'ArrayExpression',
12
+ ];
10
13
  module.exports.filter = (path) => {
11
- const {parentPath, node} = path;
12
- const {properties, elements} = node;
14
+ const {
15
+ parentPath,
16
+ node,
17
+ } = path;
18
+ const {
19
+ properties,
20
+ elements,
21
+ } = node;
13
22
 
14
23
  if (!parentPath.isObjectProperty())
15
24
  return false;
@@ -24,4 +33,3 @@ module.exports.filter = (path) => {
24
33
 
25
34
  return !elements.length;
26
35
  };
27
-
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout-config",
3
- "version": "1.2.2",
3
+ "version": "3.0.0",
4
+ "type": "commonjs",
4
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
5
- "description": "putout plugin helps to maintain putout config",
6
+ "description": "🐊Putout plugin helps to maintain putout config",
6
7
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-putout-config#readme",
7
8
  "main": "lib/index.js",
8
9
  "release": false,
@@ -31,21 +32,21 @@
31
32
  "config"
32
33
  ],
33
34
  "devDependencies": {
34
- "@putout/test": "^3.0.0",
35
+ "@putout/test": "^6.0.0",
35
36
  "c8": "^7.5.0",
36
- "eslint": "^8.0.0-beta.0",
37
- "eslint-plugin-node": "^11.0.0",
38
- "eslint-plugin-putout": "^9.0.0",
39
- "lerna": "^4.0.0",
40
- "madrun": "^8.0.1",
37
+ "eslint": "^8.0.1",
38
+ "eslint-plugin-n": "^16.0.0",
39
+ "eslint-plugin-putout": "^17.0.0",
40
+ "lerna": "^6.0.1",
41
+ "madrun": "^9.0.0",
41
42
  "nodemon": "^2.0.1"
42
43
  },
43
44
  "peerDependencies": {
44
- "putout": ">=12"
45
+ "putout": ">=29"
45
46
  },
46
47
  "license": "MIT",
47
48
  "engines": {
48
- "node": ">=12"
49
+ "node": ">=16"
49
50
  },
50
51
  "publishConfig": {
51
52
  "access": "public"