Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Jordan Harband <ljharb@gmail.com>
  • Loading branch information
golopot and ljharb committed Mar 16, 2022
1 parent d5e0fda commit 9df0684
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/rules/destructuring-assignment.md
Expand Up @@ -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'` :

Expand All @@ -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 <Goo a={a}/>
}
```
14 changes: 10 additions & 4 deletions lib/rules/destructuring-assignment.js
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 9df0684

Please sign in to comment.