Skip to content

Commit

Permalink
Add support for FSharpLint and fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
vipentti committed Dec 26, 2023
1 parent fd3ad22 commit 45be98e
Show file tree
Hide file tree
Showing 10 changed files with 567 additions and 57 deletions.
6 changes: 6 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
"commands": [
"dotnet-csharpier"
]
},
"dotnet-fsharplint": {
"version": "0.21.10",
"commands": [
"dotnet-fsharplint"
]
}
}
}
4 changes: 4 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@
"enum": [
"CheckCsharpier",
"CheckFantomas",
"CheckFSharpLint",
"Compile",
"FormatCsharpier",
"FormatFantomas",
"InstallCsharpier",
"InstallFantomas",
"InstallFSharpLint",
"InstallLinters",
"Lint",
"Pack",
Expand All @@ -106,11 +108,13 @@
"enum": [
"CheckCsharpier",
"CheckFantomas",
"CheckFSharpLint",
"Compile",
"FormatCsharpier",
"FormatFantomas",
"InstallCsharpier",
"InstallFantomas",
"InstallFSharpLint",
"InstallLinters",
"Lint",
"Pack",
Expand Down
54 changes: 51 additions & 3 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using Nuke.Common;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.Execution;
Expand All @@ -22,11 +23,11 @@
GitHubActionsImage.WindowsServer2019,
GitHubActionsImage.UbuntuLatest,
GitHubActionsImage.MacOsLatest,
OnPullRequestBranches = [ MainBranch, DevelopBranch ],
OnPushBranches = [ MainBranch, DevelopBranch ],
OnPullRequestBranches = [MainBranch, DevelopBranch],
OnPushBranches = [MainBranch, DevelopBranch],
PublishArtifacts = false
// FetchDepth = 0 // fetch full history
, SetupDotnetVersions = [ "8.x", ]
, SetupDotnetVersions = ["8.x",]
, InvokedTargets = [
nameof(ITest.Test),
nameof(IUseLinters.InstallLinters),
Expand All @@ -37,6 +38,7 @@ class Build :
NukeBuild,
IUseCsharpier,
IUseFantomas,
IUseFSharpLint,
IUseCustomLinters,
IHazSolution,
ITest,
Expand Down Expand Up @@ -68,6 +70,7 @@ public T From<T>()

bool IUseCsharpier.UseGlobalTool => false;
bool IUseFantomas.UseGlobalTool => false;
bool IUseFSharpLint.UseGlobalTool => false;

IEnumerable<AbsolutePath> IUseFantomas.DirectoriesToFormat => new[]
{
Expand All @@ -79,6 +82,7 @@ public T From<T>()
{
From<IUseCsharpier>().Linter,
From<IUseFantomas>().Linter,
From<IUseFSharpLint>().Linter,
};

// csharpier-ignore
Expand Down Expand Up @@ -135,6 +139,7 @@ from framework in TargetFrameworks
// csharpier-ignore
Configure<DotNetPackSettings> IPack.PackSettings => _ => _
.AddProperty("TargetsForTfmSpecificContentInPackage", "");

}

public interface IUseCustomLinters : INukeBuild
Expand Down Expand Up @@ -273,3 +278,46 @@ void RunFormat(AbsolutePath path)
}
}
}

public interface IUseFSharpLint : INukeBuild, IHazSolution
{
bool UseGlobalTool { get; }

IEnumerable<AbsolutePath> FilesToFormat => new[] { Solution.Path };

// csharpier-ignore
Target CheckFSharpLint => _ => _
.Executes(() => RunFSharpLint(check: true));

// csharpier-ignore
Target InstallFSharpLint => _ => _
.OnlyWhenDynamic(() => UseGlobalTool)
.Executes(ExecuteInstallGlobalFSharpLint);

sealed IProvideLinter Linter =>
new LinterDelegate(ExecuteInstallGlobalFSharpLint, () => RunFSharpLint(check: true));

sealed void ExecuteInstallGlobalFSharpLint()
{
if (UseGlobalTool)
{
DotNetToolUpdate(_ => _.SetGlobal(true).SetPackageName("dotnet-fsharplint"));
}
}

sealed void RunFSharpLint(bool check)
{
_ = check;
var toolname = UseGlobalTool ? "fsharplint" : "tool run dotnet-fsharplint";

FilesToFormat.ForEach(RunFormat);

void RunFormat(AbsolutePath path)
{
DotNet(
arguments: toolname + $" lint {path}",
logInvocation: true
);
}
}
}
Loading

0 comments on commit 45be98e

Please sign in to comment.