From 0ae457287495a435b3128c364e44ece8b145c47a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Cmit=20B=C3=BCy=C3=BCkulcay?= <143997098+umitbuyukulcay@users.noreply.github.com> Date: Thu, 11 Apr 2024 15:59:47 +0300 Subject: [PATCH] feat: add clang-format style configuration (#5424) --- README.md | 1 + TEMPLATES/.clang-format | 1 + lib/functions/linterCommands.sh | 2 +- lib/linter.sh | 2 ++ test/inspec/super-linter/controls/super_linter.rb | 1 + 5 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 TEMPLATES/.clang-format diff --git a/README.md b/README.md index b3e2f5f7..09969462 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,7 @@ You can configure super-linter using the following environment variables: | **BASH_EXEC_IGNORE_LIBRARIES** | `false` | If set to `true`, shell files with a file extension and no shebang line are ignored when checking if the executable bit is set. | | **BASH_SEVERITY** | `style` | Specify the minimum severity of errors to consider in shellcheck. Valid values in order of severity are error, warning, info and style. | | **CHECKOV_FILE_NAME** | `.checkov.yaml` | Configuration filename for Checkov. | +| **CLANG_FORMAT_FILE_NAME** | `.clang-format` | Configuration filename for [clang-format](https://clang.llvm.org/docs/ClangFormatStyleOptions.html). | | **CREATE_LOG_FILE** | `false` | If set to `true`, it creates the log file. You can set the log filename using the `LOG_FILE` environment variable. This overrides any existing log files. | | **CSS_FILE_NAME** | `.stylelintrc.json` | Filename for [Stylelint configuration](https://github.com/stylelint/stylelint) (ex: `.stylelintrc.yml`, `.stylelintrc.yaml`) | | **DEFAULT_BRANCH** | Default repository branch when running on GitHub Actions, `master` otherwise | The name of the repository default branch. There's no need to configure this variable when running on GitHub Actions | diff --git a/TEMPLATES/.clang-format b/TEMPLATES/.clang-format new file mode 100644 index 00000000..9b3aa8b7 --- /dev/null +++ b/TEMPLATES/.clang-format @@ -0,0 +1 @@ +BasedOnStyle: LLVM diff --git a/lib/functions/linterCommands.sh b/lib/functions/linterCommands.sh index 6210f116..1fffd17d 100755 --- a/lib/functions/linterCommands.sh +++ b/lib/functions/linterCommands.sh @@ -31,7 +31,7 @@ else debug "Adding the '--directory' option to the Checkov command." LINTER_COMMANDS_ARRAY_CHECKOV+=(--directory) fi -LINTER_COMMANDS_ARRAY_CLANG_FORMAT=(clang-format --Werror --dry-run) +LINTER_COMMANDS_ARRAY_CLANG_FORMAT=(clang-format --style=file:"${CLANG_FORMAT_LINTER_RULES}" --Werror --dry-run) LINTER_COMMANDS_ARRAY_CLOJURE=(clj-kondo --config "${CLOJURE_LINTER_RULES}" --lint) LINTER_COMMANDS_ARRAY_CLOUDFORMATION=(cfn-lint --config-file "${CLOUDFORMATION_LINTER_RULES}") LINTER_COMMANDS_ARRAY_COFFEESCRIPT=(coffeelint -f "${COFFEESCRIPT_LINTER_RULES}") diff --git a/lib/linter.sh b/lib/linter.sh index a73aff92..a90ff047 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -152,6 +152,8 @@ ARM_FILE_NAME=".arm-ttk.psd1" BASH_SEVERITY="${BASH_SEVERITY:-""}" CHECKOV_FILE_NAME="${CHECKOV_FILE_NAME:-".checkov.yaml"}" # shellcheck disable=SC2034 # Variable is referenced indirectly +CLANG_FORMAT_FILE_NAME="${CLANG_FORMAT_FILE_NAME:-".clang-format"}" +# shellcheck disable=SC2034 # Variable is referenced indirectly CLOJURE_FILE_NAME=".clj-kondo/config.edn" # shellcheck disable=SC2034 # Variable is referenced indirectly CLOUDFORMATION_FILE_NAME=".cfnlintrc.yml" diff --git a/test/inspec/super-linter/controls/super_linter.rb b/test/inspec/super-linter/controls/super_linter.rb index 853dee35..8f04731a 100644 --- a/test/inspec/super-linter/controls/super_linter.rb +++ b/test/inspec/super-linter/controls/super_linter.rb @@ -474,6 +474,7 @@ control "super-linter-validate-files" do "/action/lib/.automation/.cfnlintrc.yml", "/action/lib/.automation/.checkov.yaml", "/action/lib/.automation/.chktexrc", + "/action/lib/.automation/.clang-format", "/action/lib/.automation/.clj-kondo", "/action/lib/.automation/.coffee-lint.json", "/action/lib/.automation/.ecrc",