-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Problem
Currently, the dead code detector does NOT flag functions and variables as dead code when they are only referenced in test files. However, code that exists only to support testing and is never used in production code could be considered dead code (or at least should be configurable to be treated as such).
Current Behavior
- A function/variable defined in source code
- Only used/imported in test files (e.g.,
*.test.ts,*.spec.ts,__tests__/*) - NOT used anywhere in production code
- Does NOT get flagged as dead code
Expected Behavior
Code that is used ONLY in tests and never in production should be flagged as dead code, or there should be a configuration option to control this behavior.
Rationale
- Test-only code might indicate design issues - If a function is only used in tests, it might mean the abstraction is unnecessary
- Maintenance burden - Test-only functions still need to be maintained even though they provide no production value
- Code bloat - Increases bundle size for no production benefit
- Configurability - Different teams have different policies about test-only code
Possible Solutions
- Add configuration option -
flag_test_only_code: boolto control whether test-only usage should be considered dead - Separate category - Flag as
test_only_codeinstead ofdead_codefor clarity - Exclude test helpers - Allow patterns to exclude legitimate test utilities (e.g.,
src/test-utils/*)
Example
// src/utils.ts
export function testHelper() {
// Only used in tests, never in production
}
// src/utils.test.ts
import { testHelper } from './utils';
test('something', () => {
testHelper();
});Currently testHelper is NOT flagged, but arguably it should be (with proper configuration).
Related
This relates to the detect_test_files functionality and could use similar test file pattern detection.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels