@putout/plugin-remove-duplicate-keys 6.0.0 → 8.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 +11 -0
- package/lib/remove-duplicate-keys.js +21 -29
- package/package.json +10 -12
package/README.md
CHANGED
|
@@ -44,6 +44,17 @@ const a = {
|
|
|
44
44
|
};
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
+
> SyntaxError: Duplicate parameter name not allowed in this context
|
|
48
|
+
>
|
|
49
|
+
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Duplicate_parameter)
|
|
50
|
+
|
|
51
|
+
Argument name clash:
|
|
52
|
+
|
|
53
|
+
```diff
|
|
54
|
+
-const a = ({b, b, ...c}) => {};
|
|
55
|
+
+const a = ({b, ...c}) => {};
|
|
56
|
+
```
|
|
57
|
+
|
|
47
58
|
## License
|
|
48
59
|
|
|
49
60
|
MIT
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import {types, operator} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
|
|
3
|
+
const {
|
|
4
|
+
compare,
|
|
5
|
+
traverseProperties,
|
|
6
|
+
extract,
|
|
7
|
+
} = operator;
|
|
5
8
|
|
|
6
9
|
const {
|
|
7
10
|
isSpreadElement,
|
|
8
11
|
isIdentifier,
|
|
9
12
|
isMemberExpression,
|
|
10
13
|
isObjectProperty,
|
|
11
|
-
isObjectPattern,
|
|
12
14
|
isStringLiteral,
|
|
15
|
+
isObjectPattern,
|
|
13
16
|
} = types;
|
|
14
17
|
|
|
15
|
-
const {
|
|
16
|
-
traverseProperties,
|
|
17
|
-
extract,
|
|
18
|
-
} = operator;
|
|
19
|
-
|
|
20
18
|
const isSpreadId = (name) => (a) => isSpreadElement(a) && isIdentifier(a.argument, {
|
|
21
19
|
name,
|
|
22
20
|
});
|
|
@@ -35,33 +33,26 @@ const isObjectPropertyLiteral = (value) => (a) => isObjectProperty(a) && isStrin
|
|
|
35
33
|
value,
|
|
36
34
|
});
|
|
37
35
|
|
|
38
|
-
const
|
|
36
|
+
export const report = () => 'Avoid duplicate keys';
|
|
39
37
|
|
|
40
|
-
|
|
38
|
+
export const fix = ({path, newProperties}) => {
|
|
39
|
+
path.node.properties = newProperties;
|
|
40
|
+
};
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
__object: (
|
|
44
|
-
__object.properties = store();
|
|
45
|
-
store([]);
|
|
46
|
-
|
|
47
|
-
return __object;
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
module.exports.match = () => ({
|
|
52
|
-
__object: ({__object}, path) => {
|
|
42
|
+
export const traverse = ({push}) => ({
|
|
43
|
+
__object: (path) => {
|
|
53
44
|
let is = false;
|
|
54
45
|
const newProperties = [];
|
|
55
|
-
const {properties} =
|
|
56
|
-
|
|
57
|
-
if (isObjectPattern(__object))
|
|
58
|
-
return false;
|
|
46
|
+
const {properties} = path.node;
|
|
59
47
|
|
|
60
48
|
const reversed = properties
|
|
61
49
|
.slice()
|
|
62
50
|
.reverse();
|
|
63
51
|
|
|
64
52
|
for (const prop of reversed) {
|
|
53
|
+
if (isObjectPattern(path) && !compare(prop.key, prop.value))
|
|
54
|
+
continue;
|
|
55
|
+
|
|
65
56
|
if (isSpreadElement(prop) && isIdentifier(prop.argument)) {
|
|
66
57
|
const {name} = prop.argument;
|
|
67
58
|
const isFirst = checkIfFirst(properties, newProperties, isSpreadId, name);
|
|
@@ -126,9 +117,10 @@ module.exports.match = () => ({
|
|
|
126
117
|
}
|
|
127
118
|
|
|
128
119
|
if (is)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
120
|
+
push({
|
|
121
|
+
path,
|
|
122
|
+
newProperties,
|
|
123
|
+
});
|
|
132
124
|
},
|
|
133
125
|
});
|
|
134
126
|
|
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.0.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,10 +23,8 @@
|
|
|
23
23
|
"coverage": "madrun coverage",
|
|
24
24
|
"report": "madrun report"
|
|
25
25
|
},
|
|
26
|
-
"dependencies": {
|
|
27
|
-
|
|
28
|
-
},
|
|
29
|
-
"keyswords": [
|
|
26
|
+
"dependencies": {},
|
|
27
|
+
"keywords": [
|
|
30
28
|
"putout",
|
|
31
29
|
"putout-plugin",
|
|
32
30
|
"putout-plugin-remove",
|
|
@@ -35,21 +33,21 @@
|
|
|
35
33
|
"key"
|
|
36
34
|
],
|
|
37
35
|
"devDependencies": {
|
|
38
|
-
"@putout/
|
|
36
|
+
"@putout/eslint-flat": "^3.0.0",
|
|
37
|
+
"@putout/test": "^13.0.0",
|
|
39
38
|
"c8": "^10.0.0",
|
|
40
39
|
"eslint": "^9.0.0",
|
|
41
40
|
"eslint-plugin-n": "^17.0.0",
|
|
42
|
-
"eslint-plugin-putout": "^
|
|
43
|
-
"
|
|
44
|
-
"madrun": "^10.0.0",
|
|
41
|
+
"eslint-plugin-putout": "^27.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"
|