Skip to content

Add # typeprof:ignore comment to suppress diagnostics#417

Merged
mame merged 2 commits intomasterfrom
typeprof-ignore
Apr 7, 2026
Merged

Add # typeprof:ignore comment to suppress diagnostics#417
mame merged 2 commits intomasterfrom
typeprof-ignore

Conversation

@mame
Copy link
Copy Markdown
Member

@mame mame commented Apr 7, 2026

Add a way to suppress TypeProf diagnostics on specific lines via comments, following Steep's # steep:ignore convention.

Syntax

Inline form — suppresses diagnostics whose code range starts on the same line:

def check
  Foo.new.accept_int("str") # typeprof:ignore
end

Block form — suppresses diagnostics between :start and :end:

# typeprof:ignore:start
foo(1, 2)
bar(1, 2)
# typeprof:ignore:end

An unmatched # typeprof:ignore:start extends to the end of the file.

Why ignore (and not disable/enable)

To match Steep's existing convention so that users of the Ruby type-checker ecosystem only need to remember one keyword:

form Steep this PR
inline # steep:ignore # typeprof:ignore
block start # steep:ignore:start # typeprof:ignore:start
block end # steep:ignore:end # typeprof:ignore:end

Implementation

  • AST.collect_ignore_ranges (in lib/typeprof/core/ast.rb) scans Prism comments at parse time and returns a list of ignored line ranges.
  • ProgramNode stores those ranges and filters them out in each_diagnostic based on each diagnostic's starting line.

The whole feature is ~40 lines plus tests.

Relation to #306

This PR supersedes #306 by @x-smasato, which proposed the same feature with # typeprof:disable / # typeprof:enable keywords and a dedicated Diagnostic::DisableDirective::Scanner / Filter module pair.

Differences from #306:

  • Keyword renamed to typeprof:ignore / :start / :end to align with Steep (see above).
  • The Scanner/Filter classes are inlined as a small helper in ast.rb and a few lines in ProgramNode#each_diagnostic, since the logic is short enough that splitting it across files felt heavier than the implementation deserved.

@x-smasato's authorship is preserved as Co-Authored-By on the first commit. Thanks to them for the original proposal and design — the structure (scan at parse time, filter at ProgramNode#each_diagnostic) is borrowed from #306.

I'll close #306 once this lands.

mame and others added 2 commits April 7, 2026 16:05
Append `# typeprof:ignore` at the end of a line to suppress any
diagnostic whose code range starts on that line. This is useful for
code patterns that TypeProf cannot analyze precisely.

    def check
      Foo.new.accept_int("str") # typeprof:ignore
    end

The keyword matches Steep's `# steep:ignore` to keep the Ruby type
checker ecosystem consistent.

The structure (collecting comment line ranges and filtering at
ProgramNode#each_diagnostic) is borrowed from #306 which proposed
a similar feature with `# typeprof:disable`/`enable`.

Co-Authored-By: Masato Sugiyama <public@smasato.net>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
For suppressing diagnostics across multiple lines, support a block
form bracketed by `# typeprof:ignore:start` and `# typeprof:ignore:end`
comments:

    # typeprof:ignore:start
    foo(1, 2)
    bar(1, 2)
    # typeprof:ignore:end

An unmatched `:start` extends to the end of the file. The keywords
follow Steep's `# steep:ignore:start`/`:end` convention.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mame mame enabled auto-merge (rebase) April 7, 2026 07:14
@mame mame merged commit d31fa4b into master Apr 7, 2026
12 checks passed
@mame mame deleted the typeprof-ignore branch April 7, 2026 07:14
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