From 80476af4f756998ca416733d8ca95a323bebfc67 Mon Sep 17 00:00:00 2001 From: Vadim Hatsura Date: Mon, 16 Oct 2023 20:31:03 +0200 Subject: [PATCH] feat: use built-in `dotnet format` linter for csharp language (#4627) * chore: add test case for csharp language which should pass it shows that the current version of linter for csharp language reports false positive issues * feat: use built-in linter for csharp language https://github.com/dotnet/format/issues/1268 * chore: remove dotnet-format installation from install-dotnet.sh dotnet format is a part of .NET 6 SDK and shouldn't be installed separately anymore * docs: update linter name for dotnet instead of dotnet-format built-in format command from dotnet is used (points to the same repository as before) * chore: update linter name for dotnet in tests --------- Co-authored-by: Zack Koppert --- .automation/test/csharp/csharp_good_02.cs | 14 ++++++++++++++ README.md | 2 +- lib/linter.sh | 4 ++-- scripts/install-dotnet.sh | 1 - test/inspec/super-linter/controls/super_linter.rb | 4 ++-- 5 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 .automation/test/csharp/csharp_good_02.cs diff --git a/.automation/test/csharp/csharp_good_02.cs b/.automation/test/csharp/csharp_good_02.cs new file mode 100644 index 00000000..02428f39 --- /dev/null +++ b/.automation/test/csharp/csharp_good_02.cs @@ -0,0 +1,14 @@ +using System; + +namespace HelloWorld; + +internal enum Foo +{ + Bar = 1, + Baz = 2 +} + +public class TestClass +{ + public required Foo Bar { get; set; } +} diff --git a/README.md b/README.md index 73785efb..f63cb6bf 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their codebase w | **AWS CloudFormation templates** | [cfn-lint](https://github.com/aws-cloudformation/cfn-python-lint/) | | **Azure Resource Manager (ARM)** | [arm-ttk](https://github.com/azure/arm-ttk) | | **C++** | [cpp-lint](https://github.com/cpplint/cpplint) / [clang-format](https://clang.llvm.org/docs/ClangFormatStyleOptions.html) | -| **C#** | [dotnet-format](https://github.com/dotnet/format) / [clang-format](https://clang.llvm.org/docs/ClangFormatStyleOptions.html) | +| **C#** | [dotnet format](https://github.com/dotnet/format) / [clang-format](https://clang.llvm.org/docs/ClangFormatStyleOptions.html) | | **CSS** | [stylelint](https://stylelint.io/) | | **Clojure** | [clj-kondo](https://github.com/borkdude/clj-kondo) | | **CoffeeScript** | [coffeelint](https://coffeelint.github.io/) | diff --git a/lib/linter.sh b/lib/linter.sh index 981d86b4..3d9aaa00 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -286,7 +286,7 @@ LINTER_NAMES_ARRAY['CLOJURE']="clj-kondo" LINTER_NAMES_ARRAY['CLOUDFORMATION']="cfn-lint" LINTER_NAMES_ARRAY['COFFEESCRIPT']="coffeelint" LINTER_NAMES_ARRAY['CPP']="cpplint" -LINTER_NAMES_ARRAY['CSHARP']="dotnet-format" +LINTER_NAMES_ARRAY['CSHARP']="dotnet" LINTER_NAMES_ARRAY['CSS']="stylelint" LINTER_NAMES_ARRAY['DART']="dart" LINTER_NAMES_ARRAY['DOCKERFILE_HADOLINT']="hadolint" @@ -911,7 +911,7 @@ LINTER_COMMANDS_ARRAY['CLOJURE']="clj-kondo --config ${CLOJURE_LINTER_RULES} --l LINTER_COMMANDS_ARRAY['CLOUDFORMATION']="cfn-lint --config-file ${CLOUDFORMATION_LINTER_RULES}" LINTER_COMMANDS_ARRAY['COFFEESCRIPT']="coffeelint -f ${COFFEESCRIPT_LINTER_RULES}" LINTER_COMMANDS_ARRAY['CPP']="cpplint" -LINTER_COMMANDS_ARRAY['CSHARP']="dotnet-format --folder --check --exclude / --include" +LINTER_COMMANDS_ARRAY['CSHARP']="dotnet format whitespace --folder --verify-no-changes --exclude / --include" LINTER_COMMANDS_ARRAY['CSS']="stylelint --config ${CSS_LINTER_RULES}" LINTER_COMMANDS_ARRAY['DART']="dartanalyzer --fatal-infos --fatal-warnings --options ${DART_LINTER_RULES}" LINTER_COMMANDS_ARRAY['DOCKERFILE_HADOLINT']="hadolint -c ${DOCKERFILE_HADOLINT_LINTER_RULES}" diff --git a/scripts/install-dotnet.sh b/scripts/install-dotnet.sh index fc89e553..ddefc4b9 100755 --- a/scripts/install-dotnet.sh +++ b/scripts/install-dotnet.sh @@ -5,4 +5,3 @@ set -euo pipefail curl --retry 5 --retry-delay 5 -sLO https://dot.net/v1/dotnet-install.sh chmod +x dotnet-install.sh ./dotnet-install.sh --install-dir /usr/share/dotnet -channel STS -version latest -/usr/share/dotnet/dotnet tool install --tool-path /usr/bin dotnet-format --version 5.0.211103 diff --git a/test/inspec/super-linter/controls/super_linter.rb b/test/inspec/super-linter/controls/super_linter.rb index efa69b18..503a644a 100644 --- a/test/inspec/super-linter/controls/super_linter.rb +++ b/test/inspec/super-linter/controls/super_linter.rb @@ -107,7 +107,7 @@ control "super-linter-installed-commands" do { linter_name: "coffeelint"}, { linter_name: "cpplint"}, { linter_name: "dart"}, - { linter_name: "dotnet-format"}, + { linter_name: "dotnet"}, { linter_name: "dotenv-linter"}, { linter_name: "editorconfig-checker", version_option: "-version"}, { linter_name: "eslint"}, @@ -161,7 +161,7 @@ control "super-linter-installed-commands" do SLIM_IMAGE_REMOVED_LINTERS=%w( arm-ttk clippy - dotnet-format + dotnet dotenv-linter pwsh rustfmt