Skip to content

Commit 8ceae0f

Browse files
authored
feat: lint and format dotnet solutions (#6039)
Close #736
1 parent 3905209 commit 8ceae0f

44 files changed

Lines changed: 1058 additions & 86 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/linters/.jscpd.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"**/test/linters/coffeescript",
1212
"**/test/linters/css",
1313
"**/test/linters/css_prettier",
14+
"**/test/linters/dotnet_sln_format_analyzers",
15+
"**/test/linters/dotnet_sln_format_style",
16+
"**/test/linters/dotnet_sln_format_whitespace",
1417
"**/test/linters/html",
1518
"**/test/linters/javascript_es",
1619
"**/test/linters/javascript_prettier",

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ test/reports
9090
.lintr
9191
test/linters/rust_clippy/**/Cargo.lock
9292
test/linters/rust_clippy/**/target
93+
test/linters/**/src/bin
94+
test/linters/**/src/obj
9395

9496
# Super-linter ouputs
9597
super-linter-output/

Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
all: info docker test ## Run all targets.
55

66
.PHONY: test
7-
test: info validate-container-image-labels docker-build-check docker-dev-container-build-check test-lib inspec lint-codebase fix-codebase test-default-config-files test-actions-runner-debug test-actions-steps-debug test-runner-debug test-find lint-subset-files test-custom-ssl-cert test-non-default-workdir test-git-flags test-non-default-home-directory test-git-initial-commit test-git-merge-commit-push test-log-level test-use-find-and-ignore-gitignored-files test-linters-expect-failure-log-level-notice test-bash-exec-library-expect-success test-bash-exec-library-expect-failure test-save-super-linter-output test-save-super-linter-output-custom-path test-save-super-linter-custom-summary test-custom-gitleaks-log-level test-linters test-linters-fix-mode ## Run the test suite
7+
test: info validate-container-image-labels docker-build-check docker-dev-container-build-check test-lib inspec lint-codebase fix-codebase test-default-config-files test-actions-runner-debug test-actions-steps-debug test-runner-debug test-find lint-subset-files test-custom-ssl-cert test-non-default-workdir test-git-flags test-non-default-home-directory test-git-initial-commit test-git-merge-commit-push test-log-level test-use-find-and-ignore-gitignored-files test-linters-expect-failure-log-level-notice test-bash-exec-library-expect-success test-bash-exec-library-expect-failure test-save-super-linter-output test-save-super-linter-output-custom-path test-save-super-linter-custom-summary test-custom-gitleaks-log-level test-dont-save-super-linter-log-file test-dont-save-super-linter-output test-linters test-linters-fix-mode ## Run the test suite
88

99
# if this session isn't interactive, then we don't want to allocate a
1010
# TTY, which would fail, but if it is interactive, we do want to attach
@@ -532,6 +532,20 @@ test-custom-gitleaks-log-level: ## Run super-linter with a custom Gitleaks log l
532532
"run_test_case_gitleaks_custom_log_level" \
533533
"$(IMAGE)"
534534

535+
.PHONY: test-dont-save-super-linter-log-file
536+
test-dont-save-super-linter-log-file: ## Run super-linter without saving the Super-linter log file
537+
$(CURDIR)/test/run-super-linter-tests.sh \
538+
$(SUPER_LINTER_TEST_CONTAINER_URL) \
539+
"run_test_case_dont_save_super_linter_log_file" \
540+
"$(IMAGE)"
541+
542+
.PHONY: test-dont-save-super-linter-output
543+
test-dont-save-super-linter-output: ## Run super-linter without saving Super-linter output files
544+
$(CURDIR)/test/run-super-linter-tests.sh \
545+
$(SUPER_LINTER_TEST_CONTAINER_URL) \
546+
"run_test_case_dont_save_super_linter_output" \
547+
"$(IMAGE)"
548+
535549
.PHONY: docker-dev-container-build-check ## Run Docker build checks against the dev-container image
536550
docker-dev-container-build-check:
537551
DOCKER_BUILDKIT=1 docker buildx build --check \

README.md

Lines changed: 70 additions & 62 deletions
Large diffs are not rendered by default.

docs/add-new-linter.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ new tool, it should include:
1515
If the linter supports fix mode, the test case supposed to fail validation
1616
should only contain violations that the fix mode can automatically fix.
1717
Avoid test cases that fail only because of syntax errors, when possible.
18-
4. If the linter supports check-only mode or fix mode, add the `<LANGUGAGE>`
18+
4. Update expected summary reports: `test/data/super-linter-summary`.
19+
5. If the linter supports check-only mode or fix mode, add the `<LANGUGAGE>`
1920
to the `LANGUAGES_WITH_FIX_MODE` array in `test/testUtils.sh`
2021

2122
- Update the test suite to check for installed packages, the commands that your new tool needs in the `PATH`, and the expected version command:

lib/functions/buildFileList.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,10 @@ BuildFileArrays() {
517517
echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-GRAPHQL_PRETTIER"
518518
elif [ "${FILE_TYPE}" == "vue" ]; then
519519
echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-VUE_PRETTIER"
520+
elif [ "${FILE_TYPE}" == "sln" ]; then
521+
echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-DOTNET_SLN_FORMAT_ANALYZERS"
522+
echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-DOTNET_SLN_FORMAT_STYLE"
523+
echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-DOTNET_SLN_FORMAT_WHITESPACE"
520524
elif [ "${FILE_TYPE}" == "yml" ] || [ "${FILE_TYPE}" == "yaml" ]; then
521525
echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-YAML"
522526
echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-YAML_PRETTIER"

lib/functions/linterCommands.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ source /action/lib/globals/linterCommandsOptions.sh
1414

1515
# These commands are reused across several languages
1616
PRETTIER_COMMAND=(prettier)
17+
DOTNET_FORMAT_COMMAND=(dotnet format)
1718

1819
LINTER_COMMANDS_ARRAY_ANSIBLE=(ansible-lint -c "${ANSIBLE_LINTER_RULES}")
1920
LINTER_COMMANDS_ARRAY_ARM=(pwsh -NoProfile -NoLogo -Command "\"Import-Module ${ARM_TTK_PSD1} ; \\\${config} = \\\$(Import-PowerShellDataFile -Path ${ARM_LINTER_RULES}) ; Test-AzTemplate @config -TemplatePath '{}'; if (\\\${Error}.Count) { exit 1 }\"")
@@ -44,11 +45,14 @@ LINTER_COMMANDS_ARRAY_CLOJURE=(clj-kondo --config "${CLOJURE_LINTER_RULES}" --li
4445
LINTER_COMMANDS_ARRAY_CLOUDFORMATION=(cfn-lint --config-file "${CLOUDFORMATION_LINTER_RULES}")
4546
LINTER_COMMANDS_ARRAY_COFFEESCRIPT=(coffeelint -f "${COFFEESCRIPT_LINTER_RULES}")
4647
LINTER_COMMANDS_ARRAY_CPP=(cpplint)
47-
LINTER_COMMANDS_ARRAY_CSHARP=(dotnet format whitespace --folder --exclude / --include "{/}")
48+
LINTER_COMMANDS_ARRAY_CSHARP=("${DOTNET_FORMAT_COMMAND[@]}" whitespace --folder --exclude / --include "{/}")
4849
LINTER_COMMANDS_ARRAY_CSS=(stylelint --config "${CSS_LINTER_RULES}")
4950
LINTER_COMMANDS_ARRAY_CSS_PRETTIER=("${PRETTIER_COMMAND[@]}")
5051
LINTER_COMMANDS_ARRAY_DART=(dart analyze --fatal-infos --fatal-warnings)
5152
LINTER_COMMANDS_ARRAY_DOCKERFILE_HADOLINT=(hadolint -c "${DOCKERFILE_HADOLINT_LINTER_RULES}")
53+
LINTER_COMMANDS_ARRAY_DOTNET_SLN_FORMAT_ANALYZERS=("${DOTNET_FORMAT_COMMAND[@]}" analyzers)
54+
LINTER_COMMANDS_ARRAY_DOTNET_SLN_FORMAT_STYLE=("${DOTNET_FORMAT_COMMAND[@]}" style)
55+
LINTER_COMMANDS_ARRAY_DOTNET_SLN_FORMAT_WHITESPACE=("${DOTNET_FORMAT_COMMAND[@]}" whitespace)
5256
LINTER_COMMANDS_ARRAY_EDITORCONFIG=(editorconfig-checker -config "${EDITORCONFIG_LINTER_RULES}")
5357
LINTER_COMMANDS_ARRAY_ENV=(dotenv-linter)
5458
LINTER_COMMANDS_ARRAY_GITHUB_ACTIONS=(actionlint -config-file "${GITHUB_ACTIONS_LINTER_RULES}")

lib/functions/worker.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ function LintCodebase() {
103103
[[ "${FILE_TYPE}" == "BASH_EXEC" ]] ||
104104
[[ "${FILE_TYPE}" == "CLOJURE" ]] ||
105105
[[ "${FILE_TYPE}" == "CSHARP" ]] ||
106+
[[ "${FILE_TYPE}" == "DOTNET_SLN_FORMAT_ANALYZERS" ]] ||
107+
[[ "${FILE_TYPE}" == "DOTNET_SLN_FORMAT_STYLE" ]] ||
108+
[[ "${FILE_TYPE}" == "DOTNET_SLN_FORMAT_WHITESPACE" ]] ||
106109
[[ "${FILE_TYPE}" == "GITLEAKS" ]] ||
107110
[[ "${FILE_TYPE}" == "GO_MODULES" ]] ||
108111
[[ "${FILE_TYPE}" == "JSCPD" ]] ||

lib/globals/languages.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'BASH_EXEC' 'CHECKOV' 'CLANG_FORMAT'
66
'CSS'
77
"CSS_PRETTIER"
88
'DART'
9-
'DOCKERFILE_HADOLINT' 'EDITORCONFIG' 'ENV'
9+
'DOCKERFILE_HADOLINT'
10+
"DOTNET_SLN_FORMAT_ANALYZERS"
11+
"DOTNET_SLN_FORMAT_STYLE"
12+
"DOTNET_SLN_FORMAT_WHITESPACE"
13+
'EDITORCONFIG'
14+
'ENV'
1015
'GITHUB_ACTIONS'
1116
'GITLEAKS' 'GHERKIN' 'GO' 'GO_MODULES' 'GO_RELEASER' 'GOOGLE_JAVA_FORMAT'
1217
"GRAPHQL_PRETTIER"

lib/globals/linterCommandsOptions.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66
# "check only" mode options for linters that that we reuse across several languages
77
PRETTIER_CHECK_ONLY_MODE_OPTIONS=(--check)
88
RUSTFMT_CHECK_ONLY_MODE_OPTIONS=(--check)
9+
DOTNET_FORMAT_CHECK_ONLY_MODE_OPTIONS=(--verify-no-changes)
910

1011
# Define configuration options to enable "check only" mode.
1112
# Some linters and formatters only support a "check only" mode so there's no
1213
# need to define a "check only" mode option for those.
1314
CLANG_FORMAT_CHECK_ONLY_MODE_OPTIONS=(--dry-run)
14-
CSHARP_CHECK_ONLY_MODE_OPTIONS=(--verify-no-changes)
15+
CSHARP_CHECK_ONLY_MODE_OPTIONS=("${DOTNET_FORMAT_CHECK_ONLY_MODE_OPTIONS[@]}")
1516
CSS_PRETTIER_CHECK_ONLY_MODE_OPTIONS=("${PRETTIER_CHECK_ONLY_MODE_OPTIONS[@]}")
17+
DOTNET_SLN_FORMAT_ANALYZERS_CHECK_ONLY_MODE_OPTIONS=("${DOTNET_FORMAT_CHECK_ONLY_MODE_OPTIONS[@]}")
18+
DOTNET_SLN_FORMAT_STYLE_CHECK_ONLY_MODE_OPTIONS=("${DOTNET_FORMAT_CHECK_ONLY_MODE_OPTIONS[@]}")
19+
DOTNET_SLN_FORMAT_WHITESPACE_CHECK_ONLY_MODE_OPTIONS=("${DOTNET_FORMAT_CHECK_ONLY_MODE_OPTIONS[@]}")
1620
GOOGLE_JAVA_FORMAT_CHECK_ONLY_MODE_OPTIONS=(--dry-run --set-exit-if-changed)
1721
GRAPHQL_PRETTIER_CHECK_ONLY_MODE_OPTIONS=("${PRETTIER_CHECK_ONLY_MODE_OPTIONS[@]}")
1822
HTML_PRETTIER_CHECK_ONLY_MODE_OPTIONS=("${PRETTIER_CHECK_ONLY_MODE_OPTIONS[@]}")

0 commit comments

Comments
 (0)