Skip to content

Conversation

@1eyewonder
Copy link

This PR introduces a mechanism to allow users to ignore specific analyzer messages on a line-by-line basis using special comments. This provides developers with fine-grained control over when analyzer rules should be suppressed without having to disable entire analyzers on larger scales.

@Smaug123
Copy link

Smaug123 commented Oct 5, 2025

Idle aside: as you do here, I've been hand-rolling these per analyzer; it would be nice if the SDK itself could handle that somehow.

@TheAngryByrd
Copy link
Member

it would be nice if the SDK itself could handle that somehow.

💯 It would be nice if we could reuse the work Martin put into the scoped nowarn

@TheAngryByrd
Copy link
Member

Hmm looks like the nowarn/warnon stuff is still really based on rules that are soley for the compiler usage =\

Probably would be advantageous for us to align with roslyn. Using editorconfig and pragma

@TheAngryByrd
Copy link
Member

We should breathe some life into ionide/FSharp.Analyzers.SDK#47

@1eyewonder
Copy link
Author

@TheAngryByrd @Smaug123 I made an attempt at at least reducing work for every analyzer by bringing functionality to the SDK. If a form of this gets implemented, analyzers should just be able to do a code based lookup to see if they are being ignored i.e. let ignoreRanges = fooIgnoreMap |> Map.tryFind "IGNORE-001" |> Option.defaultValue []

@TheAngryByrd
Copy link
Member

Awesome work! Is it possible to not even need to analyzers to do anything? I think it be preferable if the SDK was able to filter out without an analyzer caring about what ranges are turned on/off.

I could see an analyzers being expensive to compute and may be advantageous to allow them to not need to do work for performance but thats separate from completing filtering.

@baronfel
Copy link
Contributor

baronfel commented Oct 12, 2025

Echoing @TheAngryByrd, this is awesome.

Looking forward, would it be possible to integrate/combine similar configuration from the following sources:

  • an expanded set of F# compiler-understood directives (similar to C#'s #pragma warning disable [list_of_codes]/#pragma warning restore [list_of_codes])
  • .editorconfigs, either directly discovered by the Analyzer SDK or gathered via MSBuild and provided to the analyzers through that MSBuild mechanism?

@1eyewonder
Copy link
Author

to @TheAngryByrd

So I believe the analyzers will always need to do something since the SDK doesn't have the knowledge of the code constructs each analyzer is looking at. However, I could be wrong in my understanding.

The different levels of ignore we are currently supporting in the SDK are:

  1. Turning off analyzers altogether & ignoring analyzers on a file level
    • The analyzer context will still be created, however we can avoid walking the AST/TAST since we don't need to figure out the ranges in which the analyzer logic is occurring
  2. Ignoring on a range/single line level
    • We will need to walk the AST/TAST and then check if the hit is occurring within an ignore range

I believe a performance improvement made with the SDK changes would be that each analyzer does not have to iterate over the code comments on the same file and can rather refer to the ignore map created for each file. Granted this is not as expensive as walking the trees I'm sure.


to @baronfel

When discussing with Jimmy the other day we were discussing that pragmas are available in the syntax tree but can't be used arbitrarily so I'm unsure of the mechanism if we were to try and utilize them.

As for the .editorconfig, are you thinking we'd do something along the lines of below in order to configure analyzer ignores at the file scope level? I imagine the MSBuild would be similar, just using all the build property magic to convey similar information.

[*.{fs,fsi,fsx}]
IONIDE-001 = false

[*/src/FooBar.fs]
IONIDE-003 = false

@Numpsy
Copy link
Contributor

Numpsy commented Oct 12, 2025

At a risk of adding more complexity (not sure how complicated this is compared to trying to use pragmas etc) - Roslyn analyzers can be disbled using the SuppressMessage attribute as well as with pragmas and .editoconfig, which I sometimes find useful for disabling an analyser for a single class or function without having to turn the analyzer back on again as you need to with a pragma.

@TheAngryByrd
Copy link
Member

Ignoring on a range/single line level
We will need to walk the AST/TAST and then check if the hit is occurring within an ignore range

Well since we're already getting the ignore ranges every time, we could add an additional filter step after Running since a message will have a range. I guess an analyzer could report a range outside but that feels like a bug for the analyzer.

@TheAngryByrd
Copy link
Member

Yeah unfortunately pramgas are quite limited in how they can be used in F# syntax tree. They can't seem to be used at any arbitrary range. You get messages like Directives inside modules are ignored. I think we can support them but I still think we're going to need a custom range/region syntax to handle more granular cases.

SuppressMessage attribute

@baronfel will dotnet/fsharp#13786 still be an issue here?

@baronfel
Copy link
Contributor

UGH my nemesis! Yes this will likely be a problem still.

@1eyewonder
Copy link
Author

Closing this PR since we accomplished the intent over in ionide/FSharp.Analyzers.SDK#254. Thanks for the input & assistance from everyone!

@1eyewonder 1eyewonder closed this Oct 19, 2025
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.

5 participants