Dead Code Removal
GitAuto detects and removes unreachable code using static analysis tools like ESLint's @typescript-eslint/no-unnecessary-condition rule. Dead code errors are separated from regular lint errors so they can be handled differently - dead code is removed from the source file rather than treated as a lint violation to fix.
Dead Branches Make 100% Coverage Impossible
If a branch can never be reached - for example, checking a type guard that TypeScript proves is always true, or a catch block after a synchronous operation that cannot throw - testing it is impossible. The coverage report shows those lines as uncovered, and the agent would spend all its iterations trying to write tests that exercise code paths that cannot execute.
Removing dead code improves coverage percentages without writing fake tests. Instead of producing a mock that forces an impossible condition to appear true, GitAuto removes the dead branch entirely, making the codebase cleaner and the coverage numbers accurate.
Why Models Write Tests for Dead Code
Models can't determine whether a code branch is reachable at runtime. They see an if/else and try to test both branches, even when TypeScript's type system proves one branch can never execute. The model generates increasingly contrived mocks to force the dead branch to run, producing tests that pass but test impossible scenarios. Only static analysis (type-aware linting) can definitively identify dead code. No benchmark evaluates whether a test is testing reachable code - a test that passes by mocking impossible conditions scores the same as a meaningful test.
How It Works
During the linting step, GitAuto runs static analysis that can identify conditions that are always true or always false - meaning one branch of an if/else or ternary can never execute. For example, ESLint with typed linting uses TypeScript's type information via the @typescript-eslint/no-unnecessary-condition rule to detect these unreachable branches.
GitAuto parses the linting output and separates dead code detections from regular lint errors. Dead code is fed to the model with instructions to remove the unreachable branch while preserving the reachable code. The resulting diff removes the dead branch, and coverage naturally improves because there are fewer lines that need to be covered.
Related Features
- Linting - provides the typed linting output that identifies dead code
- Untestable Detection - identifies code that is hard to test but not provably dead
- Coverage Enforcement - benefits from dead code removal by having fewer uncoverable lines
Need Help?
Have questions or suggestions? We're here to help you get the most out of GitAuto.
Contact us with your questions or feedback!