Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: adjust to find upcast new redundant #577

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
5 changes: 3 additions & 2 deletions src/FSharpLint.Core/Rules/Conventions/RedundantNewKeyword.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,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
| AstNode.Expression(SynExpr.New(_, SynType.App(SynType.LongIdent(identifier), _, _, _, _, _, _), _, range)), Some checkInfo ->
| AstNode.Expression (SynExpr.Upcast (SynExpr.New (_, SynType.LongIdent (identifier), _, range), _, _)), Some checkInfo
| 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 @@ -66,3 +66,24 @@ module Program
new Int32() |> ignore""")

Assert.IsTrue this.ErrorsExist

[<Test>]
member this.``new keyword is required.``() =
this.Parse(
"""
open System

type ISomeInterfaceWithDisposable =
interface
inherit IDisposable
end

type SomeDisposableType() =
interface ISomeInterfaceWithDisposable with
member _.Dispose() = ()

module Program =
let foo = new SomeDisposableType() :> ISomeInterfaceWithDisposable"""
)

this.AssertNoWarnings()