Skip to content

Commit

Permalink
Merge pull request #1907 from alexzherdev/1637-destructuring-assignme…
Browse files Browse the repository at this point in the history
…nt-greedy

Make Components.get ignore components with confidence = 0
  • Loading branch information
ljharb committed Jul 29, 2018
2 parents 05d781b + 8a3f932 commit efe0c0c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/util/Components.js
Expand Up @@ -75,11 +75,14 @@ class Components {
* Find a component in the list using its node
*
* @param {ASTNode} node The AST node being searched.
* @returns {Object} Component object, undefined if the component is not found
* @returns {Object} Component object, undefined if the component is not found or has confidence value of 0.
*/
get(node) {
const id = getId(node);
return this._list[id];
if (this._list[id] && this._list[id].confidence >= 1) {
return this._list[id];
}
return null;
}

/**
Expand Down
31 changes: 31 additions & 0 deletions tests/lib/rules/destructuring-assignment.js
Expand Up @@ -134,6 +134,37 @@ ruleTester.run('destructuring-assignment', rule, {
}
};`,
options: ['always']
}, {
code: [
'const div = styled.div`',
' & .button {',
' border-radius: ${props => props.borderRadius}px;',
' }',
'`'
].join('\n')
}, {
code: `
export default (context: $Context) => ({
foo: context.bar
});
`,
parser: 'babel-eslint'
}, {
code: `
class Foo {
bar(context) {
return context.baz;
}
}
`
}, {
code: `
class Foo {
bar(props) {
return props.baz;
}
}
`
}],

invalid: [{
Expand Down

0 comments on commit efe0c0c

Please sign in to comment.