Skip to content
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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Xunnamius
Copy link
Contributor

@Xunnamius Xunnamius commented Dec 23, 2024

Depends on #3127

This PR implements in import/order: a fix to ensure NaN 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:

npm install --save-dev eslint-plugin-import@npm:@-xun/eslint-plugin-import-experimental

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 the computeRank function.

This PR includes a unit test to catch potential regressions.

@Xunnamius Xunnamius changed the title [New] order: ensure arcane imports do not cause undefined behavior [Fix] order: ensure arcane imports do not cause undefined behavior Dec 23, 2024
@ljharb ljharb marked this pull request as draft December 23, 2024 04:40
Copy link
Member

@ljharb ljharb left a 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 :-)

Comment on lines 530 to 533
if (rank === undefined) {
rank = ranks.groups[impType];

if(rank === undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (rank === undefined) {
rank = ranks.groups[impType];
if(rank === undefined) {
if (typeof rank === 'undefined') {
rank = ranks.groups[impType];
if (typeof rank === 'undefined') {

Copy link
Contributor Author

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants