From e71a37d49d588b33a0d6e10f364a682e7704460e Mon Sep 17 00:00:00 2001 From: Junya Okabe <86868255+Okabe-Junya@users.noreply.github.com> Date: Wed, 10 Apr 2024 21:02:28 +0900 Subject: [PATCH] feat: add depndency (#5456) feat: configure ruff feat: update the orchestration scripts feat: update the test suite docs: update README feat: add test cases for ruff fix: CI error chore: del .github/linters/.ruff.toml fix: CI error fix: README update: LINTER_NAMES_ARRAY fix: Dockerfile fix: .github/linters/.jscpd.json fix: test files fix: del version_command --- .github/linters/.jscpd.json | 1 + Dockerfile | 1 + README.md | 4 +++- TEMPLATES/.ruff.toml | 5 +++++ dependencies/python/ruff.txt | 1 + lib/functions/buildFileList.sh | 1 + lib/functions/linterCommands.sh | 1 + lib/linter.sh | 5 ++++- scripts/linterVersions.sh | 1 + test/inspec/super-linter/controls/super_linter.rb | 3 +++ test/linters/python_ruff/python_bad_1.py | 4 ++++ test/linters/python_ruff/python_good_1.py | 4 ++++ 12 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 TEMPLATES/.ruff.toml create mode 100644 dependencies/python/ruff.txt create mode 100644 test/linters/python_ruff/python_bad_1.py create mode 100644 test/linters/python_ruff/python_good_1.py diff --git a/.github/linters/.jscpd.json b/.github/linters/.jscpd.json index dc1510de..97992f89 100644 --- a/.github/linters/.jscpd.json +++ b/.github/linters/.jscpd.json @@ -27,6 +27,7 @@ "**/test/linters/python_isort", "**/test/linters/python_mypy", "**/test/linters/python_pylint", + "**/test/linters/python_ruff", "**/test/linters/r", "**/test/linters/ruby", "**/test/linters/rust_2015", diff --git a/Dockerfile b/Dockerfile index 2d2d8d2a..c47ba82e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -383,6 +383,7 @@ ENV PATH="${PATH}:/venvs/flake8/bin" ENV PATH="${PATH}:/venvs/isort/bin" ENV PATH="${PATH}:/venvs/mypy/bin" ENV PATH="${PATH}:/venvs/pylint/bin" +ENV PATH="${PATH}:/venvs/ruff/bin" ENV PATH="${PATH}:/venvs/snakefmt/bin" ENV PATH="${PATH}:/venvs/snakemake/bin" ENV PATH="${PATH}:/venvs/sqlfluff/bin" diff --git a/README.md b/README.md index 86f7a349..b3e2f5f7 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ Super-linter supports the following tools: | **PHP** | [PHP built-in linter](https://www.php.net/manual/en/features.commandline.options.php) / [PHP CodeSniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer) / [PHPStan](https://phpstan.org/) / [Psalm](https://psalm.dev/) | | **PowerShell** | [PSScriptAnalyzer](https://github.com/PowerShell/Psscriptanalyzer) | | **Protocol Buffers** | [protolint](https://github.com/yoheimuta/protolint) | -| **Python3** | [pylint](https://pylint.pycqa.org/) / [flake8](https://flake8.pycqa.org/en/latest/) / [black](https://github.com/psf/black) / [isort](https://pypi.org/project/isort/) | +| **Python3** | [pylint](https://pylint.pycqa.org/) / [flake8](https://flake8.pycqa.org/en/latest/) / [black](https://github.com/psf/black) / [isort](https://pypi.org/project/isort/) / [ruff](https://github.com/astral-sh/ruff) | | **R** | [lintr](https://github.com/jimhester/lintr) | | **Raku** | [Raku](https://raku.org) | | **Renovate** | [renovate-config-validator](https://docs.renovatebot.com/config-validation/) | @@ -232,6 +232,7 @@ You can configure super-linter using the following environment variables: | **PYTHON_ISORT_CONFIG_FILE** | `.isort.cfg` | Filename for [isort configuration](https://pycqa.github.io/isort/docs/configuration/config_files.html) (ex: `.isort.cfg`, `pyproject.toml`) | | **PYTHON_MYPY_CONFIG_FILE** | `.mypy.ini` | Filename for [mypy configuration](https://mypy.readthedocs.io/en/stable/config_file.html) (ex: `.mypy.ini`, `setup.config`) | | **PYTHON_PYLINT_CONFIG_FILE** | `.python-lint` | Filename for [pylint configuration](https://pylint.pycqa.org/en/latest/user_guide/run.html?highlight=rcfile#command-line-options) (ex: `.python-lint`, `.pylintrc`) | +| **PYTHON_RUFF_CONFIG_FILE** | `.ruff.toml` | Filename for [ruff configuration](https://docs.astral.sh/ruff/configuration/) | | **RENOVATE_SHAREABLE_CONFIG_PRESET_FILE_NAMES** | not set | Comma-separated filenames for [renovate shareable config preset](https://docs.renovatebot.com/config-presets/) (ex: `default.json`) | | **RUBY_CONFIG_FILE** | `.ruby-lint.yml` | Filename for [rubocop configuration](https://docs.rubocop.org/rubocop/configuration.html) (ex: `.ruby-lint.yml`, `.rubocop.yml`) | | **SCALAFMT_CONFIG_FILE** | `.scalafmt.conf` | Filename for [scalafmt configuration](https://scalameta.org/scalafmt/docs/configuration.html) (ex: `.scalafmt.conf`) | @@ -302,6 +303,7 @@ You can configure super-linter using the following environment variables: | **VALIDATE_PYTHON_ISORT** | `true` | Flag to enable or disable the linting process of the Python language. (Utilizing: isort) | | **VALIDATE_PYTHON_MYPY** | `true` | Flag to enable or disable the linting process of the Python language. (Utilizing: mypy) | | **VALIDATE_PYTHON_PYLINT** | `true` | Flag to enable or disable the linting process of the Python language. (Utilizing: pylint) | +| **VALIDATE_PYTHON_RUFF** | `true` | Flag to enable or disable the linting process of the Python language. (Utilizing: ruff) | | **VALIDATE_R** | `true` | Flag to enable or disable the linting process of the R language. | | **VALIDATE_RAKU** | `true` | Flag to enable or disable the linting process of the Raku language. | | **VALIDATE_RENOVATE** | `true` | Flag to enable or disable the linting process of the Renovate configuration files. | diff --git a/TEMPLATES/.ruff.toml b/TEMPLATES/.ruff.toml new file mode 100644 index 00000000..b22a41fa --- /dev/null +++ b/TEMPLATES/.ruff.toml @@ -0,0 +1,5 @@ +# Same as .flake8 +line-length = 120 + +[lint] +ignore = ["E203"] diff --git a/dependencies/python/ruff.txt b/dependencies/python/ruff.txt new file mode 100644 index 00000000..e43c0da3 --- /dev/null +++ b/dependencies/python/ruff.txt @@ -0,0 +1 @@ +ruff==0.3.4 diff --git a/lib/functions/buildFileList.sh b/lib/functions/buildFileList.sh index 2975f923..c54122a8 100755 --- a/lib/functions/buildFileList.sh +++ b/lib/functions/buildFileList.sh @@ -437,6 +437,7 @@ BuildFileArrays() { echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-PYTHON_ISORT" echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-PYTHON_PYLINT" echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-PYTHON_MYPY" + echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-PYTHON_RUFF" elif [ "${FILE_TYPE}" == "raku" ] || [ "${FILE_TYPE}" == "rakumod" ] || [ "${FILE_TYPE}" == "rakutest" ] || [ "${FILE_TYPE}" == "pm6" ] || [ "${FILE_TYPE}" == "pl6" ] || [ "${FILE_TYPE}" == "p6" ]; then diff --git a/lib/functions/linterCommands.sh b/lib/functions/linterCommands.sh index f26bdae9..6210f116 100755 --- a/lib/functions/linterCommands.sh +++ b/lib/functions/linterCommands.sh @@ -97,6 +97,7 @@ LINTER_COMMANDS_ARRAY_PYTHON_PYLINT=(pylint --rcfile "${PYTHON_PYLINT_LINTER_RUL LINTER_COMMANDS_ARRAY_PYTHON_FLAKE8=(flake8 --config="${PYTHON_FLAKE8_LINTER_RULES}") LINTER_COMMANDS_ARRAY_PYTHON_ISORT=(isort --check --diff --sp "${PYTHON_ISORT_LINTER_RULES}") LINTER_COMMANDS_ARRAY_PYTHON_MYPY=(mypy --config-file "${PYTHON_MYPY_LINTER_RULES}" --install-types --non-interactive) +LINTER_COMMANDS_ARRAY_PYTHON_RUFF=(ruff check --config "${PYTHON_RUFF_LINTER_RULES}") LINTER_COMMANDS_ARRAY_R=(R --slave -e "\"lints <- lintr::lint('{}');print(lints);errors <- purrr::keep(lints, ~ .\\\$type == 'error');quit(save = 'no', status = if (length(errors) > 0) 1 else 0)\"") LINTER_COMMANDS_ARRAY_RAKU=(raku) LINTER_COMMANDS_ARRAY_RENOVATE=(renovate-config-validator --strict) diff --git a/lib/linter.sh b/lib/linter.sh index a04109cc..a73aff92 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -223,6 +223,8 @@ PYTHON_MYPY_FILE_NAME="${PYTHON_MYPY_CONFIG_FILE:-.mypy.ini}" # shellcheck disable=SC2034 # Variable is referenced indirectly PYTHON_PYLINT_FILE_NAME="${PYTHON_PYLINT_CONFIG_FILE:-.python-lint}" # shellcheck disable=SC2034 # Variable is referenced indirectly +PYTHON_RUFF_FILE_NAME="${PYTHON_RUFF_CONFIG_FILE:-.ruff.toml}" +# shellcheck disable=SC2034 # Variable is referenced indirectly R_FILE_NAME=".lintr" # shellcheck disable=SC2034 # Variable is referenced indirectly RUBY_FILE_NAME="${RUBY_CONFIG_FILE:-.ruby-lint.yml}" @@ -293,7 +295,8 @@ LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'BASH_EXEC' 'CHECKOV' 'CLANG_FORMAT' 'KUBERNETES_KUBECONFORM' 'KOTLIN' 'LATEX' 'LUA' 'MARKDOWN' 'NATURAL_LANGUAGE' 'OPENAPI' 'PERL' 'PHP_BUILTIN' 'PHP_PHPCS' 'PHP_PHPSTAN' 'PHP_PSALM' 'POWERSHELL' 'PROTOBUF' 'PYTHON_BLACK' 'PYTHON_PYLINT' - 'PYTHON_FLAKE8' 'PYTHON_ISORT' 'PYTHON_MYPY' 'R' 'RAKU' 'RENOVATE' 'RUBY' 'RUST_2015' + 'PYTHON_FLAKE8' 'PYTHON_ISORT' 'PYTHON_MYPY' 'PYTHON_RUFF' + 'R' 'RAKU' 'RENOVATE' 'RUBY' 'RUST_2015' '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' diff --git a/scripts/linterVersions.sh b/scripts/linterVersions.sh index a785ca06..0fd85a84 100755 --- a/scripts/linterVersions.sh +++ b/scripts/linterVersions.sh @@ -54,6 +54,7 @@ LINTER_NAMES_ARRAY['PYTHON_PYLINT']="pylint" LINTER_NAMES_ARRAY['PYTHON_FLAKE8']="flake8" LINTER_NAMES_ARRAY['PYTHON_ISORT']="isort" LINTER_NAMES_ARRAY['PYTHON_MYPY']="mypy" +LINTER_NAMES_ARRAY['PYTHON_RUFF']="ruff" LINTER_NAMES_ARRAY['R']="R" LINTER_NAMES_ARRAY['RAKU']="raku" LINTER_NAMES_ARRAY['RENOVATE']="renovate-config-validator" diff --git a/test/inspec/super-linter/controls/super_linter.rb b/test/inspec/super-linter/controls/super_linter.rb index cae05fc8..853dee35 100644 --- a/test/inspec/super-linter/controls/super_linter.rb +++ b/test/inspec/super-linter/controls/super_linter.rb @@ -183,6 +183,7 @@ control "super-linter-installed-commands" do { linter_name: "raku", version_command: "raku --version | strings -n 8"}, { linter_name: "renovate-config-validator", version_command: "renovate --version"}, { linter_name: "rubocop"}, + { linter_name: "ruff"}, { linter_name: "rustfmt"}, { linter_name: "scalafmt"}, { linter_name: "shellcheck"}, @@ -395,6 +396,7 @@ control "super-linter-installed-pypi-packages" do "isort", "mypy", "pylint", + "ruff", "snakefmt", "snakemake", "sqlfluff", @@ -495,6 +497,7 @@ control "super-linter-validate-files" do "/action/lib/.automation/.python-black", "/action/lib/.automation/.python-lint", "/action/lib/.automation/.ruby-lint.yml", + "/action/lib/.automation/.ruff.toml", "/action/lib/.automation/.scalafmt.conf", "/action/lib/.automation/.snakefmt.toml", "/action/lib/.automation/.sql-config.json", diff --git a/test/linters/python_ruff/python_bad_1.py b/test/linters/python_ruff/python_bad_1.py new file mode 100644 index 00000000..93bc7e92 --- /dev/null +++ b/test/linters/python_ruff/python_bad_1.py @@ -0,0 +1,4 @@ +a=1;b=2 +c=a+b +BROKEN_VAR=BROKEN_VAR +print(c) diff --git a/test/linters/python_ruff/python_good_1.py b/test/linters/python_ruff/python_good_1.py new file mode 100644 index 00000000..0a96ed49 --- /dev/null +++ b/test/linters/python_ruff/python_good_1.py @@ -0,0 +1,4 @@ +a = 1 +b = 2 +c = a + b +print(c)