|
| 1 | +# Explaining and configuring rules |
| 2 | + |
| 3 | +Explain React Doctor rules and edit `doctor.config.*` safely. Use this when a user |
| 4 | +wants to understand a rule or change which rules run — not for fixing diagnostics |
| 5 | +(that is the main `react-doctor` skill / `/doctor`). |
| 6 | + |
| 7 | +Triggers: "why did this rule fire", "I disagree with this rule", "turn this rule off", |
| 8 | +"stop flagging X", "too noisy", "disable design rules". |
| 9 | + |
| 10 | +## Workflow |
| 11 | + |
| 12 | +1. Identify the rule key from the diagnostic (e.g. `react-doctor/no-array-index-as-key`). |
| 13 | +2. Explain it before changing anything: |
| 14 | + |
| 15 | +```bash |
| 16 | +npx react-doctor@latest rules explain react-doctor/no-array-index-as-key |
| 17 | +``` |
| 18 | + |
| 19 | +3. Pick the narrowest control that matches the user's intent (see decision guide). |
| 20 | +4. Apply it with a `rules` subcommand (edits your `doctor.config.*` or `package.json#reactDoctor` in place, preserving other fields and formatting). |
| 21 | +5. Validate the change did what they wanted: |
| 22 | + |
| 23 | +```bash |
| 24 | +npx react-doctor@latest --verbose --diff |
| 25 | +``` |
| 26 | + |
| 27 | +## Commands |
| 28 | + |
| 29 | +```bash |
| 30 | +npx react-doctor@latest rules list # every rule + its effective severity |
| 31 | +npx react-doctor@latest rules list --configured # only what your config changed |
| 32 | +npx react-doctor@latest rules list --category Performance # filter by category |
| 33 | +npx react-doctor@latest rules explain <rule> # why it matters + how to configure |
| 34 | +npx react-doctor@latest rules disable <rule> # rule never runs |
| 35 | +npx react-doctor@latest rules enable <rule> # turn back on at its recommended severity |
| 36 | +npx react-doctor@latest rules set <rule> warn # off | warn | error |
| 37 | +npx react-doctor@latest rules category "React Native" off # whole category |
| 38 | +npx react-doctor@latest rules ignore-tag design # skip a rule family (design, test-noise, …) |
| 39 | +npx react-doctor@latest rules unignore-tag design |
| 40 | +``` |
| 41 | + |
| 42 | +Rule references accept the full key (`react-doctor/no-danger`), the bare id (`no-danger`), or a legacy key (`react/no-danger`). |
| 43 | + |
| 44 | +## Decision guide |
| 45 | + |
| 46 | +Match the control to the intent — prefer the narrowest one: |
| 47 | + |
| 48 | +- **User disagrees with one rule / it's a false positive for them** → `rules disable <rule>` (sets `rules.<key> = "off"`; the rule stops running everywhere). This is the default for "I don't want this rule". |
| 49 | +- **Rule is fine but wrong severity** → `rules set <rule> warn` or `rules set <rule> error`. |
| 50 | +- **A disabled-by-default rule they want on** → `rules enable <rule>`. |
| 51 | +- **A whole area is unwanted** (e.g. all React Native rules) → `rules category "<Category>" off`. |
| 52 | +- **A behavioral family is noisy** (`design`, `test-noise`, `migration-hint`) → `rules ignore-tag <tag>`. |
| 53 | +- **Keep it locally but hide from PR comment / score / CI gate only** → do NOT disable. Edit `surfaces` in your config (`surfaces.prComment.excludeRules`, `surfaces.score.excludeTags`, `surfaces.ciFailure.excludeCategories`). The rule still shows in local `cli` output. |
| 54 | + |
| 55 | +How the layers combine: `ignore.tags` disables every rule carrying that tag **before** linting, so a tagged rule stays off even if `rules`/`categories` set it to `warn`/`error` (a rule-level override cannot re-enable a tag-ignored rule). For rules that aren't tag-disabled, `rules` overrides `categories` overrides the rule's default. `surfaces` is visibility-only and never changes whether a rule runs. |
| 56 | + |
| 57 | +## Config shape |
| 58 | + |
| 59 | +Config lives in `doctor.config.ts` (or `.js`/`.mjs`/`.cjs`/`.json`/`.jsonc`), or the `reactDoctor` key in `package.json`. The `rules` commands edit whichever exists — TS/JS edits preserve formatting (via magicast) — and create `doctor.config.json` when none does, stamping `$schema`: |
| 60 | + |
| 61 | +```ts |
| 62 | +// doctor.config.ts |
| 63 | +export default { |
| 64 | + rules: { "react-doctor/no-array-index-as-key": "off" }, |
| 65 | + categories: { "React Native": "warn" }, |
| 66 | + ignore: { tags: ["design"] }, |
| 67 | +}; |
| 68 | +``` |
| 69 | + |
| 70 | +## Educating the user |
| 71 | + |
| 72 | +When explaining a rule, lead with the "Why it matters" guidance from `rules explain` and, when they want depth, the per-rule recipe at `https://www.react.doctor/prompts/rules/<plugin>/<rule>.md`. Only after they understand it should you offer to disable it — many "bad" rules are catching real issues. |
0 commit comments