-
Notifications
You must be signed in to change notification settings - Fork 248
Delete duplicate imports. #150
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
Conversation
What happens if someone has this?
and is the result different than if they had this?
I guess there are two questions here:
I suppose the same thing could happen for other attributes that aren't technically supported yet, like Now that I've written that last sentence, maybe the right thing to do for attributed imports is not to deduplicate them at all; that way we don't have to deal with which attributes "semantically override" the others. Can you add a test or two that covers these cases? |
Last I checked, the compiler mistook the second for having already been covered by the first and skipped it. The second example was actually testable; the first actually wasn’t. But that is probably a bug. I first ran into it when I wrote something like this... import Module
@testable import struct Module.Structure ...and nothing was testable, but I changed it to... @testable import struct Module.Structure
import Module ...and only the structure was testable, but everything was available. That had been my original intention. |
7fb2fbe
to
bb84022
Compare
The criteria for deletion is: - Has an identical path, excluding whitespace, as an existing import - No more than 1 of the matching imports have a trailing comment The trailing comment rule is necessary because it's impossible to safely combine multiple trailing comments such that they all stay grouped to the relevant import. Leading comments are safe to combine, because OrderedImports keeps multiple lines of leading comments grouped to the next import. Rather than trying to keep the trailing comments on 1 line together or promote 1 trailing comment to a leading comment, it's safer to raise the diagnostic and keep both imports.
bb84022
to
7324c20
Compare
It looks like this is fine, at least from a compilation perspective and doesn't even raise a warning. Based on the comments from @SDGGiesbrecht, we might want to reconsider the fact that
It sounds like order does matter, again based on the previous comment.
I agree. I've updated the implementation to consider all pieces of the import decl: the attributes, modifiers, kind, and path for de-duplication. Interestingly, we have special handling for the |
Yeah, as much as I don't want to have us worry too much about questionably-defined behavior, if order matters in that situation, then our current behavior for Let's merge this for now and then consider what to do for |
…able declaration code blocks (swiftlang#150) * Omit initializer expression if closure or function call to ensure reasonable declaration code blocks. Resolves swiftlang#138 * Add changelog entry for swiftlang#150
The criteria for deletion is:
The trailing comment rule is necessary because it's impossible to safely combine multiple trailing comments such that they all stay grouped to the relevant import. Leading comments are safe to combine, because OrderedImports keeps multiple lines of leading comments grouped to the next import. Rather than trying to keep the trailing comments on 1 line together or promote 1 trailing comment to a leading comment, it's safer to raise the diagnostic and keep both imports.