-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[Fix] order
: ensure arcane imports do not cause undefined behavior
#3128
base: main
Are you sure you want to change the base?
Conversation
order
: ensure arcane imports do not cause undefined behaviororder
: ensure arcane imports do not cause undefined behavior
…a `sortTypesAmongThemselves` Closes import-js#2912 import-js#2347 import-js#2441 Subsumes import-js#2615
d929108
to
400fb1a
Compare
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.
seems good overall, assuming the test fails without the fix :-)
src/rules/order.js
Outdated
if (rank === undefined) { | ||
rank = ranks.groups[impType]; | ||
|
||
if(rank === undefined) { |
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 (rank === undefined) { | |
rank = ranks.groups[impType]; | |
if(rank === undefined) { | |
if (typeof rank === 'undefined') { | |
rank = ranks.groups[impType]; | |
if (typeof rank === 'undefined') { |
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 hoped I could factor this change out from contrib-sort-types-among-themselves, but I've noticed the test needs sortTypesGroup
to trigger the bad behavior :)
853d7b6
to
321c79c
Compare
Depends on #3127
This PR implements in
import/order
: a fix to ensureNaN
is never passed into rank-computing functions, which can result in undefined behavior.A demo package containing this fix is temporarily available for easy testing:
Ensure strange imports do not cause strange behavior
There are certain edge cases where a
NaN
rank gets passed around, such as using an import with an absolute specifier under certain configurations. The fix concerns thecomputeRank
function.This PR includes a unit test to catch potential regressions.