Skip to content

Commit 9df0684

Browse files
chiawendtljharb
andauthored
Apply suggestions from code review
Co-authored-by: Jordan Harband <[email protected]>
1 parent d5e0fda commit 9df0684

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

docs/rules/destructuring-assignment.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class Foo extends React.PureComponent {
107107

108108
### `destructAtParameter` (default: "ignore")
109109

110-
This option can be one of `always` or `ignore`. When configured with `always`, the rule will require props destructuring happens at function parameter.
110+
This option can be one of `always` or `ignore`. When configured with `always`, the rule will require props destructuring happens in the function signature.
111111

112112
Examples of **incorrect** code for `destructAtParameter: 'always'` :
113113

@@ -130,7 +130,7 @@ function Foo({a}) {
130130
// Ignores when props is used elsewhere
131131
function Foo(props) {
132132
const {a} = props;
133-
useProps(props);
133+
useProps(props); // NOTE: it is a bad practice to pass the props object anywhere else!
134134
return <Goo a={a}/>
135135
}
136136
```

lib/rules/destructuring-assignment.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const messages = {
5050
noDestructContextInSFCArg: 'Must never use destructuring context assignment in SFC argument',
5151
noDestructAssignment: 'Must never use destructuring {{type}} assignment',
5252
useDestructAssignment: 'Must use destructuring {{type}} assignment',
53-
destructAtParameter: 'Must destruct props at function parameter.',
53+
destructAtParameter: 'Must destructure props in the function signature.',
5454
};
5555

5656
module.exports = {
@@ -240,9 +240,15 @@ module.exports = {
240240
});
241241
}
242242

243-
if (SFCComponent && destructuringSFC && configuration === 'always' && destructAtParameter === 'always'
244-
&& node.init.name === 'props') {
245-
const propsRefs = context.getScope().set.get('props') && context.getScope().set.get('props').references;
243+
if (
244+
SFCComponent
245+
&& destructuringSFC
246+
&& configuration === 'always'
247+
&& destructAtParameter === 'always'
248+
&& node.init.name === 'props'
249+
) {
250+
const scopeSetProps = context.getScope().set.get('props');
251+
const propsRefs = scopeSetProps && scopeSetProps.references;
246252
if (!propsRefs) {
247253
return;
248254
}

0 commit comments

Comments
 (0)