Skip to main content
Diff mode scans only files that changed compared to a base branch, making React Doctor extremely fast even in large codebases.

Quick Start

Run with --diff to scan only changed files:
React Doctor automatically:
  1. Detects your current branch
  2. Finds the base branch (usually main or master)
  3. Identifies changed source files
  4. 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 branch
3

Get changed files

Runs git diff --name-only to find modified files
4

Filter source files

Includes only .ts, .tsx, .js, .jsx files
5

Run checks

Scans only the filtered changed files
Diff mode is much faster than full scans. Use it in CI/CD, pre-commit hooks, and during development.

Specifying Base Branch

Override the auto-detected base branch:
This compares against the develop branch instead of main.

Common Use Cases

Uncommitted Changes

If you have uncommitted changes, React Doctor detects them:
This scans only your working directory changes without committing.
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:
Accepting scans only files changed in your feature branch.

Forcing Diff Mode

Pin diff mode in your config to always scan only changes:
react-doctor.config.json
Or specify a base branch:
react-doctor.config.json
CLI flags override config. Running npx react-doctor . (without --diff) will still do a full scan even if diff is in the config.

Disabling Auto-Detection

Preventing React Doctor from prompting about diff mode:
react-doctor.config.json
This disables automatic detection and prompts.

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:
If you need dead code detection, run a full scan:

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
Run full scans periodically (e.g., on merge to main) to catch context-dependent issues.

Git Integration

React Doctor uses standard Git commands:

Current Branch Detection

Base Branch Detection

Falls back to master if main doesn’t exist.

Changed Files

Uses three-dot notation to compare from the merge base.

Uncommitted Changes

Lists files modified since the last commit.
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:
Add pre-commit hook:
.husky/pre-commit
The --no-ami flag skips interactive prompts.

Using lint-staged

For more control, use lint-staged:
Configure in package.json:
package.json
Add hook:
.husky/pre-commit
Pre-commit hooks can slow down commits if scans take too long. Consider using diff mode or --score for faster feedback.

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:
Useful for CI checks:

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:
  1. Create a feature branch: git checkout -b feat/my-feature
  2. Make changes and commit
  3. 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:
This is expected if you only modified config, markdown, or other non-source files.

Base Branch Not Found

If React Doctor can’t find main or master:
Explicitly specify the base branch.

Best Practices

1. Use Diff Mode in CI

Scan only PR changes for fast feedback:

2. Run Full Scans on Main

Catch issues missed by diff mode:

3. Use Diff Mode During Development

Get instant feedback while coding:

4. Combine with Monorepo Project Selection

Maximum speed in large monorepos:
Diff mode + project selection is the fastest way to get feedback in large codebases.