diff --git a/docs/rules/destructuring-assignment.md b/docs/rules/destructuring-assignment.md index 81236232e0..ac97b46cb0 100644 --- a/docs/rules/destructuring-assignment.md +++ b/docs/rules/destructuring-assignment.md @@ -107,7 +107,7 @@ class Foo extends React.PureComponent { ### `destructAtParameter` (default: "ignore") -This option can be one of `always` or `ignore`. When configured with `always`, the rule will require props destructuring happens at function parameter. +This option can be one of `always` or `ignore`. When configured with `always`, the rule will require props destructuring happens in the function signature. Examples of **incorrect** code for `destructAtParameter: 'always'` : @@ -130,7 +130,7 @@ function Foo({a}) { // Ignores when props is used elsewhere function Foo(props) { const {a} = props; - useProps(props); + useProps(props); // NOTE: it is a bad practice to pass the props object anywhere else! return } ``` diff --git a/lib/rules/destructuring-assignment.js b/lib/rules/destructuring-assignment.js index bd020d41fc..f0e2044ad6 100644 --- a/lib/rules/destructuring-assignment.js +++ b/lib/rules/destructuring-assignment.js @@ -50,7 +50,7 @@ const messages = { noDestructContextInSFCArg: 'Must never use destructuring context assignment in SFC argument', noDestructAssignment: 'Must never use destructuring {{type}} assignment', useDestructAssignment: 'Must use destructuring {{type}} assignment', - destructAtParameter: 'Must destruct props at function parameter.', + destructAtParameter: 'Must destructure props in the function signature.', }; module.exports = { @@ -240,9 +240,15 @@ module.exports = { }); } - if (SFCComponent && destructuringSFC && configuration === 'always' && destructAtParameter === 'always' - && node.init.name === 'props') { - const propsRefs = context.getScope().set.get('props') && context.getScope().set.get('props').references; + if ( + SFCComponent + && destructuringSFC + && configuration === 'always' + && destructAtParameter === 'always' + && node.init.name === 'props' + ) { + const scopeSetProps = context.getScope().set.get('props'); + const propsRefs = scopeSetProps && scopeSetProps.references; if (!propsRefs) { return; }