Skip to content

Feature request: per-file rule ignore in react-doctor.config.json #160

@thinkbig1979

Description

@thinkbig1979

Summary

ignore.files is currently all-or-nothing: any file matched by a glob has every rule suppressed. There's no way to say "ignore rule X for files matching glob Y while keeping all other rules active." The result is that legitimate file-level exemptions force overshooting — losing coverage for unrelated rules.

(This is distinct from #86, which is a bug about ignore.files not matching at all. This request is for a config-shape extension assuming #86 is fixed.)

Current shape

{
  "ignore": {
    "rules": ["react-doctor/prefer-useReducer"],
    "files": ["app/(dev)/**", "components/modules/diff/**"]
  }
}

Requested shape

{
  "ignore": {
    "rules": ["react-doctor/prefer-useReducer"],
    "files": ["app/(dev)/**"],
    "filesByRule": [
      {
        "files": ["components/modules/diff/**"],
        "rules": ["react-doctor/no-array-index-as-key", "react-doctor/no-render-in-render"]
      },
      {
        "files": ["components/search/HighlightedSnippet.tsx"],
        "rules": ["react/no-danger"]
      }
    ]
  }
}

Concrete cases from one cleanup

File / glob Rules legitimately suppressed Other rules we'd like to keep enforced
components/modules/diff/** no-array-index-as-key (diff segments have no item identity), no-render-in-render (extracted render helpers are local to this single file) js-combine-iterations, prefer-useReducer, no-effect-event-handler, etc.
components/ai-assistant/AIMessage.tsx no-array-index-as-key (markdown lines parsed once from immutable message content) every other react-doctor rule
components/search/HighlightedSnippet.tsx react/no-danger (file's sole purpose is rendering pre-escaped HTML) every other rule
**/*PresetList* no-array-index-as-key for skeleton placeholder lists the rest

In every row, the current ignore.files shape forces us to disable react-doctor entirely for the file. That regresses coverage for any future violation we'd actually want to know about.

Workarounds today

  1. Per-site inline suppressions — works but verbose at scale (e.g. 10 sites in one diff file)
  2. Whole-file ignore.files entry — what we've been doing; loses coverage for unrelated rules
  3. Helper-component extraction with the helper isolated to its own file — works for the dangerouslySetInnerHTML case but adds files

Suggested implementation

filesByRule (or whatever the name) is a list of { files, rules } pairs. Each pair operates as "for files matching files, disable rules in rules." Rules disabled here do not affect non-matching files; rules disabled in ignore.rules still apply globally.

Repro environment

  • react-doctor 0.0.47

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions