Skip to content

Commit c304232

Browse files
authored
Merge PR #759 from webwarrior-ws/fix-rule-80-and-81
NestedFunctionNames,UnnestedFunctionNames: fix rules' false positives on non-functions (members with no params).
2 parents a848a1f + c76af8c commit c304232

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

src/FSharpLint.Core/Rules/Conventions/Naming/NestedFunctionNames.fs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ open FSharpLint.Rules.Helper.Naming
88

99
let private getIdentifiers (args: AstNodeRuleParams) =
1010
match args.AstNode with
11-
| AstNode.Binding (SynBinding (_, _, _, _, _attributes, _, _, pattern, _, _, _, _, _)) ->
11+
| AstNode.Binding (SynBinding (_, _, _, _, _attributes, _, valData, pattern, _, _, _, _, _)) ->
1212
if isNested args args.NodeIndex then
1313
let maxAccessibility = AccessControlLevel.Public
14-
getPatternIdents maxAccessibility (fun _a11y innerPattern -> getFunctionIdents innerPattern) true pattern
14+
match identifierTypeFromValData valData with
15+
| Function | Member ->
16+
getPatternIdents maxAccessibility (fun _a11y innerPattern -> getFunctionIdents innerPattern) true pattern
17+
| _ -> Array.empty
1518
else
1619
Array.empty
1720
| _ -> Array.empty

src/FSharpLint.Core/Rules/Conventions/Naming/UnnestedFunctionNames.fs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ open FSharpLint.Rules.Helper.Naming
88

99
let private getIdentifiers (args: AstNodeRuleParams) =
1010
match args.AstNode with
11-
| AstNode.Binding (SynBinding (_, _, _, _, _attributes, _, _, pattern, _, _, _, _,_)) ->
11+
| AstNode.Binding (SynBinding (_, _, _, _, _attributes, _, valData, pattern, _, _, _, _,_)) ->
1212
if isNested args args.NodeIndex then
1313
Array.empty
1414
else
1515
let maxAccessibility = AccessControlLevel.Public
16-
getPatternIdents maxAccessibility (fun _a11y innerPattern -> getFunctionIdents innerPattern) true pattern
16+
match identifierTypeFromValData valData with
17+
| Function | Member ->
18+
getPatternIdents maxAccessibility (fun _a11y innerPattern -> getFunctionIdents innerPattern) true pattern
19+
| _ -> Array.empty
1720
| _ -> Array.empty
1821

1922
let rule config =

tests/FSharpLint.Core.Tests/Rules/Conventions/Naming/NestedFunctionNames.fs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ module Program =
5454

5555
Assert.IsTrue(this.ErrorExistsAt(4, 12))
5656

57+
[<Test>]
58+
member this.NestedFunctionNameWithNoParametersIsPascalCase() =
59+
this.Parse """
60+
module Program =
61+
let CylinderVolume () =
62+
let NestedFunction () =
63+
1
64+
65+
let pi = 3.14159
66+
pi * 2
67+
"""
68+
69+
Assert.IsTrue(this.ErrorExistsAt(4, 12))
70+
5771
[<Test>]
5872
member this.NestedFunctionNameInTypeIsPascalCase() =
5973
this.Parse """
@@ -108,3 +122,14 @@ module Program =
108122
"""
109123

110124
this.AssertNoWarnings()
125+
126+
[<Test>]
127+
member this.``Bindings that are not functions should not cause errors``() =
128+
this.Parse """
129+
module Program =
130+
let OuterFunction () =
131+
let BLUE_STATE = "blue"
132+
()
133+
"""
134+
135+
this.AssertNoWarnings()

tests/FSharpLint.Core.Tests/Rules/Conventions/Naming/UnnestedFunctionNames.fs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,12 @@ module Program =
199199
"""
200200

201201
Assert.IsTrue(this.ErrorExistsAt(8, 8))
202+
203+
[<Test>]
204+
member this.``Bindings that are not functions should not cause errors``() =
205+
this.Parse """
206+
module Program =
207+
let BLUE_STATE = "blue"
208+
"""
209+
210+
this.AssertNoWarnings()

0 commit comments

Comments
 (0)