Quick Start
Run with--diff to scan only changed files:
- Detects your current branch
- Finds the base branch (usually
mainormaster) - Identifies changed source files
- Scans only those files
Diff mode uses Git to detect changes. Your project must be a Git repository.
How Diff Mode Works
React Doctor compares your current state to a base branch:1
Detect Git repository
Verifies the directory is a Git repo
2
Identify base branch
Looks for
main or master branch3
Get changed files
Runs
git diff --name-only to find modified files4
Filter source files
Includes only
.ts, .tsx, .js, .jsx files5
Run checks
Scans only the filtered changed files
Specifying Base Branch
Override the auto-detected base branch:develop branch instead of main.
Common Use Cases
Uncommitted Changes
If you have uncommitted changes, React Doctor detects them:Uncommitted changes mode compares your current state to the last commit (HEAD).
Feature Branch Detection
When you’re on a feature branch, React Doctor asks:Forcing Diff Mode
Pin diff mode in your config to always scan only changes:react-doctor.config.json
react-doctor.config.json
Disabling Auto-Detection
Preventing React Doctor from prompting about diff mode:react-doctor.config.json
Diff Mode in CI/CD
Diff mode is ideal for pull request checks:GitHub Actions
.github/workflows/react-doctor.yml
Set
fetch-depth: 0 to fetch full Git history. React Doctor needs this to compare branches.GitLab CI
.gitlab-ci.yml
Bitbucket Pipelines
bitbucket-pipelines.yml
Diff Mode Limitations
Dead Code Detection Skipped
Dead code analysis requires scanning the entire codebase to detect unused exports. React Doctor automatically skips dead code detection in diff mode:Context-Dependent Rules
Some issues span multiple files. Diff mode may miss:- Unused props passed from unchanged parent components
- Missing imports in unchanged files
- Type errors in unchanged files that depend on changed files
Git Integration
React Doctor uses standard Git commands:Current Branch Detection
Base Branch Detection
master if main doesn’t exist.
Changed Files
Uncommitted Changes
React Doctor requires Git 2.0+ for proper diff detection.
Pre-Commit Hooks
Run React Doctor on staged files before committing:Using Husky
Install Husky:.husky/pre-commit
--no-ami flag skips interactive prompts.
Using lint-staged
For more control, uselint-staged:
package.json:
package.json
.husky/pre-commit
Combining with Other Flags
Diff + Verbose
See which files have issues:Diff + Project
Scan only changed files in a specific monorepo project:Diff + Score
Get only the score for changed files:Troubleshooting Diff Mode
”No feature branch or uncommitted changes detected”
You’re on the base branch (main/master) with no changes. Diff mode falls back to full scan.
To use diff mode:
- Create a feature branch:
git checkout -b feat/my-feature - Make changes and commit
- Run
npx react-doctor . --diff
”fetch-depth: 0 required” in CI
GitHub Actions checks out only the latest commit by default. Add:Diff Mode Finds No Files
If no source files changed:Base Branch Not Found
If React Doctor can’t findmain or master: