Skip to content

Commit 4470abc

Browse files
committed
refactor
1 parent 838bc19 commit 4470abc

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

lib/rules/no-dupe-keys.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,30 +59,30 @@ function isInsideInitializer(node, references) {
5959
}
6060

6161
/**
62-
* Find if the prop is renamed in the pattern
63-
* @param {Pattern} pattern - The destructuring pattern
64-
* @param {string} propName - The original prop name
65-
* @returns {boolean} - True if the prop is renamed
62+
* Collects all renamed props from a pattern
63+
* @param {Pattern | null} pattern - The destructuring pattern
64+
* @returns {Set<string>} - Set of prop names that have been renamed
6665
*/
67-
function findRenamedProp(pattern, propName) {
66+
function collectRenamedProps(pattern) {
67+
const renamedProps = new Set()
68+
6869
if (!pattern || pattern.type !== 'ObjectPattern') {
69-
return false
70+
return renamedProps
7071
}
7172

7273
for (const prop of pattern.properties) {
7374
if (prop.type !== 'Property') continue
7475

7576
if (
7677
prop.key.type === 'Identifier' &&
77-
prop.key.name === propName &&
7878
prop.value.type === 'Identifier' &&
79-
prop.value.name !== propName
79+
prop.key.name !== prop.value.name
8080
) {
81-
return true
81+
renamedProps.add(prop.key.name)
8282
}
8383
}
8484

85-
return false
85+
return renamedProps
8686
}
8787

8888
module.exports = {
@@ -142,10 +142,12 @@ module.exports = {
142142
node
143143
]
144144

145+
const renamedProps = collectRenamedProps(propsNode)
146+
145147
for (const prop of props) {
146148
if (!prop.propName) continue
147149

148-
if (propsNode && findRenamedProp(propsNode, prop.propName)) {
150+
if (renamedProps.has(prop.propName)) {
149151
continue
150152
}
151153

0 commit comments

Comments
 (0)