@putout/plugin-package-json 8.3.0 → 9.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-duplicate-keywords](#remove-duplicate-keywords);
|
|
21
22
|
- ✅ [remove-exports-with-missing-files](#remove-exports-with-missing-files);
|
|
22
23
|
|
|
23
24
|
## Config
|
|
@@ -124,6 +125,22 @@ Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/eb12c902c
|
|
|
124
125
|
}
|
|
125
126
|
```
|
|
126
127
|
|
|
128
|
+
## remove-duplicate-keywords
|
|
129
|
+
|
|
130
|
+
Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/eb12c902c8e99effc91ae44119d625d7/8e60d60b2c2e7bb28ca5b2eba61715a062ac5319).
|
|
131
|
+
|
|
132
|
+
```diff
|
|
133
|
+
__putout_processor_json({
|
|
134
|
+
"keywords": [
|
|
135
|
+
"putout",
|
|
136
|
+
"putout-plugin",
|
|
137
|
+
- "plugin",
|
|
138
|
+
- "putout"
|
|
139
|
+
+ "plugin"
|
|
140
|
+
],
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
127
144
|
## find-file
|
|
128
145
|
|
|
129
146
|
Find `package.json` inside of `.filesystem.json` and applies all other `package-json` rules.
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {rules as packageJson} from './package-json.js';
|
|
2
2
|
import * as findFile from './find-file/index.js';
|
|
3
3
|
import * as removeExportsWithMissingFiles from './remove-exports-with-missing-files/index.js';
|
|
4
|
+
import * as removeDuplicateKeywords from './remove-duplicate-keywords/index.js';
|
|
4
5
|
|
|
5
6
|
export const rules = {
|
|
6
7
|
...packageJson,
|
|
7
8
|
'find-file': ['off', findFile],
|
|
8
9
|
'remove-exports-with-missing-files': ['off', removeExportsWithMissingFiles],
|
|
10
|
+
'remove-duplicate-keywords': removeDuplicateKeywords,
|
|
9
11
|
};
|
package/lib/package-json.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as addType from './add-type/index.js';
|
|
2
2
|
import * as removeNyc from './remove-nyc/index.js';
|
|
3
3
|
import * as removeCommitType from './remove-commit-type/index.js';
|
|
4
|
-
import * as
|
|
4
|
+
import * as applyHttpsToRepositoryUrl from './appy-https-to-repository-url/index.js';
|
|
5
5
|
|
|
6
6
|
export const rules = {
|
|
7
7
|
'add-type': addType,
|
|
8
8
|
'remove-nyc': removeNyc,
|
|
9
9
|
'remove-commit-type': removeCommitType,
|
|
10
|
-
'
|
|
10
|
+
'apply-https-to-repository-url': applyHttpsToRepositoryUrl,
|
|
11
11
|
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {operator} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
getProperties,
|
|
5
|
+
__json,
|
|
6
|
+
remove,
|
|
7
|
+
} = operator;
|
|
8
|
+
|
|
9
|
+
export const report = () => `Remove duplicate keywords`;
|
|
10
|
+
|
|
11
|
+
export const fix = (path) => {
|
|
12
|
+
remove(path);
|
|
13
|
+
};
|
|
14
|
+
export const traverse = ({push}) => ({
|
|
15
|
+
[__json](path) {
|
|
16
|
+
const objectPath = path.get('arguments.0');
|
|
17
|
+
const {keywordsPath} = getProperties(objectPath, ['keywords']);
|
|
18
|
+
|
|
19
|
+
if (!keywordsPath)
|
|
20
|
+
return;
|
|
21
|
+
|
|
22
|
+
const arrayPath = keywordsPath.get('value');
|
|
23
|
+
|
|
24
|
+
if (!arrayPath.node.elements.length)
|
|
25
|
+
return;
|
|
26
|
+
|
|
27
|
+
let first = arrayPath.get('elements.0');
|
|
28
|
+
let second = arrayPath.get('elements.1');
|
|
29
|
+
|
|
30
|
+
do {
|
|
31
|
+
do {
|
|
32
|
+
if (!second)
|
|
33
|
+
break;
|
|
34
|
+
|
|
35
|
+
if (first.node.value === second.node.value)
|
|
36
|
+
push(second);
|
|
37
|
+
} while (second = next(second));
|
|
38
|
+
} while (first = next(first));
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
function next(path) {
|
|
43
|
+
path = path.getNextSibling();
|
|
44
|
+
|
|
45
|
+
if (path.node)
|
|
46
|
+
return path;
|
|
47
|
+
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
@@ -48,8 +48,20 @@ function processNested({push, keyPath, valuePath}) {
|
|
|
48
48
|
const root = keyPath.node.value;
|
|
49
49
|
|
|
50
50
|
for (const property of valuePath.get('properties')) {
|
|
51
|
-
const
|
|
52
|
-
const
|
|
51
|
+
const valuePath = property.get('value');
|
|
52
|
+
const keyPath = property.get('key');
|
|
53
|
+
|
|
54
|
+
if (valuePath.isObjectExpression()) {
|
|
55
|
+
processNested({
|
|
56
|
+
push,
|
|
57
|
+
keyPath,
|
|
58
|
+
valuePath,
|
|
59
|
+
});
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const key = `${root}+${keyPath.node.value}`;
|
|
64
|
+
const {value} = valuePath.node;
|
|
53
65
|
|
|
54
66
|
push({
|
|
55
67
|
key,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-package-json",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.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",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"nodemon": "^3.0.1"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"putout": ">=
|
|
44
|
+
"putout": ">=37"
|
|
45
45
|
},
|
|
46
46
|
"license": "MIT",
|
|
47
47
|
"engines": {
|