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

unused_import false positives #3116

Closed
2 tasks done
AdrianBinDC opened this issue Feb 16, 2020 · 2 comments
Closed
2 tasks done

unused_import false positives #3116

AdrianBinDC opened this issue Feb 16, 2020 · 2 comments
Labels
wontfix Issues that became stale and were auto-closed by a bot.

Comments

@AdrianBinDC
Copy link
Contributor

AdrianBinDC commented Feb 16, 2020

New Issue Checklist

Describe the bug

I ran swiftlint analyze on a large project with autocorrect enabled for unused_imports. While swiftlint found a large amount of unused imports, the project didn't compile when I built after running swiftlint analyze. I stashed swiftlint's changes before making alterations to it. From there, I applied the stash and kept addressing compiler errors until I got the project to build. When I finished, I discovered despite the reduction in imports, the project took slightly longer to build when building after nuking derived data. When building WITH derived data, the build time was dramatically faster before removing imports than after.

Should I expect compile times to go down as a result of removing unused imports?

Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint
 Done linting! Found X violations, 0 serious in Y files.

Environment

  • SwiftLint version (run swiftlint version to be sure)?
    0.39.1
  • Installation method used (Homebrew, CocoaPods, building from source, etc)?
    Homebrew
  • Which Xcode version are you using (check xcodebuild -version)?
    Xcode 11.3.1
    Build version 11C504
@jpsim
Copy link
Collaborator

jpsim commented Feb 16, 2020

You seem to be discussing two separate points, first that correcting the unused import rule makes your modules fail to compile, second that after fixing those missing imports your module takes longer to compile. I’ll separate these discussion points for clarity.

1. Modules no longer compile after correcting for unused imports

This is because Swift allows referencing some declarations that are only transitively imported, but the rule will remove all imports that aren’t directly used, even if they transitively expose a module that is used in that file. Up until now, re-adding these directly used imports has required manual editing after running SwiftLint Analyze.

I’m in the process of adding configuration options to the unused import rule in #3117 that would require that all modules referenced in a source file be explicitly imported in that file. This adds a lot of noise to the import list, but has the added advantage of preventing swiftlint lint --autocorrect from introducing compiler errors in your files.

I’d love to know if you’d be interested in using that feature, or if you have suggestions for how it should work.

2. Adding new imports after correcting unused import violations makes compilation take longer

I was surprised to read this considering that the imports you’re adding are presumably direct imports for the exact modules referenced in the source file. I’d need to see a sample project with steps to reproduce to be able to offer more advice here. It may also be a swift compiler issue if narrowing the imports included in a file lengthens its compilation time.

@stale
Copy link

stale bot commented Nov 8, 2020

This issue has been automatically marked as stale because it has not had any recent activity. Please comment to prevent this issue from being closed. Thank you for your contributions!

@stale stale bot added the wontfix Issues that became stale and were auto-closed by a bot. label Nov 8, 2020
@stale stale bot closed this as completed Nov 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix Issues that became stale and were auto-closed by a bot.
Projects
None yet
Development

No branches or pull requests

2 participants