Skip to content

Commit 4d02d76

Browse files
committed
Add documentation
1 parent f88c5d1 commit 4d02d76

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
category: end-users
3+
categoryindex: 1
4+
index: 6
5+
---
6+
7+
# Optimizing Analyzers Using Ignores
8+
9+
## Overview
10+
11+
When writing analyzers, we often seen code which looks like this:
12+
13+
```fsharp
14+
[<EditorAnalyzerAttribute "YourAnalyzer">]
15+
let analyzerEditorContext (ctx: EditorContext) =
16+
handler ctx.TypedTree
17+
```
18+
19+
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.
20+
21+
## Using Ignore Ranges
22+
23+
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.
24+
25+
```fsharp
26+
[<EditorAnalyzerAttribute "YourAnalyzer">]
27+
let analyzerEditorContext (ctx: EditorContext) =
28+
let ignoreRanges = ctx.AnalyzerIgnoreRanges |> Map.tryFind "your code here"
29+
30+
match ignoreRanges with
31+
| Some ranges ->
32+
if ranges |> List.contains File then
33+
async { return [] }
34+
else
35+
handler ctx.TypedTree
36+
| None -> handler ctx.TypedTree
37+
```
38+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
category: getting-started
3+
categoryindex: 1
4+
index: 5
5+
---
6+
7+
# Ignoring Analyzer Hits
8+
9+
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.
10+
11+
## Comment Format
12+
13+
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`.
14+
15+
## Current Line Ignore
16+
17+
To ignore analyzer warnings on a single line, use a comment with the analyzer code:
18+
19+
```fsharp
20+
let someFunction () =
21+
let option = Some 42
22+
option.Value // fsharpanalyzer: ignore-line OV001
23+
```
24+
25+
## Next Line Ignore
26+
27+
To ignore analyzer warnings on a single line, use a comment with the analyzer code:
28+
29+
```fsharp
30+
let someFunction () =
31+
let option = Some 42
32+
// fsharpanalyzer: ignore-line-next OV001
33+
option.Value
34+
```
35+
36+
## Region Ignore
37+
38+
To ignore analyzer warnings for a block of code, use start and end comments:
39+
40+
```fsharp
41+
// fsharpanalyzer: ignore-region-start OV001
42+
let someFunction () =
43+
let option = Some 42
44+
option.Value
45+
// fsharpanalyzer: ignore-region-end
46+
```
47+
48+
## Ignore File
49+
50+
To ignore all analyzer warnings in a file, place the following comment at the top of the file:
51+
52+
```fsharp
53+
// fsharpanalyzer: ignore-file OV001
54+
let someFunction () =
55+
let option = Some 42
56+
option.Value
57+
```
58+
59+
[Previous]({{fsdocs-previous-page-link}})
60+
[Next]({{fsdocs-next-page-link}})

0 commit comments

Comments
 (0)