-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3671 from nojaf/logging
Revist logging
- Loading branch information
Showing
18 changed files
with
338 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<CodeRoot>$([System.IO.Path]::GetDirectoryName($(DirectoryBuildTargetsPath)))</CodeRoot> | ||
<FSharpAnalyzersOtherFlags>--analyzers-path "$(PkgG-Research_FSharp_Analyzers)/analyzers/dotnet/fs"</FSharpAnalyzersOtherFlags> | ||
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --analyzers-path "$(PkgIonide_Analyzers)/analyzers/dotnet/fs"</FSharpAnalyzersOtherFlags> | ||
<CodeRoot>$([System.IO.Path]::GetDirectoryName($(DirectoryBuildTargetsPath)))</CodeRoot> | ||
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --analyzers-path "$(CodeRoot)/Fable.Analyzers/bin/Release/net6.0"</FSharpAnalyzersOtherFlags> | ||
<SarifOutput>$(CodeRoot)/reports/</SarifOutput> | ||
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --code-root "$(CodeRoot)"</FSharpAnalyzersOtherFlags> | ||
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --report "$(SarifOutput)$(MSBuildProjectName)-$(TargetFramework).sarif"</FSharpAnalyzersOtherFlags> | ||
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --exclude-analyzer PartialAppAnalyzer</FSharpAnalyzersOtherFlags> | ||
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --exclude-analyzers PartialAppAnalyzer</FSharpAnalyzersOtherFlags> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="StdOutAnalyzer.fs"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Update="FSharp.Core" Version="8.0.100"/> | ||
<PackageReference Include="FSharp.Analyzers.SDK" Version="0.23.0"/> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
module Fable.Analyzers.StdOutAnalyzer | ||
|
||
open System | ||
open FSharp.Analyzers.SDK.TASTCollecting | ||
open FSharp.Compiler.Symbols | ||
open FSharp.Compiler.Text | ||
open FSharp.Analyzers.SDK | ||
|
||
let namesToAvoid = | ||
set | ||
[ | ||
"System.Console.Write" | ||
"System.Console.WriteLine" | ||
"System.Console.WriteAsync" | ||
"System.Console.WriteLineAsync" | ||
"Microsoft.FSharp.Core.ExtraTopLevelOperators.printf" | ||
"Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn" | ||
] | ||
|
||
[<CliAnalyzer "StdOutAnalyzer">] | ||
let stdOutAnalyzer: Analyzer<CliContext> = | ||
fun (context: CliContext) -> | ||
async { | ||
let usages = ResizeArray<range * string>() | ||
|
||
let walker = | ||
{ new TypedTreeCollectorBase() with | ||
override _.WalkCall | ||
_ | ||
(m: FSharpMemberOrFunctionOrValue) | ||
_ | ||
_ | ||
(args: FSharpExpr list) | ||
(range: range) | ||
= | ||
match m.DeclaringEntity with | ||
| None -> () | ||
| Some de -> | ||
let name = | ||
String.Join(".", de.FullName, m.DisplayName) | ||
|
||
if Set.contains name namesToAvoid then | ||
usages.Add(range, m.DisplayName) | ||
} | ||
|
||
Option.iter (walkTast walker) context.TypedTree | ||
|
||
return | ||
usages | ||
|> Seq.map (fun (m, name) -> | ||
{ | ||
Type = "StdOut analyzer" | ||
Message = | ||
$"Writing to the standard output from this location should absolutely be avoided. Replace `%s{name}` with an ILogger call." | ||
Code = "FABLE_001" | ||
Severity = Error | ||
Range = m | ||
Fixes = [] | ||
} | ||
) | ||
|> Seq.toList | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.