Skip to content

Commit 1fb6cc1

Browse files
committed
DisallowShadowing,Tests: ignore vars starting with _
In DisallowShadowing rule, ignore variables that start with underscore (`_`). Added test for this case.
1 parent 306e62d commit 1fb6cc1

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/FSharpLint.Core/Rules/Conventions/DisallowShadowing.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let rec private extractIdentifiersFromSimplePats (simplePats: SynSimplePats) : L
2626
let private checkIdentifier (args: AstNodeRuleParams) (identifier: Ident) : array<WarningDetails> =
2727
let name = identifier.idText
2828
match args.CheckInfo with
29-
| Some checkResults ->
29+
| Some checkResults when not (name.StartsWith '_') ->
3030
let allUsages = checkResults.GetAllUsesOfAllSymbolsInFile()
3131
let definitionsWithSameName =
3232
allUsages
@@ -115,7 +115,7 @@ let private checkIdentifier (args: AstNodeRuleParams) (identifier: Ident) : arra
115115
else
116116
Array.empty
117117

118-
| None -> Array.empty
118+
| _ -> Array.empty
119119

120120
let runner (args: AstNodeRuleParams) =
121121
match args.AstNode with

tests/FSharpLint.Core.Tests/Rules/Conventions/DisallowShadowing.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,13 @@ module Foo =
136136
let foo = 1"""
137137

138138
Assert.IsTrue this.NoErrorsExist
139+
140+
[<Test>]
141+
member this.``Should not produce error when variable name starts with underscore``() =
142+
this.Parse """
143+
let _foo = 0
144+
145+
module Foo =
146+
let _foo = 1"""
147+
148+
Assert.IsTrue this.NoErrorsExist

0 commit comments

Comments
 (0)