@putout/plugin-remove-duplicate-keys 1.1.0 → 3.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,12 +1,13 @@
1
- # putout-plugin-remove-duplicate-keys [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL]
1
+ # @putout/plugin-remove-duplicate-keys [![NPM version][NPMIMGURL]][NPMURL]
2
2
 
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"
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"
5
5
 
6
- [DependencyStatusURL]: https://david-dm.org/coderaiser/putout?path=packages/plugin-remove-duplicate-keys
7
- [DependencyStatusIMGURL]: https://david-dm.org/coderaiser/putout.svg?path=packages/plugin-remove-duplicate-keys
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
+ >
8
+ > (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer)
8
9
 
9
- `putout` plugin adds ability to find and remove duplecate keys.
10
+ 🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to find and remove duplecate keys.
10
11
 
11
12
  ## Install
12
13
 
@@ -19,12 +20,12 @@ npm i @putout/plugin-remove-duplicate-keys
19
20
  ```json
20
21
  {
21
22
  "rules": {
22
- "remove-duplicate-keys": true
23
+ "remove-duplicate-keys": "on"
23
24
  }
24
25
  }
25
26
  ```
26
27
 
27
- ## ❌ Incorrect code example
28
+ ## ❌ Example of incorrect code
28
29
 
29
30
  ```js
30
31
  const a = {
@@ -34,7 +35,7 @@ const a = {
34
35
  };
35
36
  ```
36
37
 
37
- ## ✅ Correct code Example
38
+ ## ✅ Example of correct code
38
39
 
39
40
  ```js
40
41
  const a = {
@@ -46,4 +47,3 @@ const a = {
46
47
  ## License
47
48
 
48
49
  MIT
49
-
@@ -15,7 +15,7 @@ const isObjectPropertyLiteral = (value) => (a) => isObjectProperty(a) && isStrin
15
15
 
16
16
  const store = fullstore([]);
17
17
 
18
- module.exports.report = () => 'Duplicate keys should be avoided';
18
+ module.exports.report = () => 'Avoid duplicate keys';
19
19
 
20
20
  module.exports.replace = () => ({
21
21
  __object: ({__object}) => {
@@ -47,6 +47,10 @@ module.exports.match = () => ({
47
47
  if (isObjectProperty(prop) && isIdentifier(prop.key)) {
48
48
  const {computed} = prop;
49
49
  const {name} = prop.key;
50
+
51
+ if (name !== prop.value.name)
52
+ continue;
53
+
50
54
  const isFirst = checkIfFirst(properties, newProperties, isObjectPropertyId, name, {
51
55
  computed,
52
56
  });
@@ -81,9 +85,6 @@ function checkIfFirst(properties, newProperties, isFn, str, {computed} = {}) {
81
85
  const oldLength = properties.filter(isFn(str, computed)).length;
82
86
  const newLength = newProperties.filter(isFn(str, computed)).length;
83
87
 
84
- if (newLength && oldLength > 1)
85
- return false;
86
-
87
- return true;
88
+ return !newLength || oldLength <= 1;
88
89
  }
89
90
 
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@putout/plugin-remove-duplicate-keys",
3
- "version": "1.1.0",
3
+ "version": "3.0.0",
4
+ "type": "commonjs",
4
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
5
- "description": "putout plugin adds ability to find and remove process.exit",
6
- "homepage": "http://github.com/coderaiser/putout",
6
+ "description": "putout plugin adds ability to find and remove duplicate keys",
7
+ "homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-duplicate-keys#readme",
7
8
  "main": "lib/remove-duplicate-keys.js",
8
9
  "release": false,
9
10
  "tag": false,
@@ -15,10 +16,10 @@
15
16
  "scripts": {
16
17
  "test": "madrun test",
17
18
  "watch:test": "madrun watch:test",
18
- "lint:lib": "madrun lint:lib",
19
19
  "lint": "madrun lint",
20
+ "fresh:lint": "madrun fresh:lint",
21
+ "lint:fresh": "madrun lint:fresh",
20
22
  "fix:lint": "madrun fix:lint",
21
- "putout": "madrun putout",
22
23
  "coverage": "madrun coverage",
23
24
  "report": "madrun report"
24
25
  },
@@ -34,22 +35,21 @@
34
35
  "key"
35
36
  ],
36
37
  "devDependencies": {
37
- "@putout/test": "^2.0.0",
38
- "coveralls": "^3.0.0",
39
- "eslint": "^7.0.0",
38
+ "@putout/test": "^5.0.0",
39
+ "c8": "^7.5.0",
40
+ "eslint": "^8.0.1",
40
41
  "eslint-plugin-node": "^11.0.0",
41
- "eslint-plugin-putout": "^4.0.0",
42
- "lerna": "^3.8.5",
43
- "madrun": "^6.0.0",
44
- "nodemon": "^2.0.1",
45
- "nyc": "^15.0.1"
42
+ "eslint-plugin-putout": "^14.0.0",
43
+ "lerna": "^4.0.0",
44
+ "madrun": "^9.0.0",
45
+ "nodemon": "^2.0.1"
46
46
  },
47
47
  "peerDependencies": {
48
- "putout": ">=8"
48
+ "putout": ">=25"
49
49
  },
50
50
  "license": "MIT",
51
51
  "engines": {
52
- "node": ">=8.3.0"
52
+ "node": ">=16"
53
53
  },
54
54
  "publishConfig": {
55
55
  "access": "public"