@putout/plugin-remove-duplicate-keys 8.0.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
  >
@@ -13,17 +13,21 @@ const {
13
13
  isObjectProperty,
14
14
  isStringLiteral,
15
15
  isObjectPattern,
16
+ isCallExpression,
16
17
  } = types;
17
18
 
18
19
  const isSpreadId = (name) => (a) => isSpreadElement(a) && isIdentifier(a.argument, {
19
20
  name,
20
21
  });
21
22
 
22
- const isObjectPropertyId = (name, computed) => (a) => isObjectProperty(a, {
23
- computed,
24
- }) && isIdentifier(a.key, {
25
- name,
26
- });
23
+ const isObjectPropertyId = (name, computed) => (a) => {
24
+ if (!isObjectProperty(a, {computed}))
25
+ return false;
26
+
27
+ return isIdentifier(a.key, {
28
+ name,
29
+ });
30
+ };
27
31
 
28
32
  const isMemberExpressionId = (name, computed) => (a) => isObjectProperty(a, {
29
33
  computed,
@@ -33,7 +37,19 @@ const isObjectPropertyLiteral = (value) => (a) => isObjectProperty(a) && isStrin
33
37
  value,
34
38
  });
35
39
 
36
- 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
+ };
37
53
 
38
54
  export const fix = ({path, newProperties}) => {
39
55
  path.node.properties = newProperties;
@@ -49,6 +65,8 @@ export const traverse = ({push}) => ({
49
65
  .slice()
50
66
  .reverse();
51
67
 
68
+ const names = [];
69
+
52
70
  for (const prop of reversed) {
53
71
  if (isObjectPattern(path) && !compare(prop.key, prop.value))
54
72
  continue;
@@ -78,6 +96,7 @@ export const traverse = ({push}) => ({
78
96
 
79
97
  if (!isFirst) {
80
98
  is = true;
99
+ names.push(name);
81
100
  continue;
82
101
  }
83
102
  }
@@ -89,11 +108,15 @@ export const traverse = ({push}) => ({
89
108
 
90
109
  if (!isFirst) {
91
110
  is = true;
111
+ names.push(value);
92
112
  continue;
93
113
  }
94
114
  }
95
115
 
96
116
  if (isObjectProperty(prop) && isMemberExpression(prop.key)) {
117
+ if (isCallExpression(prop.key.object))
118
+ continue;
119
+
97
120
  const {computed} = prop;
98
121
  const name = extract(prop.key);
99
122
 
@@ -119,6 +142,7 @@ export const traverse = ({push}) => ({
119
142
  if (is)
120
143
  push({
121
144
  path,
145
+ names,
122
146
  newProperties,
123
147
  });
124
148
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-remove-duplicate-keys",
3
- "version": "8.0.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": "^13.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": "^27.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"