@putout/plugin-remove-duplicate-keys 8.1.0 → 9.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,7 +1,7 @@
1
1
  # @putout/plugin-remove-duplicate-keys [![NPM version][NPMIMGURL]][NPMURL]
2
2
 
3
3
  [NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-remove-duplicate-keys.svg?style=flat&longCache=true
4
- [NPMURL]: https://npmjs.org/package/@putout/plugin-remove-duplicate-keys"npm"
4
+ [NPMURL]: https://npmjs.org/package/@putout/plugin-remove-duplicate-keys "npm"
5
5
 
6
6
  > An object initializer is a comma-delimited list of zero or more pairs of property names and associated values of an object, enclosed in curly braces (`{}`).
7
7
  >
@@ -20,11 +20,14 @@ const isSpreadId = (name) => (a) => isSpreadElement(a) && isIdentifier(a.argumen
20
20
  name,
21
21
  });
22
22
 
23
- const isObjectPropertyId = (name, computed) => (a) => isObjectProperty(a, {
24
- computed,
25
- }) && isIdentifier(a.key, {
26
- name,
27
- });
23
+ const isObjectPropertyId = (name, computed) => (a) => {
24
+ if (!isObjectProperty(a, {computed}))
25
+ return false;
26
+
27
+ return isIdentifier(a.key, {
28
+ name,
29
+ });
30
+ };
28
31
 
29
32
  const isMemberExpressionId = (name, computed) => (a) => isObjectProperty(a, {
30
33
  computed,
@@ -34,7 +37,19 @@ const isObjectPropertyLiteral = (value) => (a) => isObjectProperty(a) && isStrin
34
37
  value,
35
38
  });
36
39
 
37
- export const report = () => 'Avoid duplicate keys';
40
+ const addQuote = (a) => `'${a}'`;
41
+
42
+ export const report = ({names}) => {
43
+ const {length} = names;
44
+ const quotedNames = names
45
+ .reverse()
46
+ .map(addQuote)
47
+ .join(', ');
48
+
49
+ const suffix = !length ? '' : `: ${quotedNames}`;
50
+
51
+ return `Avoid duplicate keys${suffix}`;
52
+ };
38
53
 
39
54
  export const fix = ({path, newProperties}) => {
40
55
  path.node.properties = newProperties;
@@ -50,6 +65,8 @@ export const traverse = ({push}) => ({
50
65
  .slice()
51
66
  .reverse();
52
67
 
68
+ const names = [];
69
+
53
70
  for (const prop of reversed) {
54
71
  if (isObjectPattern(path) && !compare(prop.key, prop.value))
55
72
  continue;
@@ -79,6 +96,7 @@ export const traverse = ({push}) => ({
79
96
 
80
97
  if (!isFirst) {
81
98
  is = true;
99
+ names.push(name);
82
100
  continue;
83
101
  }
84
102
  }
@@ -90,6 +108,7 @@ export const traverse = ({push}) => ({
90
108
 
91
109
  if (!isFirst) {
92
110
  is = true;
111
+ names.push(value);
93
112
  continue;
94
113
  }
95
114
  }
@@ -123,6 +142,7 @@ export const traverse = ({push}) => ({
123
142
  if (is)
124
143
  push({
125
144
  path,
145
+ names,
126
146
  newProperties,
127
147
  });
128
148
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-remove-duplicate-keys",
3
- "version": "8.1.0",
3
+ "version": "9.0.0",
4
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",
@@ -33,21 +33,20 @@
33
33
  "key"
34
34
  ],
35
35
  "devDependencies": {
36
- "@putout/eslint-flat": "^3.0.0",
37
- "@putout/test": "^14.0.0",
36
+ "@putout/test": "^15.0.0",
38
37
  "c8": "^10.0.0",
39
- "eslint": "^9.0.0",
38
+ "eslint": "^10.0.0",
40
39
  "eslint-plugin-n": "^17.0.0",
41
- "eslint-plugin-putout": "^28.0.0",
42
- "madrun": "^11.0.0",
40
+ "eslint-plugin-putout": "^31.0.0",
41
+ "madrun": "^13.0.0",
43
42
  "nodemon": "^3.0.1"
44
43
  },
45
44
  "peerDependencies": {
46
- "putout": ">=40"
45
+ "putout": ">=42"
47
46
  },
48
47
  "license": "MIT",
49
48
  "engines": {
50
- "node": ">=20"
49
+ "node": ">=22"
51
50
  },
52
51
  "publishConfig": {
53
52
  "access": "public"