You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
The actual running code.
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:
Review coverage reports to identify dead functions in tests or unused tests.
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.
The text was updated successfully, but these errors were encountered:
Problem
Use-cases:
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 themain
branch in this repository.coverage.py
for Python andIstanbul
for JavaScript.SonarQube
,Pylint
for Python, andESLint
for JavaScript.The text was updated successfully, but these errors were encountered: