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
11 changes: 8 additions & 3 deletions src/FSharpLint.Core/Rules/Conventions/RedundantNewKeyword.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ let private doesNotImplementIDisposable (checkFile:FSharpCheckFileResults) (iden
ctor.DeclaringEntity
|> Option.exists (fun ctorForType ->
Seq.forall (implementsIDisposable >> not) ctorForType.AllInterfaces)
| Some(_) | None -> false
| Some symbol when (symbol.Symbol :? FSharpEntity) ->
let ctor = symbol.Symbol :?> FSharpEntity
Seq.forall (implementsIDisposable >> not) ctor.AllInterfaces
| Some _ -> false
| None -> true

let private generateFix (text:string) range = lazy(
ExpressionUtilities.tryFindTextOfRange range text
Expand All @@ -38,8 +42,9 @@ let private generateFix (text:string) range = lazy(


let runner args =
match (args.AstNode, args.CheckInfo) with
| (AstNode.Expression(SynExpr.New(_, SynType.LongIdent(identifier), _, range)), Some checkInfo) ->
match args.AstNode, args.CheckInfo with
| AstNode.Expression(SynExpr.New(_, SynType.LongIdent(identifier), _, range)), Some checkInfo
| AstNode.Expression(SynExpr.New(_, SynType.App(SynType.LongIdent(identifier), _, _, _, _, _, _), _, range)), Some checkInfo ->
{ Range = range
Message = Resources.GetString("RulesRedundantNewKeyword")
SuggestedFix = Some (generateFix args.FileContent range)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,31 @@ module Program
let _ = System.Version()"""

this.Parse source
Assert.AreEqual(expected, this.ApplyQuickFix source)
Assert.AreEqual(expected, this.ApplyQuickFix source)

[<Test>]
member this.``new keyword is not required (1).``() =
this.Parse("""
module Program
let foo =
new System.Collections.Generic.Dictionary<string, string>() |> ignore""")

Assert.IsTrue this.ErrorsExist

[<Test>]
member this.``new keyword is not required (2).``() =
this.Parse("""
module Program
let foo =
new Guid() |> ignore""")

Assert.IsTrue this.ErrorsExist

[<Test>]
member this.``new keyword is not required (3).``() =
this.Parse("""
module Program
let foo =
new Int32() |> ignore""")

Assert.IsTrue this.ErrorsExist