Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions docs/content/Optimizing Analyzers Using Ignores.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
category: end-users
categoryindex: 2
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
```

60 changes: 60 additions & 0 deletions docs/content/getting-started/Ignore Analyzer Hits.md
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}})
Loading