diff --git a/packages/plugin-remove-duplicate-keys/lib/remove-duplicate-keys.js b/packages/plugin-remove-duplicate-keys/lib/remove-duplicate-keys.js index 60a83510c..666277067 100644 --- a/packages/plugin-remove-duplicate-keys/lib/remove-duplicate-keys.js +++ b/packages/plugin-remove-duplicate-keys/lib/remove-duplicate-keys.js @@ -29,17 +29,20 @@ module.exports.report = () => 'Duplicate keys should be avoided'; module.exports.match = () => ({ __object: ({__object}) => { + let is = false; const newProps = []; const {properties} = __object; - for (const prop of properties.reverse()) { + for (const prop of properties.slice().reverse()) { if (isSpreadElement(prop) && isIdentifier(prop.argument)) { const {name} = prop.argument; const {length} = properties.filter(isSpreadId(name)); const newLength = newProps.filter(isSpreadId(name)).length; - if (newLength && length > 1) + if (newLength && length > 1) { + is = true; continue; + } } if (isObjectProperty(prop) && isIdentifier(prop.key)) { @@ -48,8 +51,10 @@ module.exports.match = () => ({ const {length} = properties.filter(isObjectPropertyId(name, computed)); const newLength = newProps.filter(isObjectPropertyId(name, computed)).length; - if (newLength && length > 1) + if (newLength && length > 1) { + is = true; continue; + } } if (isObjectProperty(prop) && isStringLiteral(prop.key)) { @@ -57,8 +62,10 @@ module.exports.match = () => ({ const {length} = properties.filter(isObjectPropertyLiteral(value)); const newLength = newProps.filter(isObjectPropertyLiteral(value)).length; - if (newLength && length > 1) + if (newLength && length > 1) { + is = true; continue; + } } newProps.unshift(prop); @@ -66,7 +73,7 @@ module.exports.match = () => ({ store(newProps); - return true; + return is; }, }); diff --git a/packages/plugin-remove-duplicate-keys/test/fixture/duplicate-fix.js b/packages/plugin-remove-duplicate-keys/test/fixture/duplicate-fix.js index 154f01dd2..f72f086f3 100644 --- a/packages/plugin-remove-duplicate-keys/test/fixture/duplicate-fix.js +++ b/packages/plugin-remove-duplicate-keys/test/fixture/duplicate-fix.js @@ -1,4 +1,4 @@ fn({ ...b, - a, + a });