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

Simplify SelfCheck #679

Merged
merged 4 commits into from
Jan 15, 2024
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
8 changes: 2 additions & 6 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,8 @@ Target.create "SelfCheck" (fun _ ->
let srcDir = Path.Combine(rootDir.FullName, "src") |> DirectoryInfo

let consoleProj = Path.Combine(srcDir.FullName, "FSharpLint.Console", "FSharpLint.Console.fsproj") |> FileInfo
printfn "Checking %s..." consoleProj.FullName
exec "dotnet" (sprintf "run lint %s" consoleProj.FullName) consoleProj.Directory.FullName

let coreProj = Path.Combine(srcDir.FullName, "FSharpLint.Core", "FSharpLint.Core.fsproj") |> FileInfo
printfn "Checking %s..." coreProj.FullName
exec "dotnet" (sprintf "run lint %s" coreProj.FullName) consoleProj.Directory.FullName
let sol = Path.Combine(rootDir.FullName, "FSharpLint.sln") |> FileInfo
exec "dotnet" (sprintf "run lint %s" sol.FullName) consoleProj.Directory.FullName
)

// --------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ open TestUtils

[<TestFixture>]
type TestAst() =
let unionCaseName (x:'a) =
match FSharpValue.GetUnionFields(x, typeof<'a>) with
let unionCaseName (x:'T) =
match FSharpValue.GetUnionFields(x, typeof<'T>) with
| case, _ -> case.Name

let astToExpr ast =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ type TestBindingFavourIgnoreOverLetWild() =
this.Parse """
module Program

let _ = ()"""
let _ = ()
"""

Assert.IsTrue(this.ErrorExistsAt(4, 4))

Expand All @@ -22,8 +23,9 @@ let _ = ()"""
module Program

let (_) =
let x = 4 + 4
()"""
let x = 4 + 4
()
"""

Assert.IsTrue(this.ErrorExistsAt(4, 4))

Expand All @@ -32,7 +34,8 @@ let (_) =
this.Parse """
module Program

let ((((_)))) = List.iter (fun x -> ()) []"""
let ((((_)))) = List.iter (fun x -> ()) []
"""

Assert.IsTrue(this.ErrorExistsAt(4, 4))

Expand All @@ -41,7 +44,8 @@ let ((((_)))) = List.iter (fun x -> ()) []"""
this.Parse """
module Program

let a = List.iter (fun x -> ()) []"""
let a = List.iter (fun x -> ()) []
"""

Assert.IsFalse(this.ErrorsExist)

12 changes: 8 additions & 4 deletions tests/FSharpLint.Core.Tests/Rules/Binding/FavourTypedIgnore.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ type TestBindingFavourTypedIgnore() =
member this.``typed ignore has no error``() =
this.Parse
"""
Console.ReadLine() |> ignore<string>"""
Console.ReadLine() |> ignore<string>
"""

this.AssertNoWarnings()

[<Test>]
member this.``typed ignore has no error (without pipe)``() =
this.Parse
"""
ignore<string>(Console.ReadLine())"""
ignore<string>(Console.ReadLine())
"""

this.AssertNoWarnings()

Expand All @@ -28,7 +30,8 @@ Console.ReadLine() |> ignore<string>"""
this.Parse
"""
Console.ReadLine()
|> ignore"""
|> ignore
"""

Assert.IsTrue(this.ErrorsExist)
Assert.IsTrue(this.ErrorExistsAt(2, 0))
Expand All @@ -39,7 +42,8 @@ Console.ReadLine()
"""
ignore(
Console.ReadLine()
)"""
)
"""

Assert.IsTrue(this.ErrorsExist)
Assert.IsTrue(this.ErrorExistsAt(2, 0))
17 changes: 11 additions & 6 deletions tests/FSharpLint.Core.Tests/Rules/Binding/TupleOfWildcards.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ module Program
type Cat = | Persian of int * int

match Persian(1, 3) with
| Persian(_, _) -> ()"""
| Persian(_, _) -> ()
"""

Assert.IsTrue(this.ErrorExistsAt(7, 14))
Assert.IsTrue(this.ErrorExistsAt(7, 10))

[<Test>]
member this.``Method's parameter list of wildcards should not be treated as tuple of wildcards.``() =
this.Parse """
module Program

type Cat() =
member __.Persian(_, _) = ()"""
member __.Persian(_, _) = ()
"""

Assert.IsFalse(this.ErrorsExist)

Expand All @@ -37,7 +39,8 @@ module Program
type Cat() =
new(_, _) = Cat()

member __.Persian(_) = ()"""
member __.Persian(_) = ()
"""

Assert.IsFalse(this.ErrorsExist)

Expand All @@ -47,7 +50,8 @@ type Cat() =
module Program

type Cat() =
member __.Persian<'t>(_, _) = ()"""
member __.Persian<'t>(_, _) = ()
"""

Assert.IsFalse(this.ErrorsExist)

Expand All @@ -61,6 +65,7 @@ type I =

let x =
{ new I with
member __.Two(_, _) = false }"""
member __.Two(_, _) = false }
"""

Assert.IsFalse(this.ErrorsExist)
21 changes: 13 additions & 8 deletions tests/FSharpLint.Core.Tests/Rules/Binding/UselessBinding.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ type TestBindingUselessBinding() =

[<Test>]
member this.UselessBinding() =
this.Parse("""
this.Parse """
module Program

let a = 10
let a = a""")
let a = a
"""

Assert.IsTrue(this.ErrorExistsAt(5, 4))

Expand All @@ -23,7 +24,8 @@ let a = a""")
module Program

let mutable a = 10
let a = a"""
let a = a
"""

Assert.IsFalse(this.ErrorsExist)

Expand All @@ -33,30 +35,33 @@ let a = a"""
module Program

let a = 10
let mutable a = a"""
let mutable a = a
"""

Assert.IsFalse(this.ErrorsExist)

[<Test>]
member this.UselessBindingWithParens() =
this.Parse("""
this.Parse """
module Program

let a = 10
let ((a)) = ((a))""")
let ((a)) = ((a))
"""

Assert.IsTrue(this.ErrorExistsAt(5, 4))

/// Regression test for https://github.com/fsprojects/FSharpLint/issues/101
/// (a use binding will dispose the value so is not useless)
[<Test>]
member this.UseBindingWithSameNameDoesNotCauseUselessBindingError() =
this.Parse("""
this.Parse """
module Program

type Cat() =
static member CreateList(reader:TextReader) =
use reader = reader
reader.ReadToEnd()""")
reader.ReadToEnd()
"""

Assert.IsFalse(this.ErrorsExist)
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ type TestBindingWildcardNamedWithAsPattern() =
module Program

match [] with
| _ as x -> ()"""
| _ as x -> ()
"""

Assert.IsTrue(this.ErrorExistsAt(5, 6))
Assert.IsTrue(this.ErrorExistsAt(5, 2))

[<Test>]
member this.NamedPattern() =
this.Parse """
module Program

match [] with
| x -> ()"""
| x -> ()
"""

Assert.IsFalse(this.ErrorsExist)

Expand All @@ -33,7 +35,8 @@ match [] with
module Program

match [] with
| _ -> ()"""
| _ -> ()
"""

Assert.IsFalse(this.ErrorsExist)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ type TestAsyncExceptionWithoutReturn() =
[<Test>]
member this.AsyncRaiseWithoutReturn() =
this.Parse("""
namespace Program
module Program

let someAsyncFunction =
let someAsyncFunction () =
async {
raise (new System.Exception("An error occurred."))
return true
Expand All @@ -24,9 +24,9 @@ let someAsyncFunction =
[<Test>]
member this.AsyncRaiseWithReturn() =
this.Parse("""
namespace Program
module Program

let someAsyncFunction =
let someAsyncFunction () =
async {
return raise (new System.Exception("An error occurred."))
}""")
Expand All @@ -36,9 +36,9 @@ let someAsyncFunction =
[<Test>]
member this.AsyncFailWithWithoutReturn() =
this.Parse("""
namespace Program
module Program

let someAsyncFunction =
let someAsyncFunction () =
async {
failwith "An error occurred."
return true
Expand All @@ -47,11 +47,11 @@ let someAsyncFunction =
Assert.IsTrue this.ErrorsExist

[<Test>]
member this.AsyncFailwithfWithoutReturn_1() =
member this.AsyncFailwithfWithoutReturn1() =
this.Parse("""
namespace Program
module Program

let someAsyncFunction =
let someAsyncFunction () =
async {
let errCode = 78
failwithf "Dummy Error Message: %i" errCode
Expand All @@ -61,11 +61,11 @@ let someAsyncFunction =
Assert.IsTrue this.ErrorsExist

[<Test>]
member this.AsyncFailwithfWithoutReturn_2() =
member this.AsyncFailwithfWithoutReturn2() =
this.Parse("""
namespace Program
module Program

let someAsyncFunction =
let someAsyncFunction () =
async {
let errCode = 78
failwithf "Dummy Error Message: %i" errCode
Expand All @@ -76,9 +76,9 @@ let someAsyncFunction =
[<Test>]
member this.AsyncFailwithWithReturn() =
this.Parse("""
namespace Program
module Program

let someAsyncFunction =
let someAsyncFunction () =
async {
return failwith "An error occurred."
}""")
Expand All @@ -88,9 +88,9 @@ let someAsyncFunction =
[<Test>]
member this.AsyncFailwithfWithReturn() =
this.Parse("""
namespace Program
module Program

let someAsyncFunction =
let someAsyncFunction () =
async {
let errCode = 78
return failwithf "Dummy Error Message: %i" errCode
Expand All @@ -101,9 +101,9 @@ let someAsyncFunction =
[<Test>]
member this.AsyncRaiseWithReturnInnerExpression() =
this.Parse("""
namespace Program
module Program

let someAsyncFunction =
let someAsyncFunction () =
async {
if 2 = 2 then
return raise (new System.Exception("An error occurred."))
Expand All @@ -116,9 +116,9 @@ let someAsyncFunction =
[<Test>]
member this.AsyncRaiseWithoutReturnInnerExpression() =
this.Parse("""
namespace Program
module Program

let someAsyncFunction =
let someAsyncFunction () =
async {
if 2 = 2 then
raise (new System.Exception("An error occurred."))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type CustomerName(firstName) =
member this.someFunc someParam =
someParam
|> someOtherFunc
"""
"""

Assert.IsTrue <| this.ErrorExistsAt(5, 8)

Expand All @@ -71,7 +71,7 @@ type CustomerName(firstName) =
someParam
|> someOtherFunc
|> yetAnotherFunc
"""
"""

Assert.IsFalse this.ErrorsExist

Expand Down
Loading
Loading