mirror of
https://github.com/super-linter/super-linter.git
synced 2024-12-22 20:52:12 -05:00
91dc6d7234
- Add missing fix mode options for: CLANG_FORMAT, ENV, GOOGLE_JAVA_FORMAT, NATURAL_LANGUAGE, PYTHON_ISORT, RUST_CLIPPY. - Refactor linter tests to make them shorter because there's no need to have big test files. - Refactor 'bad' linter tests for linters that support fix mode so they contain only automatically fixable issues. This is needed to avoid adding another set of 'bad' linter tests for fix mode. - Provide configuration files for linters that support fix mode and for which the default configuration is not suitable to enable fix mode: ansible-lint, ESLint, golangci-lint. - Add a test case for linter commands options for linters that support fix mode, to ensure that fix mode and check-only mode options have been defined. - Refactor the fix mode test to check if linters actually applied modifications to files. - Update documentation about adding test cases for linters that support fix mode. - Don't exit with a fatal error if VALIDATE_xxx is false when testing fix mode because not all linters support fix mode. To enable this, set the new FIX_MODE_TEST_CASE_RUN variable to true.
79 lines
3.9 KiB
Bash
Executable file
79 lines
3.9 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
# shellcheck disable=SC2034 # Disable ununsed variables warning because we
|
|
# source this script and use these variables as globals
|
|
|
|
# "check only" mode options for linters that that we reuse across several languages
|
|
PRETTIER_CHECK_ONLY_MODE_OPTIONS=(--check)
|
|
RUSTFMT_CHECK_ONLY_MODE_OPTIONS=(--check)
|
|
|
|
# Define configuration options to enable "check only" mode.
|
|
# Some linters and formatters only support a "check only" mode so there's no
|
|
# need to define a "check only" mode option for those.
|
|
CLANG_FORMAT_CHECK_ONLY_MODE_OPTIONS=(--dry-run)
|
|
CSHARP_CHECK_ONLY_MODE_OPTIONS=(--verify-no-changes)
|
|
GOOGLE_JAVA_FORMAT_CHECK_ONLY_MODE_OPTIONS=(--dry-run --set-exit-if-changed)
|
|
JAVASCRIPT_PRETTIER_CHECK_ONLY_MODE_OPTIONS=("${PRETTIER_CHECK_ONLY_MODE_OPTIONS[@]}")
|
|
PYTHON_BLACK_CHECK_ONLY_MODE_OPTIONS=(--diff --check)
|
|
PYTHON_ISORT_CHECK_ONLY_MODE_OPTIONS=(--diff --check)
|
|
RUST_2015_CHECK_ONLY_MODE_OPTIONS=("${RUSTFMT_CHECK_ONLY_MODE_OPTIONS[@]}")
|
|
RUST_2018_CHECK_ONLY_MODE_OPTIONS=("${RUSTFMT_CHECK_ONLY_MODE_OPTIONS[@]}")
|
|
RUST_2021_CHECK_ONLY_MODE_OPTIONS=("${RUSTFMT_CHECK_ONLY_MODE_OPTIONS[@]}")
|
|
SCALAFMT_CHECK_ONLY_MODE_OPTIONS=(--test)
|
|
SHELL_SHFMT_CHECK_ONLY_MODE_OPTIONS=(--diff)
|
|
SNAKEMAKE_SNAKEFMT_CHECK_ONLY_MODE_OPTIONS=(--check --compact-diff)
|
|
SQLFLUFF_CHECK_ONLY_MODE_OPTIONS=(lint)
|
|
TERRAFORM_FMT_CHECK_ONLY_MODE_OPTIONS=(-check -diff)
|
|
TYPESCRIPT_PRETTIER_CHECK_ONLY_MODE_OPTIONS=("${PRETTIER_CHECK_ONLY_MODE_OPTIONS[@]}")
|
|
|
|
# Fix mode options for linters that that we reuse across several languages
|
|
ESLINT_FIX_MODE_OPTIONS=(--fix)
|
|
GOLANGCI_LINT_FIX_MODE_OPTIONS=(--fix)
|
|
PRETTIER_FIX_MODE_OPTIONS=(--write)
|
|
STANDARD_FIX_MODE_OPTIONS=(--fix)
|
|
|
|
# Define configuration options to enable "fix mode".
|
|
# Not all linters and formatters support this.
|
|
ANSIBLE_FIX_MODE_OPTIONS=(--fix)
|
|
CLANG_FORMAT_FIX_MODE_OPTIONS=(-i)
|
|
CSS_FIX_MODE_OPTIONS=(--fix)
|
|
ENV_FIX_MODE_OPTIONS=(fix --no-backup)
|
|
GO_FIX_MODE_OPTIONS=("${GOLANGCI_LINT_FIX_MODE_OPTIONS[@]}")
|
|
GO_MODULES_FIX_MODE_OPTIONS=("${GOLANGCI_LINT_FIX_MODE_OPTIONS[@]}")
|
|
GOOGLE_JAVA_FORMAT_FIX_MODE_OPTIONS=(--replace)
|
|
GROOVY_FIX_MODE_OPTIONS=(--fix)
|
|
JAVASCRIPT_ES_FIX_MODE_OPTIONS=("${ESLINT_FIX_MODE_OPTIONS[@]}")
|
|
JAVASCRIPT_PRETTIER_FIX_MODE_OPTIONS=("${PRETTIER_FIX_MODE_OPTIONS[@]}")
|
|
JAVASCRIPT_STANDARD_FIX_MODE_OPTIONS=("${STANDARD_FIX_MODE_OPTIONS[@]}")
|
|
JSON_FIX_MODE_OPTIONS=("${ESLINT_FIX_MODE_OPTIONS[@]}")
|
|
JSONC_FIX_MODE_OPTIONS=("${ESLINT_FIX_MODE_OPTIONS[@]}")
|
|
JSX_FIX_MODE_OPTIONS=("${ESLINT_FIX_MODE_OPTIONS[@]}")
|
|
MARKDOWN_FIX_MODE_OPTIONS=(--fix)
|
|
NATURAL_LANGUAGE_FIX_MODE_OPTIONS=(--fix)
|
|
POWERSHELL_FIX_MODE_OPTIONS=(-Fix)
|
|
PROTOBUF_FIX_MODE_OPTIONS=(-fix)
|
|
PYTHON_ISORT_FIX_MODE_OPTIONS=(--overwrite-in-place)
|
|
PYTHON_RUFF_FIX_MODE_OPTIONS=(--fix)
|
|
RUBY_FIX_MODE_OPTIONS=(--autocorrect)
|
|
RUST_CLIPPY_FIX_MODE_OPTIONS=(--fix --allow-dirty --allow-staged)
|
|
SHELL_SHFMT_FIX_MODE_OPTIONS=(--write)
|
|
SQLFLUFF_FIX_MODE_OPTIONS=(fix)
|
|
TSX_FIX_MODE_OPTIONS=("${ESLINT_FIX_MODE_OPTIONS[@]}")
|
|
TYPESCRIPT_ES_FIX_MODE_OPTIONS=("${ESLINT_FIX_MODE_OPTIONS[@]}")
|
|
TYPESCRIPT_PRETTIER_FIX_MODE_OPTIONS=("${PRETTIER_FIX_MODE_OPTIONS[@]}")
|
|
TYPESCRIPT_STANDARD_FIX_MODE_OPTIONS=("${STANDARD_FIX_MODE_OPTIONS[@]}")
|
|
|
|
# sqlfluff is a special case because it needs a different subcommand and
|
|
# subcommand options
|
|
SQLFLUFF_SHARED_SUBCOMMAND_OPTIONS=(--config "${SQLFLUFF_LINTER_RULES}")
|
|
SQLFLUFF_CHECK_ONLY_MODE_OPTIONS+=("${SQLFLUFF_SHARED_SUBCOMMAND_OPTIONS[@]}")
|
|
SQLFLUFF_FIX_MODE_OPTIONS+=("${SQLFLUFF_SHARED_SUBCOMMAND_OPTIONS[@]}")
|
|
|
|
# If there's no input argument, GNU Parallel adds a default {} at the end of the
|
|
# command it runs. In a few cases, such as ANSIBLE, GO_MODULES, and RUST_CLIPPY,
|
|
# consume the {} element by artifically adding it to the command to run because
|
|
# we need the input to set the working directory, but we don't need it appended
|
|
# at the end of the command.
|
|
# Setting the -n 0 GNU Parallel would not help in this case, because the input
|
|
# will not be passed to the --workdir option as well.
|
|
INPUT_CONSUME_COMMAND=("&& echo \"Linted: {}\"")
|