-
-
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
react/sort-prop-types doesn't work for TypeScript #2702
Comments
The "sort prop types" rule sorts |
Hmm, in the docs of the rule I found this:
(...) type Props = {
z: number,
a: any,
b: string
}
class Component extends React.Component<Props> {
...
} What's the point of this example if the rule doesn't consider it then? |
Seems like the type annotations where added here: #2546. |
hmm - @silvenon i guess i didn't check #2546 thoroughly. There's no tests for TS or Flow types in https://github.com/yannickcr/eslint-plugin-react/blob/master/tests/lib/rules/sort-prop-types.js, so I think this is just a docs error. I'd be happy to review a PR that either 1) added, behind an option, support for sorting TS/Flow types; or 2) fixes the docs to remove the implication that it sorts TS/Flow types. |
Feels like this typescript-eslint rule handles what you'd want. Would this package still wanna support rules covered by that plugin? |
@kylemh if there's anything react-specific, then this plugin should indeed be able to overlap with that one. |
Sorry, to be clear I totally see the need for the defaultProps and propTypes property sorting. I meant maybe consider not adding the ability to sort |
That's a fair point - if that functionality is already doable with typescript-eslint, and there's nothing react-specific that's needed, then this rule probably shouldn't support it. |
It seems like In JavaScript, if you want to sort properties of every object, you can use Isn't that a valid use case for TypeScript as well? |
Since prop-types are more like a TS interface than a JS object literal, I'd say it'd make sense to sort TS prop types the same as other TS types? |
My thoughts as well. You can even limit the sorting to only ever sort My mindset is: if you're sorting the interfaces that represent |
Hmm, I see your point. My personal opinion is that something like I guess something you could do, is using |
Well, that wouldn't work either since you could have non-prop related interfaces in |
Yep, there might be some false positives! |
@amannn And |
This comment was marked as spam.
This comment was marked as spam.
I think this was addressed in #3615 (requires |
Since it is mentioned in the README of the rule I expected this to work with TypeScript.
However it seems like it doesn't:
Here's a reproduction repository: https://github.com/amannn/eslint-plugin-react-test
Thanks!
The text was updated successfully, but these errors were encountered: