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
38 changes: 23 additions & 15 deletions src/FSharpLint.Core/Rules/Hints/HintMatcher.fs
Original file line number Diff line number Diff line change
Expand Up @@ -229,30 +229,35 @@ module private MatchExpression =
match (leftExpr, opExpr) with
| ExpressionUtilities.Identifier([ident], _), ExpressionUtilities.Identifier([opIdent], _) when opIdent.idText = "op_Equality" ->
match arguments.FSharpCheckFileResults with
| Some(checkFile) ->
let checkSymbol () =
let symbolUse =
checkFile.GetSymbolUseAtLocation(
ident.idRange.StartLine, ident.idRange.EndColumn, String.Empty, [ident.idText])

match symbolUse with
| Some(symbolUse) ->
| Some checkFile ->
let symbolUse =
checkFile.GetSymbolUseAtLocation(
ident.idRange.StartLine, ident.idRange.EndColumn, String.Empty, [ident.idText])

match symbolUse with
| Some symbolUse ->
let checkSymbol () =
match symbolUse.Symbol with
| :? FSharpParameter
| :? FSharpField -> false
| :? FSharpMemberOrFunctionOrValue as element -> not element.IsProperty
| _ -> true
| None -> true
checkSymbol
|> List.singleton
|> Match
checkSymbol
|> List.singleton
|> Match
| None ->
// Symbol resolution failed, fall back to breadcrumb checking
match filterParens arguments.Breadcrumbs with
| PossiblyInMethod
| PossiblyInConstructor -> NoMatch
| _ -> Match List.Empty
| None ->
/// Check if in `new` expr or function application (either could be a constructor).
match filterParens arguments.Breadcrumbs with
| PossiblyInMethod
| PossiblyInConstructor -> NoMatch
| _ -> Match(List.Empty)
| _ -> Match(List.Empty)
| _ -> Match List.Empty
| _ -> Match List.Empty

[<TailCall>]
let rec matchHintExpr (continuation: unit -> HintMatch) arguments =
Expand Down Expand Up @@ -386,7 +391,10 @@ module private MatchExpression =
matchHintExpr
(fun () ->
matchHintExpr
(fun () -> arguments.SubHint(AstNode.Expression(rightExpr), right) |> matchHintExpr returnEmptyMatch)
(fun () ->
matchHintExpr
(fun () -> notPropertyInitialisationOrNamedParameter arguments leftExpr opExpr)
(arguments.SubHint(AstNode.Expression(rightExpr), right)))
(arguments.SubHint(AstNode.Expression(leftExpr), left)))
(arguments.SubHint(AstNode.Expression(opExpr), op))
| (AstNode.Expression(SynExpr.App(_, _, infixExpr, rightExpr, _)),
Expand Down
35 changes: 35 additions & 0 deletions tests/FSharpLint.Core.Tests/Rules/Hints/HintMatcher.fs
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,41 @@ do

this.AssertNoWarnings()

/// Regression test for: https://github.com/fsprojects/FSharpLint/issues/492
[<Test>]
member this.``Named parameter in atomic static method call should not be treated as infix operation``() =
this.SetConfig(["x = true ===> x"])

this.Parse """
module Goat

type Foo() =
static member Create(keepAssemblyContents: bool) = Foo()

do
let foo = Foo.Create(keepAssemblyContents = true)
()
"""

this.AssertNoWarnings()

/// Regression test for: https://github.com/fsprojects/FSharpLint/issues/492
[<Test>]
member this.``Named parameter in FSharpChecker.Create should not be treated as infix operation``() =
this.SetConfig(["x = true ===> x"])

this.Parse """
module Goat

open FSharp.Compiler.CodeAnalysis

do
let checker = FSharpChecker.Create(keepAssemblyContents = true)
()
"""

this.AssertNoWarnings()

/// Regression test for: https://github.com/fsprojects/FSharpLint/pull/194#issuecomment-268560761
[<Test>]
member this.``Lambdas in hint suggestions must be surrounded with parentheses.``() =
Expand Down
Loading