Skip to content

Commit 81ccc0c

Browse files
authored
Merge PR #756 from webwarrior-ws/wip/RunOnItself
Enable more rules for SelfCheck, not just the ones enabled by default.
2 parents 2155f74 + 54ab0a3 commit 81ccc0c

File tree

123 files changed

+3365
-2311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+3365
-2311
lines changed

.git-blame-ignore-revs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@
33
# that they are unlikely to be what you are interested in when blaming.
44
# Like formatting with Fantomas
55
# https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view
6-
# Add formatting commits here
6+
7+
# Console,Core,Tests: fix FSharpLint warning (Fixing the warning for AvoidTooShortNames rule.)
8+
e9410e83af1de4d76230b0e8d44ae6a99fac6d7b
9+
10+
# Core: rename some funcs and params
11+
628b1786e7f913ecd87e42a45ab7f195c536a6cb
12+

build.fsx

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ open Fake.Api
3939

4040
open System
4141
open System.IO
42+
open System.Text.Json.Nodes
4243

4344
Target.initEnvironment()
4445

@@ -249,12 +250,64 @@ Target.create "Push" (fun _ ->
249250

250251

251252
Target.create "SelfCheck" (fun _ ->
252-
let srcDir = Path.Combine(rootDir.FullName, "src") |> DirectoryInfo
253-
254-
let consoleProj = Path.Combine(srcDir.FullName, "FSharpLint.Console", "FSharpLint.Console.fsproj") |> FileInfo
255-
let sol = Path.Combine(rootDir.FullName, solutionFileName) |> FileInfo
256-
exec "dotnet" $"run --framework net9.0 lint %s{sol.FullName}" consoleProj.Directory.FullName
257-
)
253+
let runLinter () =
254+
let srcDir = Path.Combine(rootDir.FullName, "src") |> DirectoryInfo
255+
256+
let consoleProj = Path.Combine(srcDir.FullName, "FSharpLint.Console", "FSharpLint.Console.fsproj") |> FileInfo
257+
let sol = Path.Combine(rootDir.FullName, solutionFileName) |> FileInfo
258+
259+
exec "dotnet" $"run --framework net9.0 lint %s{sol.FullName}" consoleProj.Directory.FullName
260+
261+
printfn "Running self-check with default rules..."
262+
runLinter ()
263+
264+
let fsharplintJsonDir = Path.Combine("src", "FSharpLint.Core", "fsharplint.json")
265+
let fsharplintJsonText = File.ReadAllText fsharplintJsonDir
266+
267+
let excludedRules =
268+
[
269+
// Formatting rules (maybe mark them as DEPRECATED soon, recommending the use of `fantomas` instead)
270+
"typedItemSpacing"
271+
"unionDefinitionIndentation"
272+
"moduleDeclSpacing"
273+
"classMemberSpacing"
274+
"tupleCommaSpacing"
275+
"tupleIndentation"
276+
"patternMatchClausesOnNewLine"
277+
"patternMatchOrClausesOnNewLine"
278+
"patternMatchClauseIndentation"
279+
"patternMatchExpressionIndentation"
280+
"indentation"
281+
"maxCharactersOnLine"
282+
"trailingNewLineInFile"
283+
"trailingWhitespaceOnLine"
284+
285+
// TODO: we should enable at some point
286+
"typePrefixing"
287+
"unnestedFunctionNames"
288+
"nestedFunctionNames"
289+
"nestedStatements"
290+
291+
// Running NoPartialFunctions on this file causes a bug in FSharp.Compiler, so skip it for now
292+
"noPartialFunctions"
293+
294+
// rule is too complex, we can enable it later
295+
"cyclomaticComplexity"
296+
]
297+
298+
let jsonObj = JsonObject.Parse fsharplintJsonText
299+
300+
for pair in jsonObj.AsObject() do
301+
if pair.Value.GetValueKind() = Text.Json.JsonValueKind.Object then
302+
match pair.Value.AsObject().TryGetPropertyValue("enabled") with
303+
| true, isRule when not (List.contains pair.Key excludedRules) ->
304+
isRule.AsValue().ReplaceWith true
305+
| _ -> ()
306+
307+
File.WriteAllText(fsharplintJsonDir, jsonObj.ToJsonString())
308+
309+
printfn "Now re-running self-check with more rules enabled..."
310+
runLinter ())
258311

259312
// --------------------------------------------------------------------------------------
260313
// Build order

src/FSharpLint.Console/Output.fs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type StandardOutput () =
2323
if String.length errorLine = 0 then "^"
2424
else
2525
errorLine
26-
|> Seq.mapi (fun i _ -> if i = range.StartColumn then "^" else " ")
26+
|> Seq.mapi (fun index _ -> if index = range.StartColumn then "^" else " ")
2727
|> Seq.reduce (+)
2828
$"{getErrorMessage range}{Environment.NewLine}{errorLine}{Environment.NewLine}{highlightColumnLine}"
2929

@@ -59,5 +59,4 @@ type MSBuildOutput () =
5959
<| warning.RuleIdentifier
6060
<| warning.Details.Message
6161
member _.WriteError (error:string) =
62-
$"FSharpLint error: {error}"
63-
|> Console.Error.WriteLine
62+
Console.Error.WriteLine $"FSharpLint error: {error}"

src/FSharpLint.Console/Program.fs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ let private parserProgress (output:Output.IOutput) = function
5656
String.Format(Resources.GetString("ConsoleFinishedFile"), List.length warnings) |> output.WriteInfo
5757
| Failed (file, parseException) ->
5858
String.Format(Resources.GetString("ConsoleFailedToParseFile"), file) |> output.WriteError
59-
$"Exception Message:{Environment.NewLine}{parseException.Message}{Environment.NewLine}Exception Stack Trace:{Environment.NewLine}{parseException.StackTrace}{Environment.NewLine}"
60-
|> output.WriteError
59+
output.WriteError
60+
$"Exception Message:{Environment.NewLine}{parseException.Message}{Environment.NewLine}Exception Stack Trace:{Environment.NewLine}{parseException.StackTrace}{Environment.NewLine}"
6161

6262
/// Infers the file type of the target based on its file extension.
6363
let internal inferFileType (target:string) =
@@ -84,7 +84,7 @@ let private start (arguments:ParseResults<ToolArgs>) (toolsPath:Ionide.ProjInfo.
8484
let version =
8585
Assembly.GetExecutingAssembly().GetCustomAttributes false
8686
|> Seq.pick (function | :? AssemblyInformationalVersionAttribute as aiva -> Some aiva.InformationalVersion | _ -> None)
87-
$"Current version: {version}" |> output.WriteInfo
87+
output.WriteInfo $"Current version: {version}"
8888
Environment.Exit 0
8989

9090
let handleError (str:string) =
@@ -129,10 +129,10 @@ let private start (arguments:ParseResults<ToolArgs>) (toolsPath:Ionide.ProjInfo.
129129
| _ -> Lint.lintProject lintParams target toolsPath
130130
handleLintResult lintResult
131131
with
132-
| e ->
132+
| exn ->
133133
let target = if fileType = FileType.Source then "source" else target
134-
$"Lint failed while analysing %s{target}.{Environment.NewLine}Failed with: %s{e.Message}{Environment.NewLine}Stack trace: {e.StackTrace}"
135-
|> handleError
134+
handleError
135+
$"Lint failed while analysing %s{target}.{Environment.NewLine}Failed with: %s{exn.Message}{Environment.NewLine}Stack trace: {exn.StackTrace}"
136136
| _ -> ()
137137

138138
exitCode

0 commit comments

Comments
 (0)