Find and remove unused code using leftovers gem#420
Open
lukearndt wants to merge 10 commits intonz-justice-developmentfrom
Open
Find and remove unused code using leftovers gem#420lukearndt wants to merge 10 commits intonz-justice-developmentfrom
lukearndt wants to merge 10 commits intonz-justice-developmentfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
#363
We want to clean up the code base by removing unused code.
Changes
This commit takes a first step at removing and preventing unused code by
installing the
leftoversgem and running it as part of the build usinga new
Analysisstep. The gem uses static analysis to create a reportof all of the code that it thinks we haven't called.
We can use the
.leftovers.ymlfile to define general patterns forthe gem to either ignore (in the
keepsection) or consider to havebeen dynamically executed (in the
dynamicsection).Where the gem finds individual lines of code that it thinks are not
called, but we are confident that we want to keep, we can annotate them
using
# leftovers:keep. Examples of this are uncalled ActiveRecordassociations and methods that we need to define for gems to call.
In some cases, I was not sure if the code that leftovers reported was
safe to delete so I have annotated it and left comments to that effect.
In the future, we can use search for the
# leftovers:keepannotationwhen we're trying to figure out if something is safe to delete.
Finally, the commit removes some code that the gem reported as unused
and that I was confident enough to go ahead and delete.
Considerations
The
leftoversgem does not perform any kind of runtime logging toidentify which code paths are called (or not) on an ongoing basis.
Without that, it cannot report on entirely vestigial features such as
groups of unused routes, controllers, models, and views.
For that task, we could either install a tool that performs runtime
logging or rely on our knowledge of the system and judge accordingly.
This commit does not fully address issue #363 because it does not delete
all of the code that we've identified and listed there. That work can be
completed as part of a future change.