Skip to content

Allow wildcards in --treat-as-* switches - #330

Merged
nojaf merged 4 commits into
ionide:mainfrom
nojaf:glob-patterns-treat-as
Sep 10, 2026
Merged

nojaf merged 4 commits into
ionide:mainfrom
nojaf:glob-patterns-treat-as

Conversation

@nojaf

@nojaf nojaf commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Closes #325

What

The --treat-as-info, --treat-as-hint, --treat-as-warning and --treat-as-error switches now accept a trailing * wildcard next to exact codes:

dotnet fsharp-analyzers --project X.fsproj --treat-as-error "*"
dotnet fsharp-analyzers --project X.fsproj --treat-as-error "GRA-*"
dotnet fsharp-analyzers --project X.fsproj --treat-as-error "GRA-*" --treat-as-warning GRA-STRING-001
  • * matches every code, GRA-* matches every code with that prefix. Exact codes keep working unchanged.
  • An exact code takes precedence over a pattern, so the last example escalates everything under GRA- except GRA-STRING-001.
  • Listing the same exact code in two lists, or two overlapping patterns in two lists (such as * and GRA-*), is still rejected (exit code 16). The error now names the conflicting entries.
  • A * anywhere but the end (such as GRA-*-001) is rejected with a new exit code 23 rather than silently treated as an exact code.
  • The logger is flushed before these early exits. Previously the error message was lost most of the time because the console logger buffers.

Refactoring

Program.fs was a single 1000+ line file with a mutable global logger. It is now split into focused modules (Arguments, ExitErrorCodes, SeverityMapping, Output, SarifReport, MsBuildProperties, ProjectLoading, Analysis), with Program.fs left as the orchestrating main. The logger and the checker are passed explicitly. Two unused definitions (mkKn and a module-level logLevel) were removed. No behaviour change intended.

Tests

New tests/FSharp.Analyzers.Cli.Tests project (NUnit, like OptionAnalyzer.Test) covering severity code parsing, matching, overlap detection, validation, precedence and MSBuild property expansion.

Also verified manually against the OptionAnalyzer sample for the default and GitHub output formats, the SARIF report and each of the treat-as cases above.

Other

  • The solution was migrated from .sln to .slnx.
  • Docs: new "Overriding Severities" section in the CLI page.

The --treat-as-info/hint/warning/error switches only accepted exact
analyzer codes, so a CI stage that wants every finding (or every finding
from one analyzer family) to fail the build had to enumerate all codes
up front. A trailing "*" wildcard is now supported: "*" matches every
code and "GRA-*" matches a family. An exact code takes precedence over a
pattern, so "--treat-as-error GRA-* --treat-as-warning GRA-STRING-001"
escalates everything except that one code.

Validation rejects the same exact code in two lists and overlapping
patterns across lists (e.g. "*" and "GRA-*"). A "*" anywhere but the
end is rejected with a new exit code. Logs are flushed before these
early exits so the error is actually visible.

Split Program.fs into focused modules (Arguments, ExitErrorCodes,
SeverityMapping, Output, SarifReport, MsBuildProperties, ProjectLoading,
Analysis) and pass the logger explicitly instead of a mutable global.
Drop the unused mkKn and module-level logLevel.

Add a FSharp.Analyzers.Cli.Tests project covering severity code
parsing, matching, validation, precedence and MSBuild property
expansion.

Closes ionide#325
@nojaf
nojaf merged commit 1d84ab3 into ionide:main Sep 10, 2026
2 checks passed
@nojaf
nojaf deleted the glob-patterns-treat-as branch September 10, 2026 16:05
@Numpsy Numpsy mentioned this pull request Sep 15, 2026
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.

Allow glob patterns in --treat-as-* switches (e.g. "*" or "GRA-*")

2 participants