@putout/plugin-package-json 10.0.0 → 10.1.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
@@ -18,6 +18,7 @@ npm i @putout/plugin-package-json -D
18
18
  - ✅ [find-file](#find-file);
19
19
  - ✅ [remove-nyc](#remove-nyc);
20
20
  - ✅ [remove-commit-type](#remove-commit-type);
21
+ - ✅ [remove-imports-nesting](#remove-imports-nesting);
21
22
  - ✅ [remove-duplicate-keywords](#remove-duplicate-keywords);
22
23
  - ✅ [remove-exports-with-missing-files](#remove-exports-with-missing-files);
23
24
 
@@ -30,6 +31,7 @@ npm i @putout/plugin-package-json -D
30
31
  "package-json/apply-https-to-repository-url": "on",
31
32
  "package-json/remove-nyc": "on",
32
33
  "package-json/remove-commit-type": "on",
34
+ "package-json/remove-imports-nesting": "on",
33
35
  "package-json/remove-exports-with-missing-files": "off",
34
36
  "package-json/find-file": "off"
35
37
  }
@@ -130,7 +132,7 @@ Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/eb12c902c
130
132
  Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/eb12c902c8e99effc91ae44119d625d7/8e60d60b2c2e7bb28ca5b2eba61715a062ac5319).
131
133
 
132
134
  ```diff
133
- __putout_processor_json({
135
+ {
134
136
  "keywords": [
135
137
  "putout",
136
138
  "putout-plugin",
@@ -138,7 +140,35 @@ __putout_processor_json({
138
140
  - "putout"
139
141
  + "plugin"
140
142
  ],
141
- });
143
+ }
144
+ ```
145
+
146
+ ## remove-imports-nesting
147
+
148
+ Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/3527617ece2bfd9c39875db50a8a6245/2f3c6248b7b0ab539212b747f3cd480dc77ce3f1).
149
+
150
+ ```diff
151
+ {
152
+ "imports": {
153
+ - "#get-imports": {
154
+ - "default": "./lib/shorten-imported-file/get-imports/index.js"
155
+ - }
156
+ + "#get-imports": "./lib/shorten-imported-file/get-imports/index.js"
157
+ }
158
+ }
159
+ ```
160
+
161
+ ## find-file
162
+
163
+ Find `package.json` inside of `.filesystem.json` and applies all other `package-json` rules.
164
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/325233d19fde0acacadbcf1f42dd3bb2/124a50fe0e92c6c3cab24f8b87c33b202dc3e540).
165
+
166
+ ```diff
167
+ {
168
+ "name": "hello",
169
+ "version": "1.0.0",
170
+ + "type": "commonjs"
171
+ }
142
172
  ```
143
173
 
144
174
  ## find-file
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import * as removeImportsNesting from './remove-imports-nesting/index.js';
1
2
  import {rules as packageJson} from './package-json.js';
2
3
  import * as findFile from './find-file/index.js';
3
4
  import * as removeExportsWithMissingFiles from './remove-exports-with-missing-files/index.js';
@@ -8,4 +9,5 @@ export const rules = {
8
9
  'find-file': ['off', findFile],
9
10
  'remove-exports-with-missing-files': ['off', removeExportsWithMissingFiles],
10
11
  'remove-duplicate-keywords': removeDuplicateKeywords,
12
+ 'remove-imports-nesting': removeImportsNesting,
11
13
  };
@@ -0,0 +1,40 @@
1
+ import {operator, types} from 'putout';
2
+
3
+ const {isObjectExpression} = types;
4
+ const {
5
+ getProperties,
6
+ __json,
7
+ replaceWith,
8
+ } = operator;
9
+
10
+ export const report = (path) => {
11
+ const {value: property} = path.get('value.properties.0.key').node;
12
+ const {value} = path.get('key').node;
13
+
14
+ return `Avoid nesting import '${value}' with single property: '${property}'`;
15
+ };
16
+
17
+ export const fix = (path) => {
18
+ const value = path.get('value');
19
+ replaceWith(value, value.get('properties.0.value'));
20
+ };
21
+
22
+ export const traverse = ({push}) => ({
23
+ [__json]: (path) => {
24
+ const __aPath = path.get('arguments.0');
25
+ const {importsPath} = getProperties(__aPath, ['imports']);
26
+
27
+ if (!importsPath)
28
+ return;
29
+
30
+ for (const property of importsPath.get('value.properties')) {
31
+ const {value} = property.node;
32
+
33
+ if (!isObjectExpression(value))
34
+ continue;
35
+
36
+ if (value.properties.length === 1)
37
+ push(property);
38
+ }
39
+ },
40
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-package-json",
3
- "version": "10.0.0",
3
+ "version": "10.1.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin for package.json",