-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(no-duplicate): fix no-duplicate false positive on side-effect + type imports #3194
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -552,6 +552,14 @@ context('TypeScript', function () { | |
code: "import { type x } from './foo'; import type y from 'foo'", | ||
...parserConfig, | ||
}), | ||
test({ | ||
code: ` | ||
import type { A } from 'a'; | ||
import 'a'; | ||
`, | ||
options: [{ 'prefer-inline': true }], | ||
...parserConfig, | ||
}), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's also add a similar invalid test, with output? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you mean this:
? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think more like
with prefer-inline set to true? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, got it, will add it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fails but I think for the wrong reasons and is a different issue. It currently suggests:
which is syntactically wrong There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, I think that's part of #3195 perhaps? It'd be cool to fix that too here :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (sorry this is moving so slow) i pushed a fix that allows for this condition, let me know what you think. also pushed a fix for point 2 from the linked issue. taking a look at the failing test now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pushed a fix for both issues in #3195 had to disable one of the tests if the parser is babel because apparently it does not support https://astexplorer.net/#/gist/a676569326155f55fa15da7fd791ffda/latest |
||
]); | ||
|
||
const invalid = [ | ||
|
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.
the way this is written, it is literally always true, because nodes.length is > 1, and everything in it is in one of the three groups (since the "value" condition is an "else"). is that intentional?
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.
not sure i got this. my thinking was - if there are duplicates and one of them is a type import, while the other is a side effect, do not err
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.
ahhhhh you're right, this is
=== 0
. ok, so it seems like maybe this would work as well?(ofc Object.groupBy would need to use https://npmjs.com/object.groupby instead, but that's still slightly more efficient)
and an even simpler approach:
that way uses no deps, breaks as soon as it finds an invalidating condition, and avoids creating three arrays.
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.
nice, done
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.
bump