Skip to content

Enable more rules for SelfCheck #668

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

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
954d0ad
build: run FSharpLint with 1 extra rule
Mersho Dec 12, 2023
0e32b2b
build: run FSharpLint with 1 extra rule
Mersho Dec 12, 2023
77f1e98
build: run FSharpLint with 1 extra rule
Mersho Dec 12, 2023
f2fd100
Core,Tests: fix FSharpLint warning
Mersho Dec 12, 2023
f90f5c9
build: run FSharpLint with 1 extra rule
Mersho Dec 12, 2023
2590f5e
build: run FSharpLint with 1 extra rule
Mersho Dec 12, 2023
bc87817
Core.Tests: fix FSharpLint warning
Mersho Feb 1, 2024
90d00ae
build: run FSharpLint with 1 extra rule
Mersho Dec 12, 2023
bdb1603
Core: fix FSharpLint warning
Mersho Dec 13, 2023
e5023f4
build: run FSharpLint with 1 extra rule
Mersho Dec 13, 2023
8a1e77b
Core.Tests: fix FSharpLint warning
Mersho Feb 1, 2024
bed8adb
build: run FSharpLint with 1 extra rule
Mersho Dec 13, 2023
af5a602
build: run FSharpLint with 1 extra rule
Mersho Dec 13, 2023
c4582c4
build: run FSharpLint with 1 extra rule
Mersho Dec 13, 2023
6cc467c
build: run FSharpLint with 1 extra rule
Mersho Dec 13, 2023
08a5943
build: run FSharpLint with 1 extra rule
Mersho Dec 13, 2023
81c80a6
build: run FSharpLint with 1 extra rule
Mersho Dec 13, 2023
f8b43f2
build: run FSharpLint with 1 extra rule
Mersho Dec 13, 2023
b15206d
build: run FSharpLint with 1 extra rule
Mersho Dec 13, 2023
aed1545
Core,Tests: fix FSharpLint warning
Mersho Dec 13, 2023
20d8a99
build: run FSharpLint with 1 extra rule
Mersho Dec 13, 2023
13e75e7
Core,Tests: fix FSharpLint warning
Mersho Dec 13, 2023
ba32ea2
build: run FSharpLint with 1 extra rule
Mersho Dec 13, 2023
5fff104
Core,Tests: fix FSharpLint warning
Mersho Dec 14, 2023
cb4c5be
build: run FSharpLint with 1 extra rule
Mersho Dec 13, 2023
c7fabb3
Console,Core,Tests: fix FSharpLint warning
Mersho Dec 13, 2023
0104b62
build: run FSharpLint with 1 extra rule
Mersho Dec 18, 2023
c0f6d6b
build: run FSharpLint with 1 extra rule
Mersho Dec 22, 2023
2fa5b46
build: run FSharpLint with 1 extra rule
Mersho Dec 22, 2023
41a11bd
Core,Tests: fix FSharpLint warning
Mersho Dec 22, 2023
43bc29a
build: run FSharpLint with 1 extra rule
Mersho Dec 25, 2023
b93274b
build: run FSharpLint with 1 extra rule
Mersho Dec 25, 2023
19f2341
build: run FSharpLint with 1 extra rule
knocte Jan 6, 2024
216d339
Core,Tests: fix FSharpLint warning
Mersho Jan 10, 2024
9116f2b
build: run FSharpLint with 1 extra rule
Mersho Dec 18, 2023
dbf2753
Console,Core: fix FSharpLint warning
Mersho Dec 21, 2023
6c4015f
build: run FSharpLint with 1 extra rule
Mersho Feb 8, 2024
d35cfb2
build: run FSharpLint with 1 extra rule
Mersho Feb 8, 2024
2f2ea51
Core: fix FSharpLint warning
Mersho Feb 8, 2024
ce44dc6
build: refactoring for rule activation
Mersho Feb 7, 2024
94a7827
tests: refactoring for DRY principle
Mersho Feb 8, 2024
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
59 changes: 53 additions & 6 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.Core.TargetOperators
open Fake.Api
open Newtonsoft.Json.Linq

open System
open System.IO
Expand Down Expand Up @@ -209,12 +210,58 @@ Target.create "Push" (fun _ ->


Target.create "SelfCheck" (fun _ ->
let srcDir = Path.Combine(rootDir.FullName, "src") |> DirectoryInfo

let consoleProj = Path.Combine(srcDir.FullName, "FSharpLint.Console", "FSharpLint.Console.fsproj") |> FileInfo
let sol = Path.Combine(rootDir.FullName, "FSharpLint.sln") |> FileInfo
exec "dotnet" (sprintf "run lint %s" sol.FullName) consoleProj.Directory.FullName
)
let runLinter () =
let srcDir = Path.Combine(rootDir.FullName, "src") |> DirectoryInfo

let consoleProj =
Path.Combine(srcDir.FullName, "FSharpLint.Console", "FSharpLint.Console.fsproj")
|> FileInfo

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

printfn "Running self-check with default rules..."
runLinter ()

let fsharplintJsonDir = Path.Combine("src", "FSharpLint.Core", "fsharplint.json")
let fsharplintJsonText = File.ReadAllText fsharplintJsonDir

let excludedRules =
[
"typedItemSpacing"
"typePrefixing"
"unionDefinitionIndentation"
"moduleDeclSpacing"
"classMemberSpacing"
"tupleCommaSpacing"
"tupleIndentation"
"tupleParentheses"
"patternMatchClausesOnNewLine"
"patternMatchOrClausesOnNewLine"
"patternMatchClauseIndentation"
"patternMatchExpressionIndentation"
// rule is too complex and we can enable it later
"cyclomaticComplexity"
"unnestedFunctionNames"
"nestedFunctionNames"
"indentation"
"maxCharactersOnLine"
"trailingWhitespaceOnLine"
"trailingNewLineInFile"
]

let jsonObj = JObject.Parse fsharplintJsonText

for pair in jsonObj do
let isRule = (jsonObj.SelectToken pair.Key).SelectToken("enabled")

if not (isNull isRule) && not (List.contains pair.Key excludedRules) then
isRule.Replace(JValue true) |> ignore<unit>

File.WriteAllText(fsharplintJsonDir, jsonObj.ToString())

printfn "Now re-running self-check with more rules enabled..."
runLinter ())

// --------------------------------------------------------------------------------------
// Build order
Expand Down
3 changes: 2 additions & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ nuget Argu
nuget BenchmarkDotNet
nuget BenchmarkDotNet.Diagnostics.Windows
nuget FParsec
nuget FSharpx.Collections
nuget FSharp.Compiler.Service ~> 41.0.1
nuget Ionide.ProjInfo.ProjectSystem == 0.61.3
nuget Ionide.ProjInfo.FCS == 0.61.3
Expand Down Expand Up @@ -60,4 +61,4 @@ group Build
nuget Fake.Core.UserInput
nuget Fake.IO.FileSystem
nuget Fake.DotNet.MsBuild
nuget Fake.Api.GitHub
nuget Fake.Api.GitHub
2 changes: 2 additions & 0 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ NUGET
FSharp.Core (>= 4.7.2)
System.Reactive (>= 5.0 < 6.0)
FSharp.Core (6.0.7)
FSharpx.Collections (3.1)
FSharp.Core (>= 4.3.4)
Gee.External.Capstone (2.3)
Iced (1.20)
Ionide.ProjInfo (0.61.3)
Expand Down
4 changes: 2 additions & 2 deletions src/FSharpLint.Console/Output.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type StandardOutput () =
if String.length errorLine = 0 then "^"
else
errorLine
|> Seq.mapi (fun i _ -> if i = range.StartColumn then "^" else " ")
|> Seq.reduce (+)
|> Seq.mapi (fun index _ -> if index = range.StartColumn then "^" else " ")
|> Seq.fold (+) String.Empty
getErrorMessage range + Environment.NewLine + errorLine + Environment.NewLine + highlightColumnLine

let writeLine (str:string) (color:ConsoleColor) (writer:IO.TextWriter) =
Expand Down
10 changes: 6 additions & 4 deletions src/FSharpLint.Console/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ let private start (arguments:ParseResults<ToolArgs>) (toolsPath:Ionide.ProjInfo.
if arguments.Contains ToolArgs.Version then
let version =
Assembly.GetExecutingAssembly().GetCustomAttributes false
|> Seq.pick (function | :? AssemblyInformationalVersionAttribute as aiva -> Some aiva.InformationalVersion | _ -> None)
sprintf "Current version: %s" version |> output.WriteInfo
|> Seq.tryPick (function | :? AssemblyInformationalVersionAttribute as aiva -> Some aiva.InformationalVersion | _ -> None)
match version with
| Some ver -> sprintf "Current version: %s" ver |> output.WriteInfo
| None -> output.WriteInfo "No version information found in assembly attributes."
()

let handleError (str:string) =
Expand Down Expand Up @@ -132,9 +134,9 @@ let private start (arguments:ParseResults<ToolArgs>) (toolsPath:Ionide.ProjInfo.
| _ -> Lint.lintProject lintParams target toolsPath
handleLintResult lintResult
with
| e ->
| exn ->
let target = if fileType = FileType.Source then "source" else target
sprintf "Lint failed while analysing %s.\nFailed with: %s\nStack trace: %s" target e.Message e.StackTrace
sprintf "Lint failed while analysing %s.\nFailed with: %s\nStack trace: %s" target exn.Message exn.StackTrace
|> handleError
| _ -> ()

Expand Down
Loading