React Doctor

repository·main·Indexed 25 days ago

https://github.com/millionco/react-doctor

A diagnostic tool for React codebases that identifies security, performance, correctness, accessibility, bundle-size, and architecture issues. It includes an ESLint plugin for real-time linting and a CLI for comprehensive scans. The toolset includes deslop-cli and deslop-js for detecting unused files, dead exports, circular imports, DRY violations, and TypeScript-specific code smells.

Tokens
63.9K
Snippets
98
Records
369
Agent score
97%

What's inside react-doctor

  1. Overview of React Doctor for Zed features

    main

    The Zed extension runs the React Doctor language server to provide:

    • Live diagnostics: Real-time feedback as you type (including unsaved buffers).
    • Precise ranges: Diagnostics point to exact offending nodes rather than entire lines.
    • Hovers: Hover over diagnostics to see rule documentation.
    • Quick fixes: Inline suppression of diagnostics for .ts, .tsx, .js, and .jsx files.

    Supported languages: TypeScript, TSX, and JavaScript (including JSX).

  2. Understand Fuzz Liveness Targets

    main

    Fuzz liveness targets are specialized programs designed to intentionally contain diagnostics. They are used during fuzzing to ensure that updated rules remain on their reporting paths, preventing early exits and ensuring strict runs exercise the full logic of the rules.

    When performing false-positive hunting, the fuzzer is configured to load only corpus/regressions/, where every program is guaranteed to be valid by contract.

  3. Review the React Doctor rule candidates backlog

    main
    The rule-candidates-backlog.md file contains a synthesized list of proposed linting rules for react-doctor. These rules are categorized by implementation priority (Tiers S, A, and B) and functional domain (Correctness, Performance, Accessibility, Security, etc.). This backlog serves as a roadmap for upcoming features and helps developers understand the direction of the project's rule development.
  4. Researching potential MobX lint rules for React Doctor

    main
    This document outlines research into potential MobX-related rules for the React Doctor linter. These rules are categorized by priority (P2/deferred) and focus on preventing common MobX pitfalls such as stale snapshots after async boundaries, improper reaction comparisons, and memory leaks in computed values. Note that many of these are currently in research and are not yet implemented as default rules.
  5. Use React Doctor LSP features in your editor

    main

    When running the language server, you get the following editor integrations:

    • Live diagnostics: Real-time scanning of unsaved buffers with precise underlines on offending tokens.
    • Rich hovers: Hovering over issues displays the rule ID, severity, category, recommendations, suppression hints, and documentation links.
    • Quick fixes: Actions to disable rules for specific lines (using correct // or {/* ... */} syntax), suppress all issues in a file, or explain/report issues.
    • Workspace awareness: Automatic discovery of React projects and monorepo packages, with automatic cache invalidation when package.json or lockfiles change.
    • Status indicators: Progress reporting and server status notifications (health, quiescent, message).
  6. Researching React Router rules for React Doctor

    main
    This document outlines the research and proposed implementation for specific React Router rules within React Doctor. The research focuses on identifying 'P2' (Priority 2) rules and conditional candidates that prevent false positives by verifying route targets and framework-specific behaviors.
  7. React Router rule categories and modes

    main

    React Router rules in React Doctor are categorized by their operational mode. Understanding these modes is necessary to know which rules apply to your specific implementation:

    • Framework mode: Used when @react-router/dev or similar framework-specific packages are detected.
    • Data mode: Focuses on data-related APIs like loaders, actions, fetchers, and route.lazy.
    • Declarative mode: Standard React component usage where data-fetching APIs (like loaders) do not exist.
    • All modes: Rules that apply regardless of the specific mode detected.

    Rules are also prioritized by severity (P0, P1, P2), where P0 rules address harmful behaviors with direct runtime or security consequences.

  8. Install React Doctor for Zed as a dev extension

    main

    Since this extension is not yet published to the Zed extension registry, you must install it manually as a development extension:

    1. Open Zed.
    2. Open the command palette and run zed: extensions (or navigate to Zed → Extensions).
    3. Click Install Dev Extension.
    4. Select the directory: packages/zed-react-doctor.

    Note: Zed will compile the Rust extension to WebAssembly during installation. If you pull changes to the extension, reload it from the Extensions view.

  9. Use the improve-react skill for codebase audits and planning

    main

    The improve-react skill is a read-only advisor designed to survey a React codebase, identify high-leverage improvements, and produce prioritized implementation plans.

    Key distinctions:

    • Unlike the react-doctor skill, improve-react never modifies source code. It only creates files in the plans/ directory.
    • It uses React Doctor's scan results as machine-verified evidence to supplement human-like judgment (e.g., determining if a performance finding is on a 'hot path' or a 'cold path').
    • It is intended for users asking to "improve the React code", "audit this codebase", or "make this app faster".

    When to use instead:

    • For regression checks or immediate fixes, use the react-doctor skill.
  10. Triage React Doctor rule review comments

    main

    When reviewing rule implementations, classify feedback into the following categories to determine the required action:

    | Category | Action | Examples | | :--- | :--- | : | | Fix now | Immediate fix required | Real false positives/negatives, incorrect AST semantics, scope resolution bugs, or control-flow bugs. | | Usually fix | Standard cleanup | Duplicated helpers, misleading names, unnecessary abstractions, or confusing comments. | | Document or defer | Acceptable limitations | False-negative coverage outside v1 scope, path explosion, complex loop/try-catch modeling, or imported file analysis. | | Reject | Do not implement | Suggestions that broaden the rule beyond its message, increase false positives, or conflict with repo style. |

    Note: Always add a regression test for every real bug fixed during the review process.

  11. Install React Doctor for VS Code & Cursor

    main

    React Doctor provides live diagnostics, hovers, and quick fixes in VS Code and Cursor. To ensure diagnostics match your CLI and CI environments, it is highly recommended to add react-doctor to your project's development dependencies. This allows the extension to use your project's specific version instead of a fallback.

    npm i -D react-doctor
  12. Avoid makeAutoObservable in class inheritance

    main

    MobX does not support makeAutoObservable(this) in classes that extend another class or are themselves extended. Using it in an inheritance hierarchy can cause runtime errors.

    Recommended alternatives:

    • Use composition instead of inheritance.
    • Use explicit makeObservable annotations to define exactly which properties are observable.
    import { action, makeObservable, observable, override } from "mobx";
    
    class ChildStore extends BaseStore {
      count = 0;
    
      constructor() {
        super();
        // Use explicit annotations instead of makeAutoObservable
        makeObservable(this, { count: observable, reset: override });
      }
    
      reset() {
        this.count = 0;
      }
    }