Skip to content

Commit 8a01dc4

Browse files
authored
Merge PR #695 from Mersho/EmptyFnParamOnRecord
FavourStaticEmptyFields: fix false negative.
2 parents 05fa5a2 + 59fba40 commit 8a01dc4

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

src/FSharpLint.Core/Framework/Ast.fs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ module Ast =
4545
attrs
4646
|> List.collect (fun attrList -> attrList.Attributes)
4747

48-
/// Extracts an expression from parentheses e.g. ((x + 4)) -> x + 4
49-
let rec removeParens = function
50-
| SynExpr.Paren(x, _, _, _) -> removeParens x
51-
| x -> x
52-
5348
/// Inlines pipe operators to give a flat function application expression
5449
/// e.g. `x |> List.map id` to `List.map id x`.
5550
let (|FuncApp|_|) functionApplication =

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ let private runner (args: AstNodeRuleParams) =
5050
generateError range emptyLiteralType
5151
| Some(SynExpr.Const (SynConst.String ("", _, range), _)) ->
5252
generateError range EmptyStringLiteral
53+
| Some(SynExpr.App(_, _, _, SynExpr.Const (SynConst.String ("", _, range), _), _)) ->
54+
generateError range EmptyStringLiteral
5355
| _ -> Array.empty)
5456
|> Array.concat
5557
| _ -> Array.empty

src/FSharpLint.Core/Rules/Conventions/FunctionReimplementation/CanBeReplacedWithComposition.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ open FSharpLint.Framework.Suggestion
66
open FSharp.Compiler.Syntax
77
open FSharpLint.Framework.Ast
88
open FSharpLint.Framework.Rules
9+
open FSharpLint.Framework.ExpressionUtilities
910

1011
let private validateLambdaCannotBeReplacedWithComposition _ lambda range =
1112
let canBeReplacedWithFunctionComposition expression =

tests/FSharpLint.Core.Tests/Framework/TestAbstractSyntaxArray.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ open FSharp.Compiler.Syntax
88
open Microsoft.FSharp.Reflection
99
open NUnit.Framework
1010
open TestUtils
11+
open FSharpLint.Framework.ExpressionUtilities
1112

1213
[<TestFixture>]
1314
type TestAst() =

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ type Person =
104104
Assert.IsTrue this.ErrorsExist
105105
Assert.IsTrue (this.ErrorMsg.Contains "String.Empty")
106106

107+
[<Test>]
108+
member this.FavourStaticEmptyFieldsShouldProduceError12() =
109+
this.Parse """
110+
type Person =
111+
{
112+
FirstName: string
113+
}
114+
115+
{ FirstName = fooGetFirstName "" } |> ignore"""
116+
117+
Assert.IsTrue this.ErrorsExist
118+
Assert.IsTrue (this.ErrorMsg.Contains "String.Empty")
119+
107120
[<Test>]
108121
member this.FavourStaticEmptyFieldsShouldNotProduceError1() =
109122
this.Parse "let bar = String.Empty"

0 commit comments

Comments
 (0)