Skip to content

Commit efe0c0c

Browse files
authored
Merge pull request #1907 from alexzherdev/1637-destructuring-assignment-greedy
Make Components.get ignore components with confidence = 0
2 parents 05d781b + 8a3f932 commit efe0c0c

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

lib/util/Components.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,14 @@ class Components {
7575
* Find a component in the list using its node
7676
*
7777
* @param {ASTNode} node The AST node being searched.
78-
* @returns {Object} Component object, undefined if the component is not found
78+
* @returns {Object} Component object, undefined if the component is not found or has confidence value of 0.
7979
*/
8080
get(node) {
8181
const id = getId(node);
82-
return this._list[id];
82+
if (this._list[id] && this._list[id].confidence >= 1) {
83+
return this._list[id];
84+
}
85+
return null;
8386
}
8487

8588
/**

tests/lib/rules/destructuring-assignment.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,37 @@ ruleTester.run('destructuring-assignment', rule, {
134134
}
135135
};`,
136136
options: ['always']
137+
}, {
138+
code: [
139+
'const div = styled.div`',
140+
' & .button {',
141+
' border-radius: ${props => props.borderRadius}px;',
142+
' }',
143+
'`'
144+
].join('\n')
145+
}, {
146+
code: `
147+
export default (context: $Context) => ({
148+
foo: context.bar
149+
});
150+
`,
151+
parser: 'babel-eslint'
152+
}, {
153+
code: `
154+
class Foo {
155+
bar(context) {
156+
return context.baz;
157+
}
158+
}
159+
`
160+
}, {
161+
code: `
162+
class Foo {
163+
bar(props) {
164+
return props.baz;
165+
}
166+
}
167+
`
137168
}],
138169

139170
invalid: [{

0 commit comments

Comments
 (0)