Skip to content
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

Introduce support for project specific framework types #156

Merged
merged 13 commits into from
Apr 2, 2024
Merged
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
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ dotnet_diagnostic.S1135.severity = suggestion # https://github.com/atc-net

dotnet_diagnostic.IDE0057.severity = none # Substring can be simplified

dotnet_diagnostic.SA1010.severity = none #

dotnet_diagnostic.CA1054.severity = none # URI parameters should not be strings
dotnet_diagnostic.CA1848.severity = none # For improved performance, use the LoggerMessage delegates instead of calling 'LoggerExtensions.LogTrace(ILogger, string, params object[])'
dotnet_diagnostic.CA1859.severity = none #
Expand Down
43 changes: 35 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This repository contains a CLI tool, which can be used to maintain `coding-rules
- [Options file schema / example](#options-file-schema--example)
- [atc-coding-rules-updater.json example 1](#atc-coding-rules-updaterjson-example-1)
- [atc-coding-rules-updater.json example 2](#atc-coding-rules-updaterjson-example-2)
- [atc-coding-rules-updater.json example 3](#atc-coding-rules-updaterjson-example-3)
- [atc-coding-rules-updater.json default](#atc-coding-rules-updaterjson-default)
- [CLI Tool Usage from powershell](#cli-tool-usage-from-powershell)
- [Deep dive in what `atc-coding-rules-updater` actual does and doesn't do](#deep-dive-in-what-atc-coding-rules-updater-actual-does-and-doesnt-do)
Expand Down Expand Up @@ -80,8 +81,8 @@ USAGE:

OPTIONS:
-h, --help Prints help information
-v, --verbose Use verbose for more debug/trace information
--version Display version
--verbose Use verbose for more debug/trace information
-v, --version Display version

COMMANDS:
run Update the project folder with ATC coding rules and configurations
Expand All @@ -101,11 +102,11 @@ EXAMPLES:
atc-coding-rules-updater.exe run -p . (equivalent to 'run -p [CurrentFolder]')
atc-coding-rules-updater.exe run -p c:\temp\MyProject
atc-coding-rules-updater.exe run -p c:\temp\MyProject -t DotNetCore --useTemporarySuppressions --organizationName
MyCompany --repositoryName MyRepo -v
MyCompany --repositoryName MyRepo --verbose

OPTIONS:
-h, --help Prints help information
-v, --verbose Use verbose for more debug/trace information
--verbose Use verbose for more debug/trace information
-p, --projectPath <PROJECTPATH> Path to the project directory (default current
diectory)
-o, --optionsPath [OPTIONSPATH] Path to an optional options json-file
Expand Down Expand Up @@ -136,11 +137,11 @@ USAGE:
EXAMPLES:
atc-coding-rules-updater.exe sanity-check . (equivalent to 'sanity-check -p [CurrentFolder]')
atc-coding-rules-updater.exe sanity-check -p c:\temp\MyProject
atc-coding-rules-updater.exe sanity-check -p c:\temp\MyProject -t DotNetCore -v
atc-coding-rules-updater.exe sanity-check -p c:\temp\MyProject -t DotNetCore --verbose

OPTIONS:
-h, --help Prints help information
-v, --verbose Use verbose for more debug/trace information
--verbose Use verbose for more debug/trace information
-p, --projectPath <PROJECTPATH> Path to the project directory (default current diectory)
-o, --optionsPath [OPTIONSPATH] Path to an optional options json-file
-t, --projectTarget [PROJECTTARGET] Sets the ProjectTarget. Valid values are: DotNetCore, DotNet5, DotNet6, DotNet7, DotNet8 (default)
Expand Down Expand Up @@ -172,7 +173,7 @@ COMMANDS:
Having a project folder in c:\code\MyProject where the .sln file for C# projects exists in the root, run the following command

```powershell
atc-coding-rules-updater run -p c:\code\MyProject -v
atc-coding-rules-updater run -p c:\code\MyProject --verbose
```

Running the command above produces the following output
Expand Down Expand Up @@ -201,6 +202,8 @@ Running the command above produces the following output

The tool has an optional options parameter, which can be used to control the paths for persisting the .editorconfigs and props files. This can be applied as follows `--optionsPath 'C:\Temp\atc-coding-rules-updater.json'`

By default the atc-coding-rules-updater will detect projects in the solution and try to fetch the matching project specific rules and supply an .editorconfig in those projects. This mapping can however be over-ruled as seen in [atc-coding-rules-updater.json example 3](#atc-coding-rules-updaterjson-example-3)

### atc-coding-rules-updater.json example 1

```json
Expand Down Expand Up @@ -237,6 +240,29 @@ The tool has an optional options parameter, which can be used to control the pat
}
```

### atc-coding-rules-updater.json example 3

In this example a project framework mapping has been added. The entry is mapped using the CsProj fileName and the specific ProjectFrameworkType. Currently the supported values for project framework type are [defined here](/src/Atc.CodingRules.Updater/ProjectFrameworkType.cs)

By specifying this mapping it will over-rule the automatic detection of the project framework type.

```json
{
"projectTarget": "DotNet8",
"mappings": {
"sample": { "paths": [ "sample" ] },
"src": { "paths": [ "src" ] },
"test": { "paths": [ "test" ] }
},
"projectFrameworkMappings": [
{
"name": "HelloWorldWpf",
"type": "Wpf"
}
]
}
```

### atc-coding-rules-updater.json default

```json
Expand All @@ -257,7 +283,8 @@ The tool has an optional options parameter, which can be used to control the pat
"test"
]
}
}
},
"projectFrameworkMappings": []
}
```

Expand Down
2 changes: 1 addition & 1 deletion atc-coding-rules-updater.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ atc-coding-rules-updater `
run `
-p $currentPath `
--optionsPath $currentPath'\atc-coding-rules-updater.json' `
-v
--verbose
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.433" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.59" />
<PackageReference Include="Atc" Version="2.0.442" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.60" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Atc.CodingRules.AnalyzerProviders/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
global using System.Diagnostics.CodeAnalysis;
global using System.IO;
global using System.Linq;
global using System.Net;
global using System.Text.Encodings.Web;
global using System.Text.Json;
global using System.Text.Json.Serialization;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Net;

namespace Atc.CodingRules.AnalyzerProviders.Providers;

public abstract class AnalyzerProviderBase : IAnalyzerProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.433" />
<PackageReference Include="Atc.Console.Spectre" Version="2.0.433" />
<PackageReference Include="EPPlus" Version="7.0.10" />
<PackageReference Include="Atc" Version="2.0.442" />
<PackageReference Include="Atc.DotNet" Version="2.0.442" />
<PackageReference Include="Atc.Console.Spectre" Version="2.0.442" />
<PackageReference Include="EPPlus" Version="7.1.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ public class OptionsFileCreateCommand : AsyncCommand<ProjectCommandSettings>
{
private readonly ILogger<OptionsFileCreateCommand> logger;

public OptionsFileCreateCommand(ILogger<OptionsFileCreateCommand> logger) => this.logger = logger;
public OptionsFileCreateCommand(
ILogger<OptionsFileCreateCommand> logger)
=> this.logger = logger;

public override Task<int> ExecuteAsync(
CommandContext context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ public class OptionsFileValidateCommand : AsyncCommand<ProjectBaseCommandSetting
{
private readonly ILogger<OptionsFileValidateCommand> logger;

public OptionsFileValidateCommand(ILogger<OptionsFileValidateCommand> logger) => this.logger = logger;
public OptionsFileValidateCommand(
ILogger<OptionsFileValidateCommand> logger)
=> this.logger = logger;

public override Task<int> ExecuteAsync(
CommandContext context,
Expand Down
4 changes: 3 additions & 1 deletion src/Atc.CodingRules.Updater.CLI/Commands/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ public class RunCommand : AsyncCommand<RunCommandSettings>
{
private readonly ILogger<RunCommand> logger;

public RunCommand(ILogger<RunCommand> logger) => this.logger = logger;
public RunCommand(
ILogger<RunCommand> logger)
=> this.logger = logger;

public override Task<int> ExecuteAsync(
CommandContext context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ public class SanityCheckCommand : AsyncCommand<ProjectCommandSettings>
{
private readonly ILogger<SanityCheckCommand> logger;

public SanityCheckCommand(ILogger<SanityCheckCommand> logger) => this.logger = logger;
public SanityCheckCommand(
ILogger<SanityCheckCommand> logger)
=> this.logger = logger;

public override Task<int> ExecuteAsync(
CommandContext context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Atc.CodingRules.Updater.CLI.Commands.Settings;

public class RootCommandSettings : BaseCommandSettings
{
[CommandOption(CommandConstants.ArgumentLongVersion)]
[CommandOption($"{CommandConstants.ArgumentShortVersion}|{CommandConstants.ArgumentLongVersion}")]
[Description("Display version")]
public bool? Version { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private static void ConfigureRunCommand(IConfigurator config)
ArgumentCommandConstants.LongUseTemporarySuppressions,
ArgumentCommandConstants.LongOrganizationName, "MyCompany",
ArgumentCommandConstants.LongRepositoryName, "MyRepo",
CommandConstants.ArgumentShortVerbose
CommandConstants.ArgumentLongVerbose
]);

private static void ConfigureSanityCheckCommand(IConfigurator config)
Expand All @@ -46,7 +46,7 @@ private static void ConfigureSanityCheckCommand(IConfigurator config)
NameCommandConstants.SanityCheck,
CreateArgumentProjectPathWithTestFolder(),
CreateArgumentProjectTarget(SupportedProjectTargetType.DotNetCore),
CommandConstants.ArgumentShortVerbose
CommandConstants.ArgumentLongVerbose
]);

private static Action<IConfigurator<CommandSettings>> ConfigureOptionsFileCommands()
Expand Down Expand Up @@ -84,7 +84,7 @@ private static Action<IConfigurator<CommandSettings>> ConfigureAnalyzerProviders
CreateArgumentCommandsAnalyzerProvidersWithCollect(),
CreateArgumentProjectPathWithTestFolder(),
CreateArgumentFetchMode(ProviderCollectingMode.ReCollect),
CommandConstants.ArgumentShortVerbose
CommandConstants.ArgumentLongVerbose
]);

node
Expand Down
4 changes: 3 additions & 1 deletion src/Atc.CodingRules.Updater.CLI/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
global using Atc.Console.Spectre.Factories;
global using Atc.Console.Spectre.Helpers;
global using Atc.Console.Spectre.Logging;
global using Atc.DotNet;
global using Atc.Helpers;

global using Microsoft.Extensions.Configuration;
global using Microsoft.Extensions.Logging;

global using OfficeOpenXml;
global using OfficeOpenXml.Style;
global using Spectre.Console;
global using Spectre.Console.Cli;
6 changes: 3 additions & 3 deletions src/Atc.CodingRules.Updater.CLI/Models/Options/OptionsFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class OptionsFile

public OptionsMappings Mappings { get; set; } = new();

public bool HasMappingsPaths()
=> Mappings.HasMappingsPaths();
[SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "OK.")]
public IList<OptionsProjectFrameworkMapping> ProjectFrameworkMappings { get; set; } = [];

public override string ToString()
=> $"{nameof(ProjectTarget)}: {ProjectTarget}, {nameof(UseTemporarySuppressions)}: {UseTemporarySuppressions}, {nameof(TemporarySuppressionsPath)}: {TemporarySuppressionAsExcel}, {nameof(TemporarySuppressionAsExcel)}: {TemporarySuppressionsPath}, {nameof(Mappings)}: ({Mappings})";
=> $"{nameof(ProjectTarget)}: {ProjectTarget}, {nameof(UseTemporarySuppressions)}: {UseTemporarySuppressions}, {nameof(TemporarySuppressionsPath)}: {TemporarySuppressionAsExcel}, {nameof(TemporarySuppressionAsExcel)}: {TemporarySuppressionsPath}, {nameof(Mappings)}: ({Mappings}), {nameof(ProjectFrameworkMappings)}.Count: {ProjectFrameworkMappings.Count}";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Atc.CodingRules.Updater.CLI.Models.Options;

public class OptionsProjectFrameworkMapping
{
public string Name { get; set; } = string.Empty;

public ProjectFrameworkType Type { get; set; }
}
20 changes: 10 additions & 10 deletions src/Atc.CodingRules.Updater.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ private static string[] SetProjectPathFromDotArgumentIfNeeded(string[] args)
newArgs.Insert(0, NameCommandConstants.Run);
}

if (!newArgs.Contains(CommandConstants.ArgumentShortVerbose, StringComparer.OrdinalIgnoreCase) ||
!newArgs.Contains(CommandConstants.ArgumentLongVerbose, StringComparer.OrdinalIgnoreCase))
if (!newArgs.Contains(CommandConstants.ArgumentLongVerbose, StringComparer.OrdinalIgnoreCase))
{
newArgs.Add(CommandConstants.ArgumentShortVerbose);
newArgs.Add(CommandConstants.ArgumentLongVerbose);
}

return newArgs.ToArray();
return [.. newArgs];
}

private static string[] SetHelpArgumentIfNeeded(string[] args)
private static string[] SetHelpArgumentIfNeeded(
string[] args)
{
if (args.Length == 0)
{
return new[] { CommandConstants.ArgumentShortHelp };
return [CommandConstants.ArgumentShortHelp];
}

if (args.Contains(NameCommandConstants.AnalyzerProviders, StringComparer.OrdinalIgnoreCase) &&
Expand All @@ -93,25 +93,25 @@ private static string[] SetHelpArgumentIfNeeded(string[] args)
{
if (args.Contains(NameCommandConstants.SanityCheck, StringComparer.OrdinalIgnoreCase))
{
return new[] { NameCommandConstants.SanityCheck, CommandConstants.ArgumentShortHelp };
return [NameCommandConstants.SanityCheck, CommandConstants.ArgumentShortHelp];
}

if (args.Contains(CommandConstants.NameOptionsFile, StringComparer.OrdinalIgnoreCase) &&
(args.Contains(CommandConstants.NameOptionsFileCreate, StringComparer.OrdinalIgnoreCase) ||
args.Contains(CommandConstants.NameOptionsFileValidate, StringComparer.OrdinalIgnoreCase)))
{
return new[] { CommandConstants.NameOptionsFile, CommandConstants.ArgumentShortHelp };
return [CommandConstants.NameOptionsFile, CommandConstants.ArgumentShortHelp];
}

if (args.Contains(NameCommandConstants.AnalyzerProviders, StringComparer.OrdinalIgnoreCase) &&
args.Contains(NameCommandConstants.AnalyzerProvidersCollect, StringComparer.OrdinalIgnoreCase))
{
return new[] { NameCommandConstants.AnalyzerProviders, CommandConstants.ArgumentShortHelp };
return [NameCommandConstants.AnalyzerProviders, CommandConstants.ArgumentShortHelp];
}

if (args.Contains(NameCommandConstants.Run, StringComparer.OrdinalIgnoreCase))
{
return new[] { NameCommandConstants.Run, CommandConstants.ArgumentShortHelp };
return [NameCommandConstants.Run, CommandConstants.ArgumentShortHelp];
}
}

Expand Down
Loading
Loading