-
-
Notifications
You must be signed in to change notification settings - Fork 26
Add Ignore Functionality for Analyzers #254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
447ae07
Add ignore ranges and some unit tests
1eyewonder 240a558
Add more unit tests
1eyewonder 03e7653
Updated clients to auto ignore messages without analyzer code needing to
1eyewonder a9714a8
Update package providing vulnerability warning
1eyewonder 3befee8
Updated pattern to be prefix: command [codes]
1eyewonder 2e0ffef
Fix package warning
1eyewonder db8d9c7
Add unit tests for client testing ignores
1eyewonder f88c5d1
Revert package bump
1eyewonder 4d02d76
Add documentation
1eyewonder b24a98e
Update category index of document
1eyewonder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| --- | ||
| category: end-users | ||
| categoryindex: 1 | ||
| index: 6 | ||
| --- | ||
|
|
||
| # Optimizing Analyzers Using Ignores | ||
|
|
||
| ## Overview | ||
|
|
||
| When writing analyzers, we often seen code which looks like this: | ||
|
|
||
| ```fsharp | ||
| [<EditorAnalyzerAttribute "YourAnalyzer">] | ||
| let analyzerEditorContext (ctx: EditorContext) = | ||
| handler ctx.TypedTree | ||
| ``` | ||
|
|
||
| The handler code will typically dig into walking the AST/TAST to analyze code and see if the conditions of the current analyzer are being met. | ||
|
|
||
| ## Using Ignore Ranges | ||
|
|
||
| We can optimize our analyzer by checking if there are any ignore ranges with a File scope for the current analyzer. This allows us to skip running the analyzer entirely for files which have been marked to ignore all hits from this analyzer. We cannot skip analyzing files which have more granular ignore ranges (like line or region), since we need to walk the tree to see if any hits fall outside of those ranges. | ||
|
|
||
| ```fsharp | ||
| [<EditorAnalyzerAttribute "YourAnalyzer">] | ||
| let analyzerEditorContext (ctx: EditorContext) = | ||
| let ignoreRanges = ctx.AnalyzerIgnoreRanges |> Map.tryFind "your code here" | ||
|
|
||
| match ignoreRanges with | ||
| | Some ranges -> | ||
| if ranges |> List.contains File then | ||
| async { return [] } | ||
| else | ||
| handler ctx.TypedTree | ||
| | None -> handler ctx.TypedTree | ||
| ``` | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| --- | ||
| category: getting-started | ||
| categoryindex: 1 | ||
| index: 5 | ||
| --- | ||
|
|
||
| # Ignoring Analyzer Hits | ||
|
|
||
| The FSharp.Analyzers.SDK supports suppressing analyzer warnings through special comments which define ignore ranges. This allows you to disable specific analyzers for certain code sections without modifying the analyzer configuration globally. | ||
|
|
||
| ## Comment Format | ||
|
|
||
| The comment format follows this pattern: `prefix: command [codes]`. You can specify multiple codes with one comment by delimiting the codes with commas. For example: `fsharpanalyzer: ignore-line CODE1, CODE2`. | ||
|
|
||
| ## Current Line Ignore | ||
|
|
||
| To ignore analyzer warnings on a single line, use a comment with the analyzer code: | ||
|
|
||
| ```fsharp | ||
| let someFunction () = | ||
| let option = Some 42 | ||
| option.Value // fsharpanalyzer: ignore-line OV001 | ||
| ``` | ||
|
|
||
| ## Next Line Ignore | ||
|
|
||
| To ignore analyzer warnings on a single line, use a comment with the analyzer code: | ||
|
|
||
| ```fsharp | ||
| let someFunction () = | ||
| let option = Some 42 | ||
| // fsharpanalyzer: ignore-line-next OV001 | ||
| option.Value | ||
| ``` | ||
|
|
||
| ## Region Ignore | ||
|
|
||
| To ignore analyzer warnings for a block of code, use start and end comments: | ||
|
|
||
| ```fsharp | ||
| // fsharpanalyzer: ignore-region-start OV001 | ||
| let someFunction () = | ||
| let option = Some 42 | ||
| option.Value | ||
| // fsharpanalyzer: ignore-region-end | ||
| ``` | ||
|
|
||
| ## Ignore File | ||
|
|
||
| To ignore all analyzer warnings in a file, place the following comment at the top of the file: | ||
|
|
||
| ```fsharp | ||
| // fsharpanalyzer: ignore-file OV001 | ||
| let someFunction () = | ||
| let option = Some 42 | ||
| option.Value | ||
| ``` | ||
|
|
||
| [Previous]({{fsdocs-previous-page-link}}) | ||
| [Next]({{fsdocs-next-page-link}}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.