@putout/plugin-remove-duplicate-keys 7.0.0 → 8.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/lib/remove-duplicate-keys.js +16 -20
- package/package.json +9 -11
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import {types, operator} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {types, operator} = require('putout');
|
|
4
|
-
const fullstore = require('fullstore');
|
|
5
3
|
const {
|
|
6
4
|
compare,
|
|
7
5
|
traverseProperties,
|
|
@@ -15,6 +13,7 @@ const {
|
|
|
15
13
|
isObjectProperty,
|
|
16
14
|
isStringLiteral,
|
|
17
15
|
isObjectPattern,
|
|
16
|
+
isCallExpression,
|
|
18
17
|
} = types;
|
|
19
18
|
|
|
20
19
|
const isSpreadId = (name) => (a) => isSpreadElement(a) && isIdentifier(a.argument, {
|
|
@@ -35,24 +34,17 @@ const isObjectPropertyLiteral = (value) => (a) => isObjectProperty(a) && isStrin
|
|
|
35
34
|
value,
|
|
36
35
|
});
|
|
37
36
|
|
|
38
|
-
const
|
|
37
|
+
export const report = () => 'Avoid duplicate keys';
|
|
39
38
|
|
|
40
|
-
|
|
39
|
+
export const fix = ({path, newProperties}) => {
|
|
40
|
+
path.node.properties = newProperties;
|
|
41
|
+
};
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
__object: (
|
|
44
|
-
__object.properties = store();
|
|
45
|
-
store([]);
|
|
46
|
-
|
|
47
|
-
return __object;
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
module.exports.match = () => ({
|
|
52
|
-
__object: ({__object}, path) => {
|
|
43
|
+
export const traverse = ({push}) => ({
|
|
44
|
+
__object: (path) => {
|
|
53
45
|
let is = false;
|
|
54
46
|
const newProperties = [];
|
|
55
|
-
const {properties} =
|
|
47
|
+
const {properties} = path.node;
|
|
56
48
|
|
|
57
49
|
const reversed = properties
|
|
58
50
|
.slice()
|
|
@@ -103,6 +95,9 @@ module.exports.match = () => ({
|
|
|
103
95
|
}
|
|
104
96
|
|
|
105
97
|
if (isObjectProperty(prop) && isMemberExpression(prop.key)) {
|
|
98
|
+
if (isCallExpression(prop.key.object))
|
|
99
|
+
continue;
|
|
100
|
+
|
|
106
101
|
const {computed} = prop;
|
|
107
102
|
const name = extract(prop.key);
|
|
108
103
|
|
|
@@ -126,9 +121,10 @@ module.exports.match = () => ({
|
|
|
126
121
|
}
|
|
127
122
|
|
|
128
123
|
if (is)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
124
|
+
push({
|
|
125
|
+
path,
|
|
126
|
+
newProperties,
|
|
127
|
+
});
|
|
132
128
|
},
|
|
133
129
|
});
|
|
134
130
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-remove-duplicate-keys",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "8.1.0",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout plugin adds ability to find and remove duplicate keys",
|
|
7
7
|
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-duplicate-keys#readme",
|
|
@@ -23,9 +23,7 @@
|
|
|
23
23
|
"coverage": "madrun coverage",
|
|
24
24
|
"report": "madrun report"
|
|
25
25
|
},
|
|
26
|
-
"dependencies": {
|
|
27
|
-
"fullstore": "^3.0.0"
|
|
28
|
-
},
|
|
26
|
+
"dependencies": {},
|
|
29
27
|
"keywords": [
|
|
30
28
|
"putout",
|
|
31
29
|
"putout-plugin",
|
|
@@ -35,21 +33,21 @@
|
|
|
35
33
|
"key"
|
|
36
34
|
],
|
|
37
35
|
"devDependencies": {
|
|
38
|
-
"@putout/eslint-flat": "^
|
|
39
|
-
"@putout/test": "^
|
|
36
|
+
"@putout/eslint-flat": "^3.0.0",
|
|
37
|
+
"@putout/test": "^14.0.0",
|
|
40
38
|
"c8": "^10.0.0",
|
|
41
39
|
"eslint": "^9.0.0",
|
|
42
40
|
"eslint-plugin-n": "^17.0.0",
|
|
43
|
-
"eslint-plugin-putout": "^
|
|
44
|
-
"madrun": "^
|
|
41
|
+
"eslint-plugin-putout": "^28.0.0",
|
|
42
|
+
"madrun": "^11.0.0",
|
|
45
43
|
"nodemon": "^3.0.1"
|
|
46
44
|
},
|
|
47
45
|
"peerDependencies": {
|
|
48
|
-
"putout": ">=
|
|
46
|
+
"putout": ">=40"
|
|
49
47
|
},
|
|
50
48
|
"license": "MIT",
|
|
51
49
|
"engines": {
|
|
52
|
-
"node": ">=
|
|
50
|
+
"node": ">=20"
|
|
53
51
|
},
|
|
54
52
|
"publishConfig": {
|
|
55
53
|
"access": "public"
|