Skip to content

run the analyzers we just build on the code itself #65

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ jobs:
uses: actions/setup-dotnet@v3
- name: Build
run: dotnet fsi build.fsx
- name: "Run analyzers"
run: dotnet msbuild /t:AnalyzeSolution
continue-on-error: true
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: analysisreports
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,7 @@ tests/data/**/*.actual
# fsdocs
.fsdocs/
tmp/
output/
output/

# Analyzer files
*.sarif
7 changes: 7 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,11 @@
<PackageReference Include="Ionide.KeepAChangelog.Tasks" PrivateAssets="all"/>
<PackageReference Include="DotNet.ReproducibleBuilds" PrivateAssets="all"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="FSharp.Analyzers.Build">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>build</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project>
<PropertyGroup>
<CodeRoot Condition="$(CodeRoot) == ''">.</CodeRoot>
<FSharpAnalyzersOtherFlags>--analyzers-path &quot;./bin/Release/net6.0&quot;</FSharpAnalyzersOtherFlags>
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --exclude-analyzers PartialAppAnalyzer</FSharpAnalyzersOtherFlags>
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --treat-as-warning GRA-STRING-001 GRA-STRING-002 GRA-STRING-003 GRA-UNIONCASE-001 GRA-VIRTUALCALL-001 GRA-TYPE-ANNOTATE-001 GRA-UNIONCASE-001</FSharpAnalyzersOtherFlags>
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --verbosity d</FSharpAnalyzersOtherFlags>
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --code-root $(CodeRoot)</FSharpAnalyzersOtherFlags>
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --report &quot;$(CodeRoot)/analysisreports/$(MSBuildProjectName)-analysis.sarif&quot;</FSharpAnalyzersOtherFlags>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageVersion Include="NUnit" Version="4.0.1" />
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="FSharp.Analyzers.Build" Version="0.2.0" />
</ItemGroup>
</Project>
17 changes: 17 additions & 0 deletions Directory.Solution.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project>

<ItemGroup>
<ProjectsToAnalyze Include="src/**/*.fsproj" />
</ItemGroup>

<Target Name="AnalyzeSolution">
<PropertyGroup>
<CodeRoot>$(SolutionDir)</CodeRoot>
</PropertyGroup>
<RemoveDir Directories="$(SolutionDir)/analysisreports" />
<MSBuild Projects="@(ProjectsToAnalyze)"
Targets="AnalyzeFSharpProject"
Properties="CodeRoot=$(CodeRoot)" ContinueOnError="true" />
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let (|StringConst|_|) (e : FSharpExpr) =
let name = e.Type.ErasedType.TypeDefinition.TryGetFullName ()

match name, e with
| Some ("System.String"), Const (o, _type) when not (isNull o) -> Some (string o)
| Some ("System.String"), Const (o, _type) when not (isNull o) -> Some (string<obj> o)
| _ -> None


Expand Down
6 changes: 3 additions & 3 deletions src/FSharp.Analyzers/PartialAppAnalyzer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ let collectPipedArgs (pipeHandler : PipeHandler) (funcExpr : SynExpr) (argExpr :
match funcExpr with
| SynExpr.App (funcExpr = SynExpr.LongIdent (longDotId = longDotId) ; argExpr = argExpr2) ->
longDotId.LongIdent
|> Seq.tryHead
|> List.tryHead
|> Option.iter (fun i ->
let pipedArgs, target =
match i.idText with
Expand Down Expand Up @@ -85,7 +85,7 @@ let rec visitApp (handlers : Handlers) (depth : int) (expr : SynExpr) =
| SynExpr.App (funcExpr = SynExpr.Ident i) -> handlers.AppHandler (i.idText, i.idRange, 1 + depth)
| SynExpr.App (funcExpr = SynExpr.LongIdent (longDotId = longDotId) ; argExpr = argExpr) ->
longDotId.IdentsWithTrivia
|> Seq.tryLast
|> List.tryLast
|> Option.iter (fun (SynIdent.SynIdent (ident = ident)) ->
handlers.AppHandler (ident.idText, longDotId.Range, 1 + depth)
)
Expand All @@ -99,7 +99,7 @@ let rec visitApp (handlers : Handlers) (depth : int) (expr : SynExpr) =
handlers.AppHandler (i.idText, i.idRange, 1 + depth)
| SynExpr.App (funcExpr = SynExpr.TypeApp (expr = SynExpr.LongIdent (longDotId = longDotId))) ->
longDotId.IdentsWithTrivia
|> Seq.tryLast
|> List.tryLast
|> Option.iter (fun (SynIdent.SynIdent (ident = ident)) ->
handlers.AppHandler (ident.idText, longDotId.Range, 1 + depth)
)
Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Analyzers/StringAnalyzer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ let invalidStringFunctionUseAnalyzer
invocations
|> Seq.map (fun mFunctionName ->
{
Type = $"String.{functionName} analyzer"
Type = $"String.%s{functionName} analyzer"
Message = message
Code = code
Severity = severity
Expand Down