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

Static Analysis Results: Unused Code #3099

Closed
Iron-Ham opened this issue Jul 3, 2023 · 0 comments · Fixed by #3100
Closed

Static Analysis Results: Unused Code #3099

Iron-Ham opened this issue Jul 3, 2023 · 0 comments · Fixed by #3100

Comments

@Iron-Ham
Copy link
Contributor

Iron-Ham commented Jul 3, 2023

I ran a static analysis on the Apollo and ApolloSQLite targets and found the following. PR to clean these up incoming:

Static analysis warnings

Sources/Apollo/GraphQLHTTPMethod.swift:1:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)
Sources/Apollo/Collection+Helpers.swift:1:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)
Sources/Apollo/PossiblyDeferred.swift:1:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)
Sources/Apollo/NormalizedCache.swift:1:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)
Sources/Apollo/SelectionSet+JSONInitializer.swift:1:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)
Sources/Apollo/GraphQLSelectionSetMapper.swift:5:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)
Sources/Apollo/RequestChain.swift:1:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)
Sources/Apollo/RequestBodyCreator.swift:1:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)
Sources/Apollo/InMemoryNormalizedCache.swift:1:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)
Sources/Apollo/DataLoader.swift:1:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)
Sources/Apollo/HTTPURLResponse+Helpers.swift:8:7: error: Unused Declaration Violation: Declarations should be referenced at least once within all files linted (unused_declaration)
Sources/Apollo/DispatchQueue+Optional.swift:1:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)
Sources/Apollo/GraphQLResult.swift:1:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)
Sources/ApolloAPI/InputValue.swift:1:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)
Sources/ApolloAPI/LocalCacheMutation.swift:39:5: error: Unused Declaration Violation: Declarations should be referenced at least once within all files linted (unused_declaration)
Sources/ApolloAPI/LocalCacheMutation.swift:1:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)
Sources/ApolloAPI/DataDict.swift:35:5: error: Unused Declaration Violation: Declarations should be referenced at least once within all files linted (unused_declaration)
Sources/ApolloAPI/DataDict.swift:45:5: error: Unused Declaration Violation: Declarations should be referenced at least once within all files linted (unused_declaration)
Sources/ApolloAPI/JSON.swift:1:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)
Sources/ApolloAPI/GraphQLNullable.swift:1:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)
Sources/ApolloAPI/AnyHashableConvertible.swift:1:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)
Sources/ApolloAPI/Selection.swift:1:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)
Sources/ApolloAPI/Selection+Conditions.swift:1:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)
/Sources/ApolloSQLite/SQLiteSerialization.swift:2:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)

Methodology:

First, I created a .swiftlint.yml analysis configuration:

analyzer_rules:
  - unused_import
  - unused_declaration

Then, I ran the following commands:

➜ xcodebuild -project Apollo.xcodeproj -scheme Apollo -configuration Debug -sdk iphonesimulator > 'xcodebuild.log'
➜ swiftlint analyze --compiler-log-path xcodebuild.log | tee deadcode.log
➜ grep -E "(warning|error):" deadcode.log | tee deadcode.md

And repeated for ApolloSQLite

Note that swiftlint analyze registers _modify blocks as unused declarations. I've opened up an issue about that.

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

Successfully merging a pull request may close this issue.

1 participant