A CLI tool to automatically remove feature flags from TypeScript code.
This tool detects code related to the specified feature flag and automatically rewrites the code to keep only the code when the flag is enabled (the then branch).
- Recursively traverse directories to scan TypeScript code
- Detect calls to feature flag functions (default:
isFeatureReleased('flag-name')) - Support custom function names via
--functionoption - Remove variable declarations
- Replace if statements with the content of the thenStatement
yarn install
yarn buildyarn dev <target-directory> <flag-name> [--write | --suffix] [--function <function-name>]# Preview changes (dry-run mode, default)
yarn dev ./src AWESOME_FEATURE
# Remove AWESOME_FEATURE flag (directly update source files)
yarn dev ./src AWESOME_FEATURE --write
# Suffix mode (preserve original files, create .fixed files)
yarn dev ./src AWESOME_FEATURE --suffix
# Use a custom function name
yarn dev ./src AWESOME_FEATURE --function checkFeatureBy default, the tool runs in dry-run mode without modifying any files. To actually modify files, use one of the following options:
--write: Overwrite the original files directly with the modified content.--suffix: Create new files with a.fixedsuffix containing the modified content, leaving the original files unchanged.--function <function-name>: Specify a custom function name to detect feature flags. Default isisFeatureReleased.
Note: --write and --suffix cannot be used together.
Before:
const isReleased = isFeatureReleased('AWESOME_FEATURE');
if (isReleased) {
console.log('Feature is enabled');
} else {
console.log('Feature is disabled');
}After:
console.log('Feature is enabled');Before:
if (isFeatureReleased('AWESOME_FEATURE')) {
console.log('Feature is enabled');
}After:
console.log('Feature is enabled');- Default (dry-run mode): Files are not modified (preview only)
- --write mode: Files are directly overwritten
- --suffix mode: Original files are preserved, and
.fixedfiles are created
Note: By default, the tool runs in dry-run mode for safety. Use --write or --suffix to actually modify files.
This tool removes feature flag code as-is, preserving the original indentation and whitespace. After running this tool, it is recommended to use a code formatter (e.g., Prettier) to clean up any formatting inconsistencies that may result from the removal of code blocks.
# Run tests
yarn test
# Run tests in watch mode
yarn test:watch
# Run tests with UI
yarn test:ui
# Run tests with coverage
yarn test:coverage
# Format code
yarn format
# Check formatting
yarn format:check
# Lint
yarn lint
# Fix linting issues automatically
yarn lint:fixremove-feat-flag/
├── src/
│ ├── lib/ # Core library (AST parsing, TypeScript file discovery, replacement processing, type definitions, etc.)
│ └── remove-feat-flag.ts # Main script
├── test-fixtures/
│ └── input/ # Test sample files
├── dist/ # Build output
├── package.json
├── tsconfig.json
├── tsconfig.eslint.json # TypeScript configuration for ESLint
├── vitest.config.ts # Vitest test configuration
├── eslint.config.mjs
└── README.md
Tests are executed using vitest.
Test files (.test.ts) are placed in the same directory as the modules being tested.
Test data is located in test-fixtures/input/.
- AST Parsing: Converts code to AST using TypeScript Compiler
- Flag Detection: Detects calls to the specified function (default:
isFeatureReleased('flag-name')) - Pattern Detection:
- If assigned to a variable → Remove the variable declaration + Replace if statements using that variable
- If used directly in an if statement → Replace the if statement
- Replacement Execution: Replace the entire if statement with the content of the thenStatement (excluding braces)
- File Saving: Write changes to files
MIT