diff --git a/.github/linters/.jscpd.json b/.github/linters/.jscpd.json index 1098d1f0..3999d690 100644 --- a/.github/linters/.jscpd.json +++ b/.github/linters/.jscpd.json @@ -36,6 +36,8 @@ "**/test/linters/scalafmt", "**/test/linters/tekton/**", "**/test/linters/typescript_es/**", + "**/test/linters/typescript_prettier/**", + "**/test/linters/typescript_standard/**", "**/github_conf/**", "**/workflows/cd.yml", "**/workflows/ci.yml" diff --git a/.github/linters/commitlint.config.js b/.github/linters/commitlint.config.js index c84589e4..9730e91f 100644 --- a/.github/linters/commitlint.config.js +++ b/.github/linters/commitlint.config.js @@ -1,7 +1,7 @@ module.exports = { - extends: ['@commitlint/config-conventional'], - helpUrl: 'https://www.conventionalcommits.org/', + extends: ["@commitlint/config-conventional"], + helpUrl: "https://www.conventionalcommits.org/", // We need this until https://github.com/dependabot/dependabot-core/issues/2445 // is resolved. - ignores: [(msg) => /Signed-off-by: dependabot\[bot]/m.test(msg)] -} + ignores: [(msg) => /Signed-off-by: dependabot\[bot]/m.test(msg)], +}; diff --git a/README.md b/README.md index 95a10479..c05226fa 100644 --- a/README.md +++ b/README.md @@ -216,7 +216,6 @@ You can configure super-linter using the following environment variables: | **IGNORE_GENERATED_FILES** | `false` | If set to `true`, super-linter will ignore all the files with `@generated` marker but without `@not-generated` marker. | | **IGNORE_GITIGNORED_FILES** | `false` | If set to `true`, super-linter will ignore all the files that are ignored by Git. | | **JAVA_FILE_NAME** | `sun_checks.xml` | Filename for [Checkstyle configuration](https://checkstyle.sourceforge.io/config.html). Checkstyle embeds several configuration files, such as `sun_checks.xml`, `google_checks.xml` that you can use without providing your own configuration file. | -| **JAVASCRIPT_DEFAULT_STYLE** | `standard` | Flag to set the default style of JavaScript. Available options: **standard**/**prettier** | | **JAVASCRIPT_ES_CONFIG_FILE** | `.eslintrc.yml` | Filename for [ESLint configuration](https://eslint.org/docs/user-guide/configuring#configuration-file-formats) (ex: `.eslintrc.yml`, `.eslintrc.json`) | | **JSCPD_CONFIG_FILE** | `.jscpd.json` | Filename for JSCPD configuration | | **KUBERNETES_KUBECONFORM_OPTIONS** | `null` | Additional arguments to pass to the command-line when running **Kubernetes Kubeconform** (Example: --ignore-missing-schemas) | @@ -254,7 +253,6 @@ You can configure super-linter using the following environment variables: | **SUPPRESS_POSSUM** | `false` | If set to `true`, will hide the ASCII possum at top of log output. Default is `false` | | **TERRAFORM_TERRASCAN_CONFIG_FILE** | `terrascan.toml` | Filename for [terrascan configuration](https://github.com/accurics/terrascan) (ex: `terrascan.toml`) | | **TERRAFORM_TFLINT_CONFIG_FILE** | `.tflint.hcl` | Filename for [tfLint configuration](https://github.com/terraform-linters/tflint) (ex: `.tflint.hcl`) | -| **TYPESCRIPT_DEFAULT_STYLE** | `ts-standard` | Flag to set the default style of TypeScript. Available options: **ts-standard**/**prettier** | | **TYPESCRIPT_ES_CONFIG_FILE** | `.eslintrc.yml` | Filename for [ESLint configuration](https://eslint.org/docs/user-guide/configuring#configuration-file-formats) (ex: `.eslintrc.yml`, `.eslintrc.json`) | | **TYPESCRIPT_STANDARD_TSCONFIG_FILE** | `${DEFAULT_WORKSPACE}/tsconfig.json` | Path to the [TypeScript project configuration](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) in [ts-standard](https://github.com/standard/ts-standard). The path is relative to `DEFAULT_WORKSPACE` | | **USE_FIND_ALGORITHM** | `false` | By default, we use `git diff` to find all files in the workspace and what has been updated, this would enable the Linux `find` method instead to find all files to lint | @@ -286,6 +284,7 @@ You can configure super-linter using the following environment variables: | **VALIDATE_HTML** | `true` | Flag to enable or disable the linting process of the HTML language. | | **VALIDATE_JAVA** | `true` | Flag to enable or disable the linting process of the Java language. (Utilizing: checkstyle) | | **VALIDATE_JAVASCRIPT_ES** | `true` | Flag to enable or disable the linting process of the JavaScript language. (Utilizing: ESLint) | +| **VALIDATE_JAVASCRIPT_PRETTIER** | `true` | Flag to enable or disable the linting process of the JavaScript language. (Utilizing: prettier) | | **VALIDATE_JAVASCRIPT_STANDARD** | `true` | Flag to enable or disable the linting process of the JavaScript language. (Utilizing: standard) | | **VALIDATE_JSCPD** | `true` | Flag to enable or disable JSCPD. | | **VALIDATE_JSON** | `true` | Flag to enable or disable the linting process of the JSON language. | @@ -335,6 +334,7 @@ You can configure super-linter using the following environment variables: | **VALIDATE_TERRAGRUNT** | `true` | Flag to enable or disable the linting process for Terragrunt files. | | **VALIDATE_TSX** | `true` | Flag to enable or disable the linting process for tsx files (Utilizing: ESLint) | | **VALIDATE_TYPESCRIPT_ES** | `true` | Flag to enable or disable the linting process of the TypeScript language. (Utilizing: ESLint) | +| **VALIDATE_TYPESCRIPT_PRETTIER** | `true` | Flag to enable or disable the linting process of the TypeScript language. (Utilizing: prettier) | | **VALIDATE_TYPESCRIPT_STANDARD** | `true` | Flag to enable or disable the linting process of the TypeScript language. (Utilizing: ts-standard) | | **VALIDATE_XML** | `true` | Flag to enable or disable the linting process of the XML language. | | **VALIDATE_YAML** | `true` | Flag to enable or disable the linting process of the YAML language. | diff --git a/docs/upgrade-guide.md b/docs/upgrade-guide.md index 02a78ab4..81fb6b6c 100644 --- a/docs/upgrade-guide.md +++ b/docs/upgrade-guide.md @@ -6,7 +6,7 @@ This document helps you upgrade from a super-linter version to newer ones: ## Upgrade from v5 to v6 -This section helps you migrate from super-linter `v5` to `v6`. +This section helps you upgrade from super-linter `v5` to `v6`. ### eslint-config-airbnb-typescript diff --git a/lib/functions/validation.sh b/lib/functions/validation.sh index 4558cc69..87bd1fee 100755 --- a/lib/functions/validation.sh +++ b/lib/functions/validation.sh @@ -119,11 +119,12 @@ function ValidateValidationVariables() { debug "Configuration contains at least one custom value to enable or disable linters." if [ -z "${!VALIDATE_LANGUAGE:-}" ]; then # Flag was not set, default to: - # if ANY_TRUE then set to false - # if ANY_FALSE then set to true + # - true if the configuration provided any false value -> enable linters that the user didn't explicitly disable + # - false if the configuration didn't provid any false value -> disable linters that the user didn't explicitly enable eval "${VALIDATE_LANGUAGE}='$ANY_FALSE'" fi else + # The user didn't provide and configuration value -> enable all linters by default eval "${VALIDATE_LANGUAGE}='true'" debug "Configuration doesn't include any custom values to enable or disable linters. Setting VALIDATE variable for ${LANGUAGE} to: ${!VALIDATE_LANGUAGE}" fi @@ -342,7 +343,7 @@ function WarnIfDeprecatedValueForConfigurationVariableIsSet() { function ValidateDeprecatedVariables() { - # The following variables have been deprecated in v6 + # The following variables have been deprecated in v6.0.0 WarnIfVariableIsSet "${ERROR_ON_MISSING_EXEC_BIT:-}" "ERROR_ON_MISSING_EXEC_BIT" WarnIfVariableIsSet "${EXPERIMENTAL_BATCH_WORKER:-}" "EXPERIMENTAL_BATCH_WORKER" WarnIfVariableIsSet "${VALIDATE_JSCPD_ALL_CODEBASE:-}" "VALIDATE_JSCPD_ALL_CODEBASE" @@ -351,4 +352,8 @@ function ValidateDeprecatedVariables() { # The following values have been deprecated in v6.1.0 WarnIfDeprecatedValueForConfigurationVariableIsSet "${LOG_LEVEL}" "TRACE" "LOG_LEVEL" "DEBUG" WarnIfDeprecatedValueForConfigurationVariableIsSet "${LOG_LEVEL}" "VERBOSE" "LOG_LEVEL" "INFO" + + # The following variables have been deprecated in v7.0.0 + WarnIfVariableIsSet "${JAVASCRIPT_DEFAULT_STYLE:-}" "JAVASCRIPT_DEFAULT_STYLE" + WarnIfVariableIsSet "${TYPESCRIPT_DEFAULT_STYLE:-}" "TYPESCRIPT_DEFAULT_STYLE" } diff --git a/lib/linter.sh b/lib/linter.sh index 096c0210..2f639785 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -195,9 +195,6 @@ JAVA_FILE_NAME="${JAVA_FILE_NAME:-sun_checks.xml}" # shellcheck disable=SC2034 # Variable is referenced indirectly JAVASCRIPT_ES_FILE_NAME="${JAVASCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}" # shellcheck disable=SC2034 # Variable is referenced indirectly -JAVASCRIPT_DEFAULT_STYLE="${JAVASCRIPT_DEFAULT_STYLE:-standard}" -JAVASCRIPT_STYLE_NAME='' # Variable for the style -# shellcheck disable=SC2034 # Variable is referenced indirectly JAVASCRIPT_STANDARD_FILE_NAME="${JAVASCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}" # shellcheck disable=SC2034 # Variable is referenced indirectly JSCPD_FILE_NAME="${JSCPD_CONFIG_FILE:-.jscpd.json}" @@ -261,45 +258,10 @@ NATURAL_LANGUAGE_FILE_NAME="${NATURAL_LANGUAGE_CONFIG_FILE:-.textlintrc}" # shellcheck disable=SC2034 # Variable is referenced indirectly TSX_FILE_NAME="${TYPESCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}" # shellcheck disable=SC2034 # Variable is referenced indirectly -TYPESCRIPT_DEFAULT_STYLE="${TYPESCRIPT_DEFAULT_STYLE:-ts-standard}" -TYPESCRIPT_STYLE_NAME='' # Variable for the style -# shellcheck disable=SC2034 # Variable is referenced indirectly TYPESCRIPT_ES_FILE_NAME="${TYPESCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}" # shellcheck disable=SC2034 # Variable is referenced indirectly YAML_FILE_NAME="${YAML_CONFIG_FILE:-.yaml-lint.yml}" -################################################# -# Parse if we are using JS standard or prettier # -################################################# -# Remove spaces -JAVASCRIPT_DEFAULT_STYLE=$(echo "${JAVASCRIPT_DEFAULT_STYLE}" | tr -d ' ') -# lowercase -JAVASCRIPT_DEFAULT_STYLE=$(echo "${JAVASCRIPT_DEFAULT_STYLE}" | tr '[:upper:]' '[:lower:]') -# Check and set -if [ "${JAVASCRIPT_DEFAULT_STYLE}" == "prettier" ]; then - # Set to prettier - JAVASCRIPT_STYLE_NAME='JAVASCRIPT_PRETTIER' -else - # Default to standard - JAVASCRIPT_STYLE_NAME='JAVASCRIPT_STANDARD' -fi - -################################################# -# Parse if we are using JS standard or prettier # -################################################# -# Remove spaces -TYPESCRIPT_DEFAULT_STYLE=$(echo "${TYPESCRIPT_DEFAULT_STYLE}" | tr -d ' ') -# lowercase -TYPESCRIPT_DEFAULT_STYLE=$(echo "${TYPESCRIPT_DEFAULT_STYLE}" | tr '[:upper:]' '[:lower:]') -# Check and set -if [ "${TYPESCRIPT_DEFAULT_STYLE}" == "prettier" ]; then - # Set to prettier - TYPESCRIPT_STYLE_NAME='TYPESCRIPT_PRETTIER' -else - # Default to standard - TYPESCRIPT_STYLE_NAME='TYPESCRIPT_STANDARD' -fi - ################## # Language array # ################## @@ -307,7 +269,7 @@ LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'BASH_EXEC' 'CHECKOV' 'CLANG_FORMAT' 'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT' 'CPP' 'CSHARP' 'CSS' 'DART' 'DOCKERFILE_HADOLINT' 'EDITORCONFIG' 'ENV' 'GITHUB_ACTIONS' 'GITLEAKS' 'GHERKIN' 'GO' 'GO_MODULES' 'GO_RELEASER' 'GOOGLE_JAVA_FORMAT' 'GROOVY' 'HTML' 'JAVA' - 'JAVASCRIPT_ES' "${JAVASCRIPT_STYLE_NAME}" 'JSCPD' 'JSON' 'JSONC' 'JSX' + 'JAVASCRIPT_ES' 'JAVASCRIPT_PRETTIER' 'JAVASCRIPT_STANDARD' 'JSCPD' 'JSON' 'JSONC' 'JSX' 'KUBERNETES_KUBECONFORM' 'KOTLIN' 'LATEX' 'LUA' 'MARKDOWN' 'NATURAL_LANGUAGE' 'OPENAPI' 'PERL' 'PHP_BUILTIN' 'PHP_PHPCS' 'PHP_PHPSTAN' 'PHP_PSALM' 'POWERSHELL' 'PROTOBUF' 'PYTHON_BLACK' 'PYTHON_PYLINT' @@ -316,7 +278,7 @@ LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'BASH_EXEC' 'CHECKOV' 'CLANG_FORMAT' 'RUST_2018' 'RUST_2021' 'RUST_CLIPPY' 'SCALAFMT' 'SHELL_SHFMT' 'SNAKEMAKE_LINT' 'SNAKEMAKE_SNAKEFMT' 'STATES' 'SQL' 'SQLFLUFF' 'TEKTON' 'TERRAFORM_FMT' 'TERRAFORM_TFLINT' 'TERRAFORM_TERRASCAN' 'TERRAGRUNT' 'TSX' - 'TYPESCRIPT_ES' "${TYPESCRIPT_STYLE_NAME}" 'XML' 'YAML') + 'TYPESCRIPT_ES' 'TYPESCRIPT_PRETTIER' 'TYPESCRIPT_STANDARD' 'XML' 'YAML') ########################## # Array of changed files # diff --git a/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-failure-slim.md b/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-failure-slim.md index bd30bc89..ba0a3938 100644 --- a/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-failure-slim.md +++ b/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-failure-slim.md @@ -28,6 +28,7 @@ | HTML | Fail ❌ | | JAVA | Fail ❌ | | JAVASCRIPT_ES | Fail ❌ | +| JAVASCRIPT_PRETTIER | Fail ❌ | | JAVASCRIPT_STANDARD | Fail ❌ | | JSCPD | Fail ❌ | | JSON | Fail ❌ | @@ -70,6 +71,7 @@ | TERRAGRUNT | Fail ❌ | | TSX | Fail ❌ | | TYPESCRIPT_ES | Fail ❌ | +| TYPESCRIPT_PRETTIER | Fail ❌ | | TYPESCRIPT_STANDARD | Fail ❌ | | XML | Fail ❌ | | YAML | Fail ❌ | diff --git a/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-failure-standard.md b/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-failure-standard.md index c10bbd4b..09fa4f5a 100644 --- a/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-failure-standard.md +++ b/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-failure-standard.md @@ -30,6 +30,7 @@ | HTML | Fail ❌ | | JAVA | Fail ❌ | | JAVASCRIPT_ES | Fail ❌ | +| JAVASCRIPT_PRETTIER | Fail ❌ | | JAVASCRIPT_STANDARD | Fail ❌ | | JSCPD | Fail ❌ | | JSON | Fail ❌ | @@ -77,6 +78,7 @@ | TERRAGRUNT | Fail ❌ | | TSX | Fail ❌ | | TYPESCRIPT_ES | Fail ❌ | +| TYPESCRIPT_PRETTIER | Fail ❌ | | TYPESCRIPT_STANDARD | Fail ❌ | | XML | Fail ❌ | | YAML | Fail ❌ | diff --git a/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-success-slim.md b/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-success-slim.md index 2b0abd61..1fe4f3b4 100644 --- a/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-success-slim.md +++ b/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-success-slim.md @@ -28,6 +28,7 @@ | HTML | Pass ✅ | | JAVA | Pass ✅ | | JAVASCRIPT_ES | Pass ✅ | +| JAVASCRIPT_PRETTIER | Pass ✅ | | JAVASCRIPT_STANDARD | Pass ✅ | | JSCPD | Pass ✅ | | JSON | Pass ✅ | @@ -70,6 +71,7 @@ | TERRAGRUNT | Pass ✅ | | TSX | Pass ✅ | | TYPESCRIPT_ES | Pass ✅ | +| TYPESCRIPT_PRETTIER | Pass ✅ | | TYPESCRIPT_STANDARD | Pass ✅ | | XML | Pass ✅ | | YAML | Pass ✅ | diff --git a/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-success-standard.md b/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-success-standard.md index 2dabdd66..7f34346d 100644 --- a/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-success-standard.md +++ b/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-success-standard.md @@ -30,6 +30,7 @@ | HTML | Pass ✅ | | JAVA | Pass ✅ | | JAVASCRIPT_ES | Pass ✅ | +| JAVASCRIPT_PRETTIER | Pass ✅ | | JAVASCRIPT_STANDARD | Pass ✅ | | JSCPD | Pass ✅ | | JSON | Pass ✅ | @@ -77,6 +78,7 @@ | TERRAGRUNT | Pass ✅ | | TSX | Pass ✅ | | TYPESCRIPT_ES | Pass ✅ | +| TYPESCRIPT_PRETTIER | Pass ✅ | | TYPESCRIPT_STANDARD | Pass ✅ | | XML | Pass ✅ | | YAML | Pass ✅ | diff --git a/test/linters/typescript_prettier/typescript_bad_1.ts b/test/linters/typescript_prettier/typescript_bad_1.ts new file mode 100644 index 00000000..c9c15a5c --- /dev/null +++ b/test/linters/typescript_prettier/typescript_bad_1.ts @@ -0,0 +1,12 @@ +enum Test { + Hoo = 'hoo' +} + +const spiderman = (person: String) => { + return 'Hello, ' + person; +} + +var handler = createHandler( { path : /webhook, secret : (process.env.SECRET) }) + +let user = 1; +console.log(spiderman(user)); diff --git a/test/linters/typescript_prettier/typescript_good_1.ts b/test/linters/typescript_prettier/typescript_good_1.ts new file mode 100644 index 00000000..2107f22d --- /dev/null +++ b/test/linters/typescript_prettier/typescript_good_1.ts @@ -0,0 +1,11 @@ +enum Test { + Hoo = "hoo", +} + +const spiderman = (person: string): string => { + return `Hello, ${person}`; +}; + +const user = "Peter Parker"; +console.log(spiderman(user)); +console.log(Test.Hoo);