-
-
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
[New] sort-prop-types
: support comments on prop types
#1973
[New] sort-prop-types
: support comments on prop types
#1973
Conversation
} else { | ||
let currentToken = token; | ||
do { | ||
const previousToken = sourceCode.getTokenBefore(currentToken); |
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.
Note: this code was extracted from jsx-curly-spacing
and for some reason this line (or the next) returns undefined
on ESLint 3.0.0 😕(our test suite on master fails against that version). Works well on 3.19.0.
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.
Is this still failing? It'd be useful to figure out which version of 3.x this api was introduced in.
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 it was originally introduced in 3.0.0. My branch has 182 test failures on that version (not all of them seem to be related to this api or caused by my changes though. Master has 127 failures). Between 3.15.0 and 3.16.0 it drops from 169 to 34 failures, removing a lot of errors related to tokens/comments handling. Although a few of the remaining errors are me using getLocFromIndex
in this PR, which was only introduced in 3.17.0 😕 Not sure what to do about that, it would not be feasible/doable to backport, but also there are other tests that are failing on that version anyway... We need at least 3.18.0 for 0 test failures.
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.
If we backported the eslint API, would that work?
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.
Looks like both getLocFromIndex
and getIndexFromLoc
are relying heavily on lineStartIndices
and lines
in the SourceCode
class that get populated once in the constructor. The ESLint docs explicitly say we can use lines
(bottom of the section) but there's no word about lineStartIndices
. Potentially we can just copy over those functions, but the bigger issue with getTokenBefore
/getTokenAfter
remains, and those don't seem possible to be backported.
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.
Is there a way we could runtime-detect these APIs, and provide a reasonable degraded experience for older eslint users?
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'm skeptical (not that we could detect them, but that there is a reasonable experience beyond just not applying fixes), but let me look into that.
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.
yeah that's what i meant - applying fewer fixes when they weren't good enough.
@@ -1533,5 +1533,1330 @@ ruleTester.run('sort-prop-types', rule, { | |||
' }', | |||
'});' | |||
].join('\n') | |||
}, { | |||
code: ` |
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.
Suggestions for more test cases are welcome.
e23cc32
to
44fe90b
Compare
5592386
to
faf1952
Compare
This could use a rebase. |
Will look into that today 👍 |
faf1952
to
67b88a8
Compare
Hmm appveyor actually failed (node 5 choked on args spread somewhere inside eslint), but there's a green check here. |
@alexzherdev node 5 is an allowed failure; eslint 5 also requires node 6+ now, so it's fine. |
@@ -120,6 +122,90 @@ module.exports = { | |||
return 0; | |||
} | |||
|
|||
function getRelatedComments(node, nextNode) { |
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.
Should this live in a shared utility?
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 don't mind that. Although I imagine the isSameLine
bit in the output is pretty specific to this use case, I don't think it is generally useful to know whether the comment related to a thing is on the same line as the thing or not 🤔
} else { | ||
let currentToken = token; | ||
do { | ||
const previousToken = sourceCode.getTokenBefore(currentToken); |
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.
Is this still failing? It'd be useful to figure out which version of 3.x this api was introduced in.
Is there something missing for this PR to get merged? I also encountered the problem described in the referenced issue. |
@amannn I will be tackling #1973 (comment) within a few days |
@alexzherdev That's great to hear! Thank you so much for your help! It's really cool to have auto fixable |
Any resolution on this PR yet? Would be super useful for users of storybook |
Haven’t had time to get back to it yet. The issue in #1973 (comment) is a tricky one to make sense of. |
@alexzherdev Not sure if that's an option, but since even the test suite on master fails for that version, would it be an option to bump the peer dependency of Would be a shame if the support for that version would block helpful contributions like this PR. ESLint 3.0.0 was released on July 1, 2016 – that's three years ago. Even node.js LTS releases have a stop of maintenance after 3 years. |
@amannn no, that'd be a breaking change. Surely there's a way we can handle eslint 3.0 - even if that means gracefully degrading to the behavior prior to this PR. |
@alexzherdev I'm going to disable the entire autofix behavior of this rule before the next release unless we can find a way to get this PR in; it'd be great if you had time to update this. |
ping @alexzherdev, any update? |
58a3c8b
to
deb3090
Compare
59af733
to
865ed16
Compare
069314a
to
181c68f
Compare
Closing in favor of #3471. |
Resolves #1940