-
-
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
Bug in order.js preventing from assigning external
to patterns using pathGroups
#1724
Conversation
Co-authored-by: Emily Marigold Klassen <[email protected]> Co-authored-by: Vitaly Gordon <[email protected]>
1 similar comment
Can you add test cases in https://github.com/benmosher/eslint-plugin-import/blob/master/tests/src/rules/order.js ? |
Sure. Will add the case a bit later. |
@golopot I've added the case. Also, sorry about some confusion in my initial message — in my case, I should've probably titled the PR "preventing from assigning So here is the code, it assigns test({
code: `
import fs from 'fs';
import external from 'external';
import externalTooPlease from './make-me-external';
import sibling from './sibling';`,
options: [{
'newlines-between': 'always',
pathGroupsExcludedImportTypes: [],
pathGroups: [
{ pattern: './make-me-external', group: 'external' },
],
groups: [['builtin', 'external'], 'internal', 'parent', 'sibling', 'index'],
}],
}), Under the hood, this happens: {
ranks: {
builtin: 0, // <----- having rank 0
external: 0, // <----- having rank 0
internal: 1,
parent: 2,
sibling: 3,
index: 4,
unknown: 5
},
pathGroups: [{
pattern: './make-me-external',
group: 'external',
position: 0 // because it's 0, the expression evaluates to 0:
// ranks[group] + (position / maxPosition)
}]
} |
Oh my, here is a PR with the same fix (and with a bit more proper title)! :) |
Thanks, I'll handle getting both landed. |
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.
Combined the two PRs; the fix from both, plus your tests. Thanks!
Because I pushed this to two PRs, two appveyor builds ran. The second failed (https://ci.appveyor.com/project/benmosher/eslint-plugin-import/builds/32116513), but the first succeeded (https://ci.appveyor.com/project/benmosher/eslint-plugin-import/builds/32116512), so I'm going to merge through the failure. |
Here, if
group
isexternal
orbuiltin
then the returned rank will be0
:...and then, there we would erroneously throw it away, as if
0
was not a valid rank (which isn't true):Making the comparison more strict fixes the bug: