From c0fda3f57f8027c762de27bef79c53b4fdd79219 Mon Sep 17 00:00:00 2001 From: Alex Zherdev Date: Sat, 28 Jul 2018 14:16:57 -0700 Subject: [PATCH 1/2] Make Components.get ignore components with confidence = 0 Resolves #1637 --- lib/util/Components.js | 7 +++++-- tests/lib/rules/destructuring-assignment.js | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) 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..b4c3bff529 100644 --- a/tests/lib/rules/destructuring-assignment.js +++ b/tests/lib/rules/destructuring-assignment.js @@ -134,6 +134,14 @@ ruleTester.run('destructuring-assignment', rule, { } };`, options: ['always'] + }, { + code: [ + 'const div = styled.div`', + ' & .button {', + ' border-radius: ${props => props.borderRadius}px;', + ' }', + '`' + ].join('\n') }], invalid: [{ From 8a3f93256f4277515b230c6854e4a1bf195b5303 Mon Sep 17 00:00:00 2001 From: Alex Zherdev Date: Sat, 28 Jul 2018 23:59:33 -0700 Subject: [PATCH 2/2] Add tests to destructuring-assignment --- tests/lib/rules/destructuring-assignment.js | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/lib/rules/destructuring-assignment.js b/tests/lib/rules/destructuring-assignment.js index b4c3bff529..b1200c2d06 100644 --- a/tests/lib/rules/destructuring-assignment.js +++ b/tests/lib/rules/destructuring-assignment.js @@ -142,6 +142,29 @@ ruleTester.run('destructuring-assignment', rule, { ' }', '`' ].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: [{