Skip to content

Commit df8d631

Browse files
committed
AvoidSinglePipeOperator,docs: improved rule 77
Changed rule AvoidSinglePipeOperator to not apply to functions with more than one argument. Updated the docs to reflect this change and give rationale for it.
1 parent db34739 commit df8d631

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

docs/content/how-tos/rules/FL0077.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Use of the pipe operator when only one invocation is employed.
1717
When the use of the pipe operator happens for a single invocation (instead of a multiple one, which would add a chain of them, usually staggered across
1818
many lines), it doesn't aid readibility.
1919

20+
This rule does not apply to functions with more than one argument. The reason for that is primarily application of higher-order functions
21+
such as `map` or `iter`, for which type inference may break without using pipe operator. And it also it helps to have the collection,
22+
which is iterated over, to be on top.
23+
2024
Example of single pipe operator usage:
2125

2226
```fsharp
@@ -34,6 +38,13 @@ let someFunc someParam =
3438
|> yetAnotherFunc
3539
```
3640

41+
Example of single pipe applied to function with several arguments:
42+
43+
```fsharp
44+
projectsInOrder
45+
|> Seq.map(fun proj -> proj.AbsolutePath |> FileInfo)
46+
```
47+
3748
## How To Fix
3849

3950
Just use a normal function call, without the need for any operator:

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,13 @@ let runner (args: AstNodeRuleParams) =
5252

5353
let error =
5454
match args.AstNode with
55-
| AstNode.Expression(SynExpr.App(_exprAtomicFlag, _isInfix, funcExpr, _argExpr, _range)) ->
56-
checkExpr funcExpr (args.GetParents args.NodeIndex)
55+
| AstNode.Expression(SynExpr.App(_exprAtomicFlag, _isInfix, funcExpr, argExpr, _range)) ->
56+
match argExpr with
57+
| SynExpr.App(_) ->
58+
// function has extra arguments
59+
Array.empty
60+
| _ ->
61+
checkExpr funcExpr (args.GetParents args.NodeIndex)
5762
| _ ->
5863
Array.empty
5964

0 commit comments

Comments
 (0)