diff --git a/.automation/test/editorconfig-checker/.editorconfig b/.automation/test/editorconfig-checker/.editorconfig new file mode 100644 index 00000000..f41c803b --- /dev/null +++ b/.automation/test/editorconfig-checker/.editorconfig @@ -0,0 +1,3 @@ +[*.ext] +indent_style = space +indent_size = 4 diff --git a/.automation/test/editorconfig-checker/README.md b/.automation/test/editorconfig-checker/README.md new file mode 100644 index 00000000..650f9932 --- /dev/null +++ b/.automation/test/editorconfig-checker/README.md @@ -0,0 +1,13 @@ +# EDITORCONFIG_CHECKER Test Cases +This folder holds the test cases for **EDITORCONFIG_CHECKER**. + +## Additional Docs +No Additional information is needed for this test case. + +## Good Test Cases +The test cases denoted: `LANGUAGE_good_FILE.EXTENSION` are all valid, and should pass successfully when linted. +- **Note:** They are linted utilizing the default linter rules. + +## Bad Test Cases +The test cases denoted: `LANGUAGE_bad_FILE.EXTENSION` are **NOT** valid, and should trigger errors when linted. +- **Note:** They are linted utilizing the default linter rules. diff --git a/.automation/test/editorconfig-checker/editorconfig-checker_bad_1.ext b/.automation/test/editorconfig-checker/editorconfig-checker_bad_1.ext new file mode 100644 index 00000000..e60d663b --- /dev/null +++ b/.automation/test/editorconfig-checker/editorconfig-checker_bad_1.ext @@ -0,0 +1,3 @@ + some line + some line + some line diff --git a/.automation/test/editorconfig-checker/editorconfig-checker_good_1.ext b/.automation/test/editorconfig-checker/editorconfig-checker_good_1.ext new file mode 100644 index 00000000..30464ecd --- /dev/null +++ b/.automation/test/editorconfig-checker/editorconfig-checker_good_1.ext @@ -0,0 +1,3 @@ +some line + some line + some line diff --git a/.github/linters/.ecrc b/.github/linters/.ecrc new file mode 100644 index 00000000..e052a07b --- /dev/null +++ b/.github/linters/.ecrc @@ -0,0 +1,18 @@ +{ + "Verbose": false, + "Debug": false, + "IgnoreDefaults": false, + "SpacesAftertabs": false, + "NoColor": false, + "Exclude": [], + "AllowedContentTypes": [], + "PassedFiles": [], + "Disable": { + "EndOfLine": false, + "Indentation": false, + "InsertFinalNewline": false, + "TrimTrailingWhitespace": false, + "IndentSize": false, + "MaxLineLength": false + } +} diff --git a/Dockerfile b/Dockerfile index 56bc44a8..c4fc9783 100644 --- a/Dockerfile +++ b/Dockerfile @@ -159,6 +159,12 @@ RUN curl -sLO https://github.com/borkdude/clj-kondo/releases/download/v${CLJ_KON RUN curl -sSLO https://github.com/pinterest/ktlint/releases/latest/download/ktlint && chmod a+x ktlint \ && mv "ktlint" /usr/bin/ +################################ +# Install editorconfig-checker # +################################ +RUN wget -qO- "https://github.com/editorconfig-checker/editorconfig-checker/releases/latest/download/ec-linux-amd64.tar.gz" | tar -xzf - \ + && mv "bin/ec-linux-amd64" /usr/bin/editorconfig-checker + ########################################### # Load GitHub Env Vars for GitHub Actions # ########################################### @@ -193,6 +199,7 @@ ENV GITHUB_SHA=${GITHUB_SHA} \ VALIDATE_POWERSHELL=${VALIDATE_POWERSHELL} \ VALIDATE_OPENAPI=${VALIDATE_OPENAPI} \ VALIDATE_PROTOBUF=${VALIDATE_PROTOBUF} \ + VALIDATE_EDITORCONFIG=${VALIDATE_EDITORCONFIG} \ ANSIBLE_DIRECTORY=${ANSIBLE_DIRECTORY} \ RUN_LOCAL=${RUN_LOCAL} \ TEST_CASE_RUN=${TEST_CASE_RUN} \ diff --git a/README.md b/README.md index 6c1b6520..d899a522 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base | **Clojure** | [clj-kondo](https://github.com/borkdude/clj-kondo) | | **CoffeeScript** | [coffeelint](https://coffeelint.github.io/) | | **Dockerfile** | [dockerfilelint](https://github.com/replicatedhq/dockerfilelint.git) | +| **EDITORCONFIG** | [editorconfig-checker](https://github.com/editorconfig-checker/editorconfig-checker) | | **ENV** | [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter) | | **Golang** | [golangci-lint](https://github.com/golangci/golangci-lint) | | **JavaScript** | [eslint](https://eslint.org/) [standard js](https://standardjs.com/) | @@ -179,6 +180,7 @@ and won't run anything unexpected. | **VALIDATE_OPENAPI** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_CLOUDFORMATION** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_PROTOBUF** | `true` | Flag to enable or disable the linting process of the language. | +| **VALIDATE_EDITORCONFIG** | `true` | Flag to enable or disable the linting process with the editorconfig. | | **ANSIBLE_DIRECTORY** | `/ansible` | Flag to set the root directory for Ansible file location(s). | | **ACTIONS_RUNNER_DEBUG** | `false` | Flag to enable additional information about the linter, versions, and additional output. | | **DISABLE_ERRORS** | `false` | Flag to have the linter complete with exit code 0 even if errors were detected. | diff --git a/docs/disabling-linters.md b/docs/disabling-linters.md index 93800eb7..524d2779 100644 --- a/docs/disabling-linters.md +++ b/docs/disabling-linters.md @@ -36,6 +36,7 @@ For some linters it is also possible to override rules on a case by case level w - [Kotlin](#kotlin) - [OpenAPI](#openapi) - [Protocol Buffers](#protocol-buffers) +- [EDITORCONFIG-CHECKER](#editorconfig-checker) @@ -742,4 +743,36 @@ lint: ### clj-kondo disable entire file ```clojure {:output {:exclude-files ["path/to/file"]}} + +## EDITORCONFIG-CHECKER +- [editorconfig-checker](https://github.com/editorconfig-checker/editorconfig-checker) + +-------------------------------------------------------------------------------- + +### editorconfig-checker Config file +- `.github/linters/.ecrc` +- This linter will also use the [`.editorconfig`](https://editorconfig.org/) of your project + +### editorconfig-checker disable single line +- +```js + // editorconfig-checker-disable-line +``` + +### editorconfig-checker disable code block +- There is currently **No** way to disable rules inline of the file(s) + +### editorconfig-checker disable entire file +- +```js +// editorconfig-checker-disable-file +``` +- You can disable entire files with the `Exclude` property in `.ecrc` +```json +{ + "Exclude": [ + "path/to/file", + "^regular\\/expression\\.ext$" + ] +} ``` diff --git a/lib/linter.sh b/lib/linter.sh index a036dc2c..811f1f0e 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -129,6 +129,7 @@ VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to vali VALIDATE_POWERSHELL="${VALIDATE_POWERSHELL}" # Boolean to validate language VALIDATE_KOTLIN="${VALIDATE_KOTLIN}" # Boolean to validate language VALIDATE_OPENAPI="${VALIDATE_OPENAPI}" # Boolean to validate language +VALIDATE_EDITORCONFIG="${VALIDATE_EDITORCONFIG}" # Boolean to validate files with editorconfig TEST_CASE_RUN="${TEST_CASE_RUN}" # Boolean to validate only test cases DISABLE_ERRORS="${DISABLE_ERRORS}" # Boolean to enable warning-only output without throwing errors @@ -743,6 +744,7 @@ Footer() { exit 0 fi } + ################################################################################ ############################### MAIN ########################################### ################################################################################ @@ -1069,6 +1071,18 @@ if [ "$VALIDATE_KOTLIN" == "true" ]; then LintCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "${FILE_ARRAY_KOTLIN[@]}" fi +######################## +# EDITORCONFIG LINTING # +######################## +echo ed: "$VALIDATE_EDITORCONFIG" +if [ "$VALIDATE_EDITORCONFIG" == "true" ]; then + #################################### + # Lint the files with editorconfig # + #################################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "EDITORCONFIG" "editorconfig-checker" "editorconfig-checker" "^.*$" "${FILE_ARRAY_ENV[@]}" +fi + ################## # DOCKER LINTING # ################## diff --git a/lib/validation.sh b/lib/validation.sh index 988abea5..6edaadb9 100755 --- a/lib/validation.sh +++ b/lib/validation.sh @@ -71,6 +71,7 @@ function GetValidationInfo() { VALIDATE_KOTLIN=$(echo "$VALIDATE_KOTLIN" | awk '{print tolower($0)}') VALIDATE_PROTOBUF=$(echo "$VALIDATE_PROTOBUF" | awk '{print tolower($0)}') VALIDATE_OPENAPI=$(echo "$VALIDATE_OPENAPI" | awk '{print tolower($0)}') + VALIDATE_EDITORCONFIG=$(echo "$VALIDATE_EDITORCONFIG" | awk '{print tolower($0)}') ################################################ # Determine if any linters were explicitly set # @@ -100,7 +101,8 @@ function GetValidationInfo() { $VALIDATE_CLOJURE || -n \ $VALIDATE_PROTOBUF || -n \ $VALIDATE_OPENAPI || -n \ - $VALIDATE_KOTLIN ]]; then + $VALIDATE_KOTLIN || -n \ + $VALIDATE_EDITORCONFIG ]]; then ANY_SET="true" fi @@ -454,6 +456,20 @@ function GetValidationInfo() { VALIDATE_CLOJURE="true" fi + ############################################ + # Validate if we should check editorconfig # + ############################################ + if [[ $ANY_SET == "true" ]]; then + # Some linter flags were set - only run those set to true + if [[ -z $VALIDATE_EDITORCONFIG ]]; then + # EDITORCONFIG flag was not set - default to false + VALIDATE_EDITORCONFIG="false" + fi + else + # No linter flags were set - default all to true + VALIDATE_EDITORCONFIG="true" + fi + ####################################### # Print which linters we are enabling # ####################################### @@ -582,6 +598,11 @@ function GetValidationInfo() { else PRINT_ARRAY+=("- Excluding [PROTOBUF] files in code base...") fi + if [[ $VALIDATE_EDITORCONFIG == "true" ]]; then + PRINT_ARRAY+=("- Validating [EDITORCONFIG] files in code base...") + else + PRINT_ARRAY+=("- Excluding [EDITORCONFIG] files in code base...") + fi ############################## # Validate Ansible Directory #