-
Notifications
You must be signed in to change notification settings - Fork 18
Conversation
react-prefer-private-members
rulereact-prefer-private-members
rule
meta: { | ||
docs: { | ||
description: 'Disallow public members within React component classes', | ||
category: 'Possible Errors', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really sure what to put in here. Just did my best to follow other rules in this repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably best practices
docs: { | ||
description: 'Disallow public members within React component classes', | ||
category: 'Possible Errors', | ||
recommended: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach looks great!
meta: { | ||
docs: { | ||
description: 'Disallow public members within React component classes', | ||
category: 'Possible Errors', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably best practices
} = node; | ||
return { | ||
node, | ||
message: `${name} should be a private member of ${componentName}.`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to pass the variables?
].some((method) => method === name); | ||
} | ||
|
||
function isReactStaticProperty({key: {name}}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you probably want to allow all static properties, or at least those that are pascal-case, to allow for our (pretty common) pattern of exposing subcomponent as public static members.
parser: babelParser, | ||
}, | ||
], | ||
invalid: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need more tests than this (missing for private members, static members, etc
30510a3
to
d5866f3
Compare
d5866f3
to
21378e0
Compare
@lemonmade this is ready for another look. 🙏 |
} | ||
``` | ||
|
||
The Life Cycle methods and static properties that are part of the React API are not required to be private for this rule. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lifecycle
``` | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So many empty lines :D
1f732c2
to
db33276
Compare
Addresses one of the points here #77 by looking for React class components and making sure they do not have private members. React API stuff will pass through. Will fill in the docs once the general approach is approved.