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

Find and remove unused code using leftovers gem #420

Open
wants to merge 10 commits into
base: nz-justice-development
Choose a base branch
from

Conversation

lukearndt
Copy link
Collaborator

@lukearndt lukearndt commented Sep 24, 2024

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 leftovers gem and running it as part of the build using
a new Analysis step. The gem uses static analysis to create a report
of all of the code that it thinks we haven't called.

We can use the .leftovers.yml file to define general patterns for
the gem to either ignore (in the keep section) or consider to have
been dynamically executed (in the dynamic section).

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 ActiveRecord
associations 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:keep annotation
when 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 leftovers gem does not perform any kind of runtime logging to
identify 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.

@lukearndt lukearndt marked this pull request as draft September 24, 2024 05:12
@lukearndt lukearndt marked this pull request as ready for review September 24, 2024 05:22
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 this pull request may close these issues.

1 participant