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
41 changes: 23 additions & 18 deletions src/FSharpLint.Core/Rules/Conventions/AvoidSinglePipeOperator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,35 @@ let runner (args: AstNodeRuleParams) =
SuggestedFix = None
TypeChecks = List.Empty
} |> Array.singleton

let checkExpr (expr: SynExpr) =
match expr with
| SynExpr.App(_exprAtomicFlag, _isInfix, funcExpr, argExpr, _range) ->
match funcExpr with
| ExpressionUtilities.Identifier([ ident ], _) ->
if ident.idText = "op_PipeRight" then
match argExpr with
| SynExpr.App(_exprAtomicFlag, _isInfix, _funcExpr, _argExpr, _range) ->
Array.empty
| SynExpr.IfThenElse _ ->
Array.empty
| _ ->
errors ident.idRange
else
Array.empty
| _ ->
Array.empty
| _ ->
Array.empty

let error =
match args.AstNode with
| AstNode.Binding (SynBinding(_synAcc, _synBinding, _mustInline, _isMut, _synAttribs, _preXmlDoc, _synValData, _headPat, _synBindingRet, synExpr, _range, _debugPointAtBinding, _)) ->
match synExpr with
| SynExpr.App(_exprAtomicFlag, _isInfix, funcExpr, _argExpr, _range) ->
match funcExpr with
| SynExpr.App(_exprAtomicFlag, _isInfix, funcExpr, argExpr, _range) ->
match funcExpr with
| ExpressionUtilities.Identifier([ ident ], _) ->
if ident.idText = "op_PipeRight" then
match argExpr with
| SynExpr.App(_exprAtomicFlag, _isInfix, _funcExpr, _argExpr, _range) ->
Array.empty
| SynExpr.IfThenElse _ ->
Array.empty
| _ ->
errors ident.idRange
else
Array.empty
| _ ->
Array.empty
| _ ->
Array.empty
checkExpr funcExpr
| SynExpr.IfThenElse(_, SynExpr.App(_exprAtomicFlag, _isInfix, funcExpr, _argExpr, _range), _, _, _, _, _) ->
checkExpr funcExpr
| _ ->
Array.empty
| _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,39 @@ let foo param =
"""

Assert.True this.NoErrorsExist

[<Test>]
member this.``Use pipe operator once on record``() =
this.Parse """
type Person =
{
FirstName: string
}

let someFunc someParam =
if someParam then
{ FirstName = "Bar" } |> someOtherFunc
else
Array.empty
"""

Assert.IsTrue this.ErrorsExist

[<Test>]
member this.``Use pipe operator twice on record``() =
this.Parse """
type Person =
{
FirstName: string
}

let someFunc someParam =
if someParam then
{ FirstName = "Bar" }
|> someOtherFunc
|> yetAnotherFunc
else
Array.empty
"""

Assert.IsTrue this.NoErrorsExist