-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rule to require static propTypes = ..
instad of Foo.propTypes = ..
for class-based components
#1923
Comments
Such a rule would need to support both directions: forcing class fields, and forbidding them. |
Agreed. Would a blacklist/whitelist with property names make sense? I'd say no, since having e.g. defaultProps outside but propTypes inside the class would make no sense. |
I’d think you’d set the rule to “static class field” or “outside the class body”, and then separately disable propTypes, defaultProps, contextTypes, etc (ie, set them to “ignore”). Also, the rule should forbid (or require as a third option) static getter methods for these things. |
From what I’ve read here there’s only downsides to using static getters for these, curious why anyone would need to require it? |
If someone isn't able to use class fields yet (they're not yet part of the language) and yet still wants to force static properties to go inside of the class body, they'd need to require it. Additionally, having it be autofixable (ideal), and able to go in all directions, helps migrate a codebase to the inevitable future, static class fields. |
How likely is it that someone uses react without babel though? |
I think the point is that not everyone's babel config includes the class fields transform plugin. |
@ThiefMaster "with babel" in no way means "with proposals" - eslint can't parse stage 3 features, for example, and using babel-eslint isn't a great solution because it enables parsing of all features, not just the ones you're transpiling. Separately, airbnb won't use class fields until there's a lint rule that can forbid ever putting functions in them, for reasons I've gone into elsewhere on this repo. |
(last comment off topic)
That sounds like a fairly straightforward rule, any particular reason it hasn't been implemented? |
@alexzherdev it'd belong in eslint core, and they don't support anything til it's stage 4. |
I'd love to contribute to this purely to have the opposite rule available for my team. I'll likely poke around this weekend, but was curious what sort of extra work is entailed with making it a "fixable" rule. I also wanted to know what was meant by getting |
@kylemh a |
I could be wrong, but isn't |
Ordering, yes - but this is about placement and style (sort-comp doesn’t govern things outside the class, for example) |
@ljharb I was more politely asking if you could find the time to do the development. I was able to read the labels thanks. 😞 Sorry if I inconvenienced you. |
lol ah. if i can find the time, of course! My time however is very limited. |
With such a rule the following would be invalid:
and this would be valid:
The text was updated successfully, but these errors were encountered: