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

Dead Code Detection #621

Open
Tracked by #3127
Adal3n3 opened this issue Dec 20, 2024 · 1 comment
Open
Tracked by #3127

Dead Code Detection #621

Adal3n3 opened this issue Dec 20, 2024 · 1 comment

Comments

@Adal3n3
Copy link

Adal3n3 commented Dec 20, 2024

Problem

Use-cases:

In all of the repositories that I maintain, I have already gotten coverage to 100% and require it there. And so I know that if code is uncovered, it's either untested or it's dead code generally. In other repositories I’ve worked on in the past that haven’t reached 100% coverage—for example, Sentry, which is at 60% or something abysmally low—you can actually partition your codebase into two parts:

  1. The actual running code.
  2. The test code.

One assertion you can always make is that your test code should have 100% coverage.
For test helpers, such as assertion helpers or factories, I typically do two things in an application that’s not fully covered:

  1. Review coverage reports to identify dead functions in tests or unused tests.
  2. Eliminate those dead tests and then enforce 100% coverage in test files.

If your test files aren’t 100% covered, it likely means you’re not running all your tests, or you have helper functions in your test code that are unused and can be cleaned up. Removing dead code makes your test suite leaner and more effective.

Dead code, in this context, refers to code that never runs. In a production application, dead code is code that you ship out but is never called. It takes up space, wastes resources for linters, code formatters, and import times, and adds overhead to compiling and type checking. Essentially, it’s just clutter in your codebase that serves no purpose.

Research

What tools can be used to detect dead code?

  • vulture - A Python library that scans the codebase for unused code and generates a report. It is configured to run on every push and pull request to the main branch in this repository.
  • Code coverage tools - These tools can help identify untested code, which may indicate dead code. Examples include coverage.py for Python and Istanbul for JavaScript.
  • Static analysis tools - These tools analyze the code without executing it and can help identify dead code. Examples include SonarQube, Pylint for Python, and ESLint for JavaScript.
  • Integrated development environments (IDEs) - Many modern IDEs have built-in features or plugins to detect dead code. Examples include PyCharm for Python and Visual Studio Code with appropriate extensions.
@Adal3n3 Adal3n3 transferred this issue from codecov/engineering-team Jan 6, 2025
@covecod covecod bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Jan 6, 2025
@jerrodcodecov
Copy link
Contributor

Another tool in the market is: https://www.emergetools.com/blog/posts/dead-code-detection-with-reaper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for: Product Owner
Development

No branches or pull requests

2 participants