Skip to content

perf: skip rules below the minimum visible severity - #581

Merged
mattiamanzati merged 1 commit into
mainfrom
feat/min-severity-rule-skip
Aug 9, 2026
Merged

perf: skip rules below the minimum visible severity#581
mattiamanzati merged 1 commit into
mainfrom
feat/min-severity-rule-skip

Conversation

@mattiamanzati

Copy link
Copy Markdown
Contributor

What changed

In tsc CLI mode without includeSuggestionsInTsc, suggestion- and message-severity diagnostics are dropped from the output — but only after their rules had already executed, wasting their type-checker queries on every file. This PR skips those rules before execution:

  • rulerunner.Run now takes a minSeverity argument: the least visible severity the caller can surface, computed via the new rulerunner.MinVisibleSeverity(config) helper (CLI without includeSuggestionsInTscwarning; LSP/tests/oxlint and CLI with suggestions enabled → message, i.e. nothing is skipped).
  • A rule whose config-resolved severity is below the threshold is skipped unless any directive in the file references it (by name or *, at file/section/next-line level, regardless of assigned severity). This guard is needed for two reasons: a directive like // @effect-diagnostics ruleName:error can raise the rule above the threshold, and a suppression directive must still be marked used so unusedDirective reporting stays accurate (skipping the rule would fabricate a spurious "directive has no effect" warning).
  • transformDiagnostics now filters by the same threshold instead of consulting global CLI-mode state, so the runner is mode-agnostic and the previously hard-to-test CLI behavior is covered by plain unit tests.
  • New Severity.AtLeastAsVisibleAs in etscore with an explicit visibility ranking (error > warning > suggestion > message > off/skip-file), since the constants' declaration order is not a visibility ordering.
  • The existing skipDisabledOptimization escape hatch also disables this skip, matching the off-severity skip.

Example

// suggestion-severity rules are skipped entirely during `tsc` builds…
const x = Effect.succeed(1)

// …unless a directive references them, e.g. raising one to error:
// @effect-diagnostics someRule:error
const y = Effect.succeed(2)   // someRule runs here and reports as error

Verification

  • Emitted diagnostics are byte-identical (errors and warnings) to a pre-change baseline across a full tsc -b --diagnostics build of the Effect monorepo.
  • Measured on that build (3-run medians): ~1–2s less check time and −23.5M allocations vs the same-day baseline (this box had ambient load, so the wall-clock delta is a range; the allocation drop is load-independent evidence the skip is active).
  • New unit tests: severity ranking, directive-mention matching (HasAnyDirectiveForRule), and MinVisibleSeverity under CLI mode toggled via etscore.EnterCommandLineMode — the CLI-mode test that previously blocked this optimization.
  • pnpm lint, pnpm check, and the full pnpm test suite pass.

🤖 Generated with Claude Code

In CLI mode without includeSuggestionsInTsc, suggestion- and
message-severity diagnostics were filtered out of the output only after
their rules had already run. Pass the minimum surfaceable severity into
rulerunner.Run so such rules are skipped before execution, unless a
directive in the file references them (a directive can raise their
severity and must be marked used for unusedDirective tracking).

transformDiagnostics now filters by the same threshold instead of
consulting global CLI-mode state, making the runner mode-agnostic and
the skip logic unit-testable. Emitted diagnostics are unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mattiamanzati
mattiamanzati merged commit 9020153 into main Aug 9, 2026
6 checks passed
@mattiamanzati
mattiamanzati deleted the feat/min-severity-rule-skip branch August 9, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant