@putout/plugin-remove-duplicate-keys 8.1.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
@@ -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,21 +20,19 @@ 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
- });
28
-
29
- const isMemberExpressionId = (name, computed) => (a) => isObjectProperty(a, {
30
- computed,
31
- }) && name === extract(a.key);
32
-
33
23
  const isObjectPropertyLiteral = (value) => (a) => isObjectProperty(a) && isStringLiteral(a.key, {
34
24
  value,
35
25
  });
36
26
 
37
- export const report = () => 'Avoid duplicate keys';
27
+ const addQuote = (a) => `'${a}'`;
28
+
29
+ export const report = ({names}) => {
30
+ const quotedNames = names
31
+ .map(addQuote)
32
+ .join(', ');
33
+
34
+ return `Avoid duplicate keys: ${quotedNames}`;
35
+ };
38
36
 
39
37
  export const fix = ({path, newProperties}) => {
40
38
  path.node.properties = newProperties;
@@ -50,6 +48,8 @@ export const traverse = ({push}) => ({
50
48
  .slice()
51
49
  .reverse();
52
50
 
51
+ const names = [];
52
+
53
53
  for (const prop of reversed) {
54
54
  if (isObjectPattern(path) && !compare(prop.key, prop.value))
55
55
  continue;
@@ -60,6 +60,7 @@ export const traverse = ({push}) => ({
60
60
 
61
61
  if (!isFirst) {
62
62
  is = true;
63
+ names.unshift(name);
63
64
  continue;
64
65
  }
65
66
  }
@@ -79,6 +80,7 @@ export const traverse = ({push}) => ({
79
80
 
80
81
  if (!isFirst) {
81
82
  is = true;
83
+ names.unshift(name);
82
84
  continue;
83
85
  }
84
86
  }
@@ -90,6 +92,7 @@ export const traverse = ({push}) => ({
90
92
 
91
93
  if (!isFirst) {
92
94
  is = true;
95
+ names.unshift(value);
93
96
  continue;
94
97
  }
95
98
  }
@@ -112,6 +115,7 @@ export const traverse = ({push}) => ({
112
115
 
113
116
  if (!isFirst) {
114
117
  is = true;
118
+ names.unshift(name);
115
119
  continue;
116
120
  }
117
121
  }
@@ -123,6 +127,7 @@ export const traverse = ({push}) => ({
123
127
  if (is)
124
128
  push({
125
129
  path,
130
+ names,
126
131
  newProperties,
127
132
  });
128
133
  },
@@ -134,3 +139,19 @@ function checkIfFirst(properties, newProperties, isFn, str, {computed} = {}) {
134
139
 
135
140
  return !newLength || oldLength <= 1;
136
141
  }
142
+
143
+ const isObjectPropertyId = (name, computed) => (a) => {
144
+ if (!isObjectProperty(a, {computed}))
145
+ return false;
146
+
147
+ return isIdentifier(a.key, {
148
+ name,
149
+ });
150
+ };
151
+
152
+ const isMemberExpressionId = (name, computed) => (a) => {
153
+ if (!isObjectProperty(a, {computed}))
154
+ return false;
155
+
156
+ return name === extract(a.key);
157
+ };
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.1.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"