From 61d6c020022bd6a3941977033246107abab3b6ea Mon Sep 17 00:00:00 2001 From: nojaf Date: Mon, 8 Sep 2025 10:41:31 +0200 Subject: [PATCH 1/4] Run analyzers for all projects --- .config/dotnet-tools.json | 2 +- .github/workflows/pull-requests.yml | 2 +- .gitignore | 2 +- Directory.Packages.props | 5 ++--- Directory.Solution.targets | 31 ++++++++++++++++++++++------- src/Directory.Build.props | 4 ---- src/Directory.Build.targets | 8 -------- 7 files changed, 29 insertions(+), 25 deletions(-) delete mode 100644 src/Directory.Build.targets diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index d31c2ebd5..94a9edcc6 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -9,7 +9,7 @@ ] }, "fsharp-analyzers": { - "version": "0.26.0", + "version": "0.32.1", "commands": [ "fsharp-analyzers" ] diff --git a/.github/workflows/pull-requests.yml b/.github/workflows/pull-requests.yml index 87dae709d..82ea50027 100644 --- a/.github/workflows/pull-requests.yml +++ b/.github/workflows/pull-requests.yml @@ -34,4 +34,4 @@ jobs: uses: github/codeql-action/upload-sarif@v3 if: matrix.os == 'ubuntu-latest' with: - sarif_file: ./reports + sarif_file: ./analysis.sarif diff --git a/.gitignore b/.gitignore index dd9927a30..eb79946e5 100644 --- a/.gitignore +++ b/.gitignore @@ -50,4 +50,4 @@ tests/FSharp.Literate.Tests/output2/ tests/FSharp.Literate.Tests/previous-next-output/ # Analyzer -reports/ \ No newline at end of file +analysis.sarif \ No newline at end of file diff --git a/Directory.Packages.props b/Directory.Packages.props index 481969f41..0f6a9d08e 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -26,8 +26,7 @@ - - - + + \ No newline at end of file diff --git a/Directory.Solution.targets b/Directory.Solution.targets index 33bbc1ddd..c6cc36c5c 100644 --- a/Directory.Solution.targets +++ b/Directory.Solution.targets @@ -1,9 +1,26 @@ - - - + + - - - - \ No newline at end of file + + + + + + + $(SolutionDir) + --analyzers-path "$(PkgG-Research_FSharp_Analyzers)/analyzers/dotnet/fs" + $(FSharpAnalyzersOtherFlags) --analyzers-path "$(PkgIonide_Analyzers)/analyzers/dotnet/fs" + $(FSharpAnalyzersOtherFlags) --exclude-analyzers PartialAppAnalyzer ReturnStructPartialActivePatternAnalyzer -c Release + $(FSharpAnalyzersOtherFlags) --code-root $(CodeRoot) + $(FSharpAnalyzersOtherFlags) --report "$(CodeRoot)/analysis.sarif" + + + + + + + diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 4839b530e..108bfc06a 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,10 +1,6 @@ - - all - build - all analyzers diff --git a/src/Directory.Build.targets b/src/Directory.Build.targets deleted file mode 100644 index dbe79b390..000000000 --- a/src/Directory.Build.targets +++ /dev/null @@ -1,8 +0,0 @@ - - - --analyzers-path "$(PkgG-Research_FSharp_Analyzers)/analyzers/dotnet/fs" - $(FSharpAnalyzersOtherFlags) --analyzers-path "$(PkgIonide_Analyzers)/analyzers/dotnet/fs" - $(FSharpAnalyzersOtherFlags) --exclude-analyzers PartialAppAnalyzer -c Release - $(FSharpAnalyzersOtherFlags) --code-root ../.. --report "../../reports/$(MSBuildProjectName)-$(TargetFramework).sarif" - - \ No newline at end of file From be3fbca39752834f2607fd0e599c08a2aea93f6a Mon Sep 17 00:00:00 2001 From: nojaf Date: Mon, 8 Sep 2025 10:59:19 +0200 Subject: [PATCH 2/4] Avoid double filter --- .../YaafFSharpScripting.fs | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/FSharp.Formatting.Common/YaafFSharpScripting.fs b/src/FSharp.Formatting.Common/YaafFSharpScripting.fs index 6e32a3310..bc8178be9 100644 --- a/src/FSharp.Formatting.Common/YaafFSharpScripting.fs +++ b/src/FSharp.Formatting.Common/YaafFSharpScripting.fs @@ -282,14 +282,18 @@ module internal CompilerServiceExtensions = |> Seq.filter (fun file -> let fileName = Path.GetFullPath file |> Path.GetFileName - dllFiles - |> List.exists (fun (dllFile: string) -> Path.GetFileName dllFile =? fileName) - |> not) - |> Seq.filter (fun file -> - if Path.GetFileName file =? "FSharp.Core.dll" then - FSharpAssemblyHelper.tryCheckFsCore file |> Option.isSome - else - true) + let dllNotAlreadyReferenced = + dllFiles + |> List.exists (fun (dllFile: string) -> Path.GetFileName dllFile =? fileName) + |> not + + let checkFSharpCore = + if Path.GetFileName file =? "FSharp.Core.dll" then + FSharpAssemblyHelper.tryCheckFsCore file |> Option.isSome + else + true + + dllNotAlreadyReferenced && checkFSharpCore) |> Seq.toList // See https://github.com/tpetricek/FSharp.Formatting/commit/5d14f45cd7e70c2164a7448ea50a6b9995166489 @@ -350,7 +354,6 @@ type internal FsiEvaluationException (Log.formatArgs args) (base.ToString()) - /// Exception for invalid expression types type internal FsiExpressionTypeException = val private value: obj option From f732d0b21bc84e906efb47dd4d14783ee373892e Mon Sep 17 00:00:00 2001 From: nojaf Date: Mon, 8 Sep 2025 11:04:27 +0200 Subject: [PATCH 3/4] Fix string analyzers --- src/FSharp.Formatting.ApiDocs/GenerateModel.fs | 4 ++-- src/FSharp.Formatting.Literate/ParseScript.fs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs index d7cba7207..c1c7272fd 100644 --- a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs +++ b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs @@ -870,7 +870,7 @@ type internal CrossReferenceResolver(root, collectionName, qualify, extensions) let tryGetTypeFromMemberName (memberName: string) = let sub = removeParen memberName - let lastPeriod = sub.LastIndexOf(".") + let lastPeriod = sub.LastIndexOf('.') if lastPeriod > 0 then Some(memberName.Substring(0, lastPeriod)) @@ -879,7 +879,7 @@ type internal CrossReferenceResolver(root, collectionName, qualify, extensions) let tryGetShortMemberNameFromMemberName (memberName: string) = let sub = removeParen memberName - let lastPeriod = sub.LastIndexOf(".") + let lastPeriod = sub.LastIndexOf('.') if lastPeriod > 0 then Some(memberName.Substring(lastPeriod + 1)) diff --git a/src/FSharp.Formatting.Literate/ParseScript.fs b/src/FSharp.Formatting.Literate/ParseScript.fs index e1136dd79..8873edd43 100644 --- a/src/FSharp.Formatting.Literate/ParseScript.fs +++ b/src/FSharp.Formatting.Literate/ParseScript.fs @@ -62,7 +62,7 @@ module internal CodeBlockUtils = let rec private collectComment (comment: string) lines = seq { let findCommentEnd (comment: string) = - let cend = comment.LastIndexOf("*)") + let cend = comment.LastIndexOf("*)", StringComparison.OrdinalIgnoreCase) if cend = -1 then failwith "A (* comment was not closed" From 72659b0c8ff0a1d2e27c59783e035e417b7bdac9 Mon Sep 17 00:00:00 2001 From: nojaf Date: Mon, 8 Sep 2025 11:04:45 +0200 Subject: [PATCH 4/4] Avoid multiple filters --- src/FSharp.Formatting.ApiDocs/Categorise.fs | 34 ++++++++++++--------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/FSharp.Formatting.ApiDocs/Categorise.fs b/src/FSharp.Formatting.ApiDocs/Categorise.fs index 40202f73b..d107d1936 100644 --- a/src/FSharp.Formatting.ApiDocs/Categorise.fs +++ b/src/FSharp.Formatting.ApiDocs/Categorise.fs @@ -53,28 +53,32 @@ let entities (nsIndex: int, ns: ApiDocNamespace, suppress) = // TODO: use to do these, or work out if there's a better way if suppress then categoryEntities - - // Remove FSharp.Data.UnitSystems.SI from the list-of-namespaces - // display - it's just so rarely used, has long names and dominates the docs. - // - // See https://github.com/fsharp/fsharp-core-docs/issues/57, we may rethink this - |> List.filter (fun e -> - (e.Symbol.Namespace <> Some "Microsoft.FSharp.Data.UnitSystems.SI.UnitSymbols")) - |> List.filter (fun e -> - (e.Symbol.Namespace <> Some "Microsoft.FSharp.Data.UnitSystems.SI.UnitNames")) - // Don't show 'AnonymousObject' in list-of-namespaces navigation |> List.filter (fun e -> + // Remove FSharp.Data.UnitSystems.SI from the list-of-namespaces + // display - it's just so rarely used, has long names and dominates the docs. + // + // See https://github.com/fsharp/fsharp-core-docs/issues/57, we may rethink this + (e.Symbol.Namespace <> Some "Microsoft.FSharp.Data.UnitSystems.SI.UnitSymbols") + && (e.Symbol.Namespace <> Some "Microsoft.FSharp.Data.UnitSystems.SI.UnitNames") + + && + + // Don't show 'AnonymousObject' in list-of-namespaces navigation not ( e.Symbol.Namespace = Some "Microsoft.FSharp.Linq.RuntimeHelpers" && e.Symbol.DisplayName = "AnonymousObject" - )) - // Don't show 'FSharp.Linq.QueryRunExtensions' in list-of-namespaces navigation - |> List.filter (fun e -> + ) + + && + + // Don't show 'FSharp.Linq.QueryRunExtensions' in list-of-namespaces navigation not ( e.Symbol.Namespace = Some "Microsoft.FSharp.Linq.QueryRunExtensions" && e.Symbol.DisplayName = "LowPriority" - )) - |> List.filter (fun e -> + ) + + && + not ( e.Symbol.Namespace = Some "Microsoft.FSharp.Linq.QueryRunExtensions" && e.Symbol.DisplayName = "HighPriority"