diff --git a/lib/util/Components.js b/lib/util/Components.js index 90ec38550f..a9a4161bb6 100644 --- a/lib/util/Components.js +++ b/lib/util/Components.js @@ -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; } /** diff --git a/tests/lib/rules/destructuring-assignment.js b/tests/lib/rules/destructuring-assignment.js index ca5a85e28a..b1200c2d06 100644 --- a/tests/lib/rules/destructuring-assignment.js +++ b/tests/lib/rules/destructuring-assignment.js @@ -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: [{