- Notifications
You must be signed in to change notification settings - Fork2
A CLI tool to update atc coding rules and guidelines in a project / solution.
License
atc-net/atc-coding-rules-updater
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This repository contains a CLI tool, which can be used to maintaincoding-rules
in a project, whereatc-coding-rules has been utilized.
- Read aboutatc-coding-rules
- Master rule filesinformation
- ATC-NET Coding rules updater
The Atc.CodingRules.Updater.CLI library is available through a cross platform command line application.
The tool can be installed as a .NET Core global tool by the following command
dotnet tool install--global atc-coding-rules-updater
or by following the instructionshere to install a specific version of the tool.
A successful installation will output something like
The tool can be invoked by the following command: atc-coding-rules-updaterTool'atc-coding-rules-updater' (version'2.0.xxx') was successfully installed.`
The tool can be updated by following command
dotnet tool update--global atc-coding-rules-updater
Since the tool is published as a .NET Tool, it can be launched from anywhere using any shell or command-line interface by callingatc-coding-rules-updater. The help information is displayed when providing the--help
argument toatc-coding-rules-updater
atc-coding-rules-updater--helpUSAGE:atc-coding-rules-updater.exe [OPTIONS]OPTIONS:-h,--help Prints help information--verbose Use verbosefor more debug/trace information-v,--version Display versionCOMMANDS: run Update the project folder with ATC coding rules and configurations sanity-check Sanity check the project files options-file Commandsfor the options file'atc-coding-rules-updater.json' analyzer-providers Commandsfor analyzer providers
USAGE:atc-coding-rules-updater.exe run [OPTIONS]EXAMPLES:atc-coding-rules-updater.exe. (equivalent to'run -p [CurrentFolder]')atc-coding-rules-updater.exe run. (equivalent to'run -p [CurrentFolder]')atc-coding-rules-updater.exe run-p. (equivalent to'run -p [CurrentFolder]')atc-coding-rules-updater.exe run-p c:\temp\MyProjectatc-coding-rules-updater.exe run-p c:\temp\MyProject-t DotNetCore--useTemporarySuppressions--organizationNameMyCompany--repositoryName MyRepo--verboseOPTIONS:-h,--help Prints help information--verbose Use verbosefor 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)--useLatestMinorNugetVersion Indicateif nuget packages should by updated to latest minor version (default true)--useTemporarySuppressions Indicateif buildprocess should use temporary suppressions- appends to .editorconfig- unless temporarySuppressionPath is set--temporarySuppressionPath [TEMPORARYSUPPRESSIONPATH] Optional path to temporary suppressions file-if not set .editorconfig file is used--temporarySuppressionAsExcel Indicateif temporary suppressions file should be saved as Excel (.xlsx)--buildFile [BUILDFILE] Solution/project file- required when multiple .sln files existsin root path--organizationName [ORGANIZATIONNAME] Optional: Specify the name of your organizationfor the Directory.Build.Props file--repositoryName [REPOSITORYNAME] Optional: Specify the name of your repositoryfor the Directory.Build.Props file
USAGE:atc-coding-rules-updater.exe sanity-check [OPTIONS]EXAMPLES:atc-coding-rules-updater.exe sanity-check. (equivalent to'sanity-check -p [CurrentFolder]')atc-coding-rules-updater.exe sanity-check-p c:\temp\MyProjectatc-coding-rules-updater.exe sanity-check-p c:\temp\MyProject-t DotNetCore--verboseOPTIONS:-h,--help Prints help information--verbose Use verbosefor 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)
USAGE:atc-coding-rules-updater.exe options-file [OPTIONS]<COMMAND>EXAMPLES:atc-coding-rules-updater.exe options-file create. (equivalent to'options-file create -p [CurrentFolder]')atc-coding-rules-updater.exe options-file create-p. (equivalent to'options-file create -p [CurrentFolder]')atc-coding-rules-updater.exe options-file create-p c:\temp\MyProjectatc-coding-rules-updater.exe options-file create-p c:\temp\MyProject-t DotNet5atc-coding-rules-updater.exe options-file validate. (equivalent to'options-file validate -p [CurrentFolder]')atc-coding-rules-updater.exe options-file validate-p c:\temp\MyProjectOPTIONS:-h,--help Prints help informationCOMMANDS: create Createdefault options file'atc-coding-rules-updater.json'if it doesn´t exist validate Validate the options file'atc-coding-rules-updater.json'
Having a project folder in c:\code\MyProject where the .sln file for C# projects exists in the root, run the following command
atc-coding-rules-updater run-p c:\code\MyProject--verbose
Running the command above produces the following output
_______|_ \__||_____________||___||_______||_)|||||||/_ \/__||||||`_ \/_`|/_`||__|/_ \|`__||_<||_|||||__/ \__ \||_||||_)|| (_||| (_||||_|__/|||_| \_\ \__,_||_| \___||___/ \__,_||.__/ \__,_| \__,_| \__| \___||_||_|🐭 Working on EditorConfig files🟢 root: .editorconfig files merged🟢 sample: .editorconfig created🟢 src: .editorconfig created🟢 test: .editorconfig created🔨 Working on Directory.Build.props files🟢 root: Directory.Build.props created🟢 sample: Directory.Build.props created🟢 src: Directory.Build.props created🟢 test: Directory.Build.props created✅ Done
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 inatc-coding-rules-updater.json example 3
{"mappings": {"sample": {"paths": ["C:\\Temp\\MyProject\\sample1","C:\\Temp\\MyProject\\sample2" ] },"src": {"paths": ["C:\\Temp\\MyProject\\src" ] },"test": {"paths": ["C:\\Temp\\MyProject\\test" ] } }}
{"mappings": {"src": {"paths": ["source" ] },"test": {"paths": ["tests" ] } }}
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 aredefined here
By specifying this mapping it will over-rule the automatic detection of the project framework type.
{"projectTarget":"DotNet8","mappings": {"sample": {"paths": ["sample" ] },"src": {"paths": ["src" ] },"test": {"paths": ["test" ] } },"projectFrameworkMappings": [ {"name":"HelloWorldWpf","type":"Wpf" } ]}
{"projectTarget":"DotNet8","useLatestMinorNugetVersion":true,"useTemporarySuppressions":false,"temporarySuppressionAsExcel":false,"analyzerProviderCollectingMode":"LocalCache","mappings": {"src": {"paths": ["src" ] },"test": {"paths": ["test" ] } },"projectFrameworkMappings": []}
Note: If there is aatc-coding-rules-updater.json
file present in the root folder (given by options--projectPath
/-p
), then it will automatically be found and used. Other given arguments will then override.
To ensure that the latest version of the CLI toolatc-coding-rules-updater
is being used, the following methodology can be used:
- Download the 2 files from
sample
into a project root folder. - Modify the
atc-coding-rules-updater.json
to the projects specific needs. - Run
atc-coding-rules-updater.ps1
from powershell
Theatc-coding-rules-updater
downloads files from theatc-coding-rules repository's distribution folder.
From here it works with 2 concepts:
- Scaffolding files (
.editorconfig
andDirectory.Build.props
) - if a file does not exist - it creates a copy. - Updating files (
.editorconfig
) - if a file exist - updates the files first content part and does not touch the second content part.- First content part is related to rules above the line
# Custom - Code Analyzers Rules
- and will be updated - herafter known as ATC-part. - Second content part is related to rules below the line
# Custom - Code Analyzers Rules
- and will not be touched - herafter known as Customer-part.
- First content part is related to rules above the line
In scenario A we have root wheresrc
andtest
destination is defined as:
{"mappings": {"src": {"paths": ["src" ] },"test": {"paths": ["test" ] } }}
When theatc-coding-rules-update
is exceuted first time, the following happens (see legend for explanation):
arrows indicate files created in
root
folder.arrows indicate files created in
src
folder.arrows indicate files created in
test
folder.
In this scenario we have root wheresrc
andtest
destination is defined as:
{"mappings": {"src": {"paths": ["MyDemo.Gui","MyDemo.SharedContracts","MyDemo.WebApi" ] },"test": {"paths": ["MyDemo.Gui.Tests","MyDemo.SharedContracts.Tests","MyDemo.WebApi.Tests" ] } }}
When theatc-coding-rules-update
is executed first time, the following happens (see legend for explanation):
arrows indicate files created in
root
folder.arrows indicate files created in
src
folder.arrows indicate files created in
test
folder.
For both scenario A and scenario B, when theatc-coding-rules-update
is executed a second time it will only update.editorconfig
file. And as previously stated, it will only update the ATC-part of these files.
When starting with ATC rules on an existing project, the general recommendation is to initially suppress all failing rules in your Custom section in order to get back to ✅ state for the project, and then later clean up the code and remove the suppressions one by one in nice clean commits.
The challenge is that this initial suppression list takes a long time to hand-write. In order to circumvent this tedious process, some extra flags have been added to the CLI to allow for auto-generation of these suppression lines. When utilizing these new options, the updater process will run a dotnet build on your project and extract any errors and create suppressions for these along with a count of how many occurences are present. The CLI will also add additional information, e.g: Category, Title, Link to the rule being broken.
The three CLI options for generating temporary suppressions are as follows.
--useTemporarySuppressions Use temporary suppressions from build - appends to .editorconfig - unless temporarySuppressionPath is set--temporarySuppressionPath Optional path to temporary suppressions file - if not set .editorconfig file is used--temporarySuppressionAsExcel Optional - save temporary suppressions file as Excel (.xlsx)
Below an example of the auto-generated supressions is shown:
########################################### ATC temporary suppressions# generated @ 21. juni 2021 02:33:34# Please fix all generated temporary suppressions# either by code changes or move the# suppressions one by one to the relevant# 'Custom - Code Analyzers Rules' section.########################################### Microsoft.CodeAnalysis.NetAnalyzersdotnet_diagnostic.CA1303.severity = none # 1 occurrence - Do not pass literals as localized parameters - https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1303dotnet_diagnostic.CA1707.severity = none # 1 occurrence - Identifiers should not contain underscores - https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1707dotnet_diagnostic.CA1801.severity = none # 1 occurrence - Review unused parameters - https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1801# SonarAnalyzer.CSharpdotnet_diagnostic.S1118.severity = none # 1 occurrence - Category: 'Code Smell' - Utility classes should not have public constructors - https://rules.sonarsource.com/csharp/RSPEC-1118# StyleCop.Analyzersdotnet_diagnostic.SA1400.severity = none # 2 occurrences - Category: 'Maintainability' - Access modifier must be declared - https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1400.md
When using the--useTemporarySuppressions
option, adotnet.exe build
will be executed (up to 10 times depending on the complexity of the solution).Hence a requirement is that dotnet.exe can be called from the root path.If there are multiple solutions (.sln) files in the root folder, the--buildFile
option will then be required as a parameter when calling the CLI tool.
--buildFile Optional path to solution/project file - required when multiple .sln files exists in root path
About
A CLI tool to update atc coding rules and guidelines in a project / solution.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.