Skip to content

Commit 08ceae7

Browse files
authored
Merge PR #696 from Mersho/AvoidSinglePipeOperatorFalseNegative
Fix AvoidSinglePipeOperator false negative.
2 parents 8a01dc4 + 0b25137 commit 08ceae7

File tree

2 files changed

+59
-18
lines changed

2 files changed

+59
-18
lines changed

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

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,35 @@ let runner (args: AstNodeRuleParams) =
1616
SuggestedFix = None
1717
TypeChecks = List.Empty
1818
} |> Array.singleton
19+
20+
let checkExpr (expr: SynExpr) =
21+
match expr with
22+
| SynExpr.App(_exprAtomicFlag, _isInfix, funcExpr, argExpr, _range) ->
23+
match funcExpr with
24+
| ExpressionUtilities.Identifier([ ident ], _) ->
25+
if ident.idText = "op_PipeRight" then
26+
match argExpr with
27+
| SynExpr.App(_exprAtomicFlag, _isInfix, _funcExpr, _argExpr, _range) ->
28+
Array.empty
29+
| SynExpr.IfThenElse _ ->
30+
Array.empty
31+
| _ ->
32+
errors ident.idRange
33+
else
34+
Array.empty
35+
| _ ->
36+
Array.empty
37+
| _ ->
38+
Array.empty
1939

2040
let error =
2141
match args.AstNode with
2242
| AstNode.Binding (SynBinding(_synAcc, _synBinding, _mustInline, _isMut, _synAttribs, _preXmlDoc, _synValData, _headPat, _synBindingRet, synExpr, _range, _debugPointAtBinding, _)) ->
2343
match synExpr with
2444
| SynExpr.App(_exprAtomicFlag, _isInfix, funcExpr, _argExpr, _range) ->
25-
match funcExpr with
26-
| SynExpr.App(_exprAtomicFlag, _isInfix, funcExpr, argExpr, _range) ->
27-
match funcExpr with
28-
| ExpressionUtilities.Identifier([ ident ], _) ->
29-
if ident.idText = "op_PipeRight" then
30-
match argExpr with
31-
| SynExpr.App(_exprAtomicFlag, _isInfix, _funcExpr, _argExpr, _range) ->
32-
Array.empty
33-
| SynExpr.IfThenElse _ ->
34-
Array.empty
35-
| _ ->
36-
errors ident.idRange
37-
else
38-
Array.empty
39-
| _ ->
40-
Array.empty
41-
| _ ->
42-
Array.empty
45+
checkExpr funcExpr
46+
| SynExpr.IfThenElse(_, SynExpr.App(_exprAtomicFlag, _isInfix, funcExpr, _argExpr, _range), _, _, _, _, _) ->
47+
checkExpr funcExpr
4348
| _ ->
4449
Array.empty
4550
| _ ->

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,39 @@ let foo param =
104104
"""
105105

106106
Assert.True this.NoErrorsExist
107+
108+
[<Test>]
109+
member this.``Use pipe operator once on record``() =
110+
this.Parse """
111+
type Person =
112+
{
113+
FirstName: string
114+
}
115+
116+
let someFunc someParam =
117+
if someParam then
118+
{ FirstName = "Bar" } |> someOtherFunc
119+
else
120+
Array.empty
121+
"""
122+
123+
Assert.IsTrue this.ErrorsExist
124+
125+
[<Test>]
126+
member this.``Use pipe operator twice on record``() =
127+
this.Parse """
128+
type Person =
129+
{
130+
FirstName: string
131+
}
132+
133+
let someFunc someParam =
134+
if someParam then
135+
{ FirstName = "Bar" }
136+
|> someOtherFunc
137+
|> yetAnotherFunc
138+
else
139+
Array.empty
140+
"""
141+
142+
Assert.IsTrue this.NoErrorsExist

0 commit comments

Comments
 (0)