From 5b13acee46a0eadcd57601d14c7767701faf08db Mon Sep 17 00:00:00 2001 From: Nito Buendia Date: Tue, 27 Aug 2024 23:00:51 +0800 Subject: [PATCH] feat: add pyink as a Python formatter (#6083) --- .github/linters/.jscpd.json | 1 + Dockerfile | 1 + README.md | 7 +++++-- TEMPLATES/.python-pyink | 0 dependencies/python/pyink.txt | 1 + lib/functions/buildFileList.sh | 1 + lib/functions/linterCommands.sh | 1 + lib/globals/languages.sh | 2 +- lib/globals/linterCommandsOptions.sh | 1 + lib/globals/linterRules.sh | 2 ++ scripts/linterVersions.sh | 1 + .../expected-summary-test-linters-expect-failure-slim.md | 1 + ...xpected-summary-test-linters-expect-failure-standard.md | 1 + .../expected-summary-test-linters-expect-success-slim.md | 1 + ...xpected-summary-test-linters-expect-success-standard.md | 1 + .../table/expected-summary-test-linters-fix-mode-slim.md | 1 + .../expected-summary-test-linters-fix-mode-standard.md | 1 + test/inspec/super-linter/controls/super_linter.rb | 3 +++ test/linters/python_pyink/python_bad_1.py | 4 ++++ test/linters/python_pyink/python_good_1.py | 4 ++++ test/testUtils.sh | 1 + 21 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 TEMPLATES/.python-pyink create mode 100644 dependencies/python/pyink.txt create mode 100644 test/linters/python_pyink/python_bad_1.py create mode 100644 test/linters/python_pyink/python_good_1.py diff --git a/.github/linters/.jscpd.json b/.github/linters/.jscpd.json index cfdc0863e60..e72f5af3c73 100644 --- a/.github/linters/.jscpd.json +++ b/.github/linters/.jscpd.json @@ -30,6 +30,7 @@ "**/test/linters/python_flake8", "**/test/linters/python_isort", "**/test/linters/python_mypy", + "**/test/linters/python_pyink", "**/test/linters/python_pylint", "**/test/linters/python_ruff", "**/test/linters/r", diff --git a/Dockerfile b/Dockerfile index b233c903b1d..1c6508c7283 100644 --- a/Dockerfile +++ b/Dockerfile @@ -404,6 +404,7 @@ ENV PATH="${PATH}:/venvs/cpplint/bin" ENV PATH="${PATH}:/venvs/flake8/bin" ENV PATH="${PATH}:/venvs/isort/bin" ENV PATH="${PATH}:/venvs/mypy/bin" +ENV PATH="${PATH}:/venvs/pyink/bin" ENV PATH="${PATH}:/venvs/pylint/bin" ENV PATH="${PATH}:/venvs/ruff/bin" ENV PATH="${PATH}:/venvs/snakefmt/bin" diff --git a/README.md b/README.md index 4853724bc53..e84e4027e11 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ Super-linter supports the following tools: | **Amazon States Language** | [ASL Validator](https://github.com/ChristopheBougere/asl-validator) | See JSON formatters | | **AWS CloudFormation templates** | [AWS CloudFormation Linter (cfn-lint)](https://github.com/aws-cloudformation/cfn-lint), [Checkov](https://www.checkov.io/) | See YAML formatters | | **Azure Resource Manager (ARM)** | [Azure Resource Manager Template Toolkit (arm-ttk)](https://github.com/azure/arm-ttk), [Checkov](https://www.checkov.io/) | See JSON formatters | -| **C**, **C++++** | [cpp-lint](https://github.com/cpplint/cpplint) | [clang-format](https://clang.llvm.org/docs/ClangFormatStyleOptions.html) | +| **C**, **C++** | [cpp-lint](https://github.com/cpplint/cpplint) | [clang-format](https://clang.llvm.org/docs/ClangFormatStyleOptions.html) | | **C#** | See Dotnet solutions | [dotnet format whitespace command](https://github.com/dotnet/format) | | **CSS**, **SCSS**, **Sass** | [stylelint](https://stylelint.io/) | [Prettier](https://prettier.io/) | | **Clojure** | [clj-kondo](https://github.com/borkdude/clj-kondo) | | @@ -92,7 +92,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 (Protobuf)** | [protolint](https://github.com/yoheimuta/protolint) | | -| **Python3** | [pylint](https://pylint.pycqa.org/), [flake8](https://flake8.pycqa.org/en/latest/), [isort](https://pypi.org/project/isort/), [ruff](https://github.com/astral-sh/ruff) | [black](https://github.com/psf/black) | +| **Python3** | [pylint](https://pylint.pycqa.org/), [flake8](https://flake8.pycqa.org/en/latest/), [isort](https://pypi.org/project/isort/), [ruff](https://github.com/astral-sh/ruff) | [black](https://github.com/psf/black), [pyink](https://github.com/google/pyink) | | **R** | [lintr](https://github.com/jimhester/lintr) | | | **Raku** | [Raku](https://raku.org) | | | **Renovate** | [renovate-config-validator](https://docs.renovatebot.com/config-validation/) | N/A | @@ -244,6 +244,7 @@ You can configure Super-linter using the following environment variables: | **FIX_PROTOBUF** | `false` | Option to enable fix mode for `PROTOBUF`. | | **FIX_PYTHON_BLACK** | `false` | Option to enable fix mode for `PYTHON_BLACK`. | | **FIX_PYTHON_ISORT** | `false` | Option to enable fix mode for `PYTHON_ISORT`. | +| **FIX_PYTHON_PYINK** | `false` | Option to enable fix mode for `PYTHON_PYINK`. | | **FIX_PYTHON_RUFF** | `false` | Option to enable fix mode for `PYTHON_RUFF`. | | **FIX_RUBY** | `false` | Option to enable fix mode for `RUBY`. | | **FIX_RUST_2015** | `false` | Option to enable fix mode for `RUST_2015`. | @@ -291,6 +292,7 @@ You can configure Super-linter using the following environment variables: | **PYTHON_FLAKE8_CONFIG_FILE** | `.flake8` | Filename for [flake8 configuration](https://flake8.pycqa.org/en/latest/user/configuration.html) (ex: `.flake8`, `tox.ini`) | | **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_PYINK_CONFIG_FILE** | `.python-pyink` | Filename for [pyink configuration](https://github.com/google/pyink?tab=readme-ov-file#how-do-i-use-pyink) (ex: `.isort.cfg`, `pyproject.toml`) | | **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`) | @@ -377,6 +379,7 @@ You can configure Super-linter using the following environment variables: | **VALIDATE_PYTHON_FLAKE8** | `true` | Flag to enable or disable the linting process of the Python language. (Utilizing: flake8) | | **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_PYINK** | `true` | Flag to enable or disable the linting process of the Python language. (Utilizing: pyink) | | **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. | diff --git a/TEMPLATES/.python-pyink b/TEMPLATES/.python-pyink new file mode 100644 index 00000000000..e69de29bb2d diff --git a/dependencies/python/pyink.txt b/dependencies/python/pyink.txt new file mode 100644 index 00000000000..b4e4a4c414b --- /dev/null +++ b/dependencies/python/pyink.txt @@ -0,0 +1 @@ +pyink==24.3.0 diff --git a/lib/functions/buildFileList.sh b/lib/functions/buildFileList.sh index 7d044190965..87c3b9c3dc3 100755 --- a/lib/functions/buildFileList.sh +++ b/lib/functions/buildFileList.sh @@ -469,6 +469,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_PYINK" echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-PYTHON_RUFF" elif [ "${FILE_TYPE}" == "raku" ] || [ "${FILE_TYPE}" == "rakumod" ] || [ "${FILE_TYPE}" == "rakutest" ] || [ "${FILE_TYPE}" == "pm6" ] || diff --git a/lib/functions/linterCommands.sh b/lib/functions/linterCommands.sh index 64c9e29d5be..2a5268628ae 100755 --- a/lib/functions/linterCommands.sh +++ b/lib/functions/linterCommands.sh @@ -132,6 +132,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 --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_PYINK=(pyink --config "${PYTHON_PYINK_LINTER_RULES}") 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) diff --git a/lib/globals/languages.sh b/lib/globals/languages.sh index 1ea94d6044a..d5839fd55c0 100755 --- a/lib/globals/languages.sh +++ b/lib/globals/languages.sh @@ -29,7 +29,7 @@ LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'BASH_EXEC' 'CHECKOV' 'CLANG_FORMAT' "MARKDOWN_PRETTIER" 'NATURAL_LANGUAGE' 'OPENAPI' 'PERL' 'PHP_BUILTIN' 'PHP_PHPCS' 'PHP_PHPSTAN' 'PHP_PSALM' 'POWERSHELL' 'PROTOBUF' 'PYTHON_BLACK' 'PYTHON_PYLINT' - 'PYTHON_FLAKE8' 'PYTHON_ISORT' 'PYTHON_MYPY' 'PYTHON_RUFF' + 'PYTHON_FLAKE8' 'PYTHON_ISORT' 'PYTHON_MYPY' 'PYTHON_PYINK' 'PYTHON_RUFF' 'R' 'RAKU' 'RENOVATE' 'RUBY' 'RUST_2015' 'RUST_2018' 'RUST_2021' 'RUST_CLIPPY' 'SCALAFMT' 'SHELL_SHFMT' 'SNAKEMAKE_LINT' 'SNAKEMAKE_SNAKEFMT' 'STATES' 'SQLFLUFF' 'TEKTON' diff --git a/lib/globals/linterCommandsOptions.sh b/lib/globals/linterCommandsOptions.sh index 87785689d6b..9e1572b1680 100755 --- a/lib/globals/linterCommandsOptions.sh +++ b/lib/globals/linterCommandsOptions.sh @@ -27,6 +27,7 @@ JSX_PRETTIER_CHECK_ONLY_MODE_OPTIONS=("${PRETTIER_CHECK_ONLY_MODE_OPTIONS[@]}") MARKDOWN_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) +PYTHON_PYINK_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[@]}") diff --git a/lib/globals/linterRules.sh b/lib/globals/linterRules.sh index ce9d67d9102..2aee44ae7d2 100755 --- a/lib/globals/linterRules.sh +++ b/lib/globals/linterRules.sh @@ -78,6 +78,8 @@ PYTHON_ISORT_FILE_NAME="${PYTHON_ISORT_CONFIG_FILE:-.isort.cfg}" # shellcheck disable=SC2034 # Variable is referenced indirectly PYTHON_MYPY_FILE_NAME="${PYTHON_MYPY_CONFIG_FILE:-.mypy.ini}" # shellcheck disable=SC2034 # Variable is referenced indirectly +PYTHON_PYINK_FILE_NAME="${PYTHON_PYINK_CONFIG_FILE:-.python-pyink}" +# 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}" diff --git a/scripts/linterVersions.sh b/scripts/linterVersions.sh index 91cf11f7d41..0fbbb4edc2f 100755 --- a/scripts/linterVersions.sh +++ b/scripts/linterVersions.sh @@ -56,6 +56,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_PYINK']="pyink" LINTER_NAMES_ARRAY['PYTHON_RUFF']="ruff" LINTER_NAMES_ARRAY['R']="R" LINTER_NAMES_ARRAY['RAKU']="raku" diff --git a/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-expect-failure-slim.md b/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-expect-failure-slim.md index a2a66501afb..5124d191a96 100644 --- a/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-expect-failure-slim.md +++ b/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-expect-failure-slim.md @@ -60,6 +60,7 @@ | PYTHON_FLAKE8 | Fail ❌ | | PYTHON_ISORT | Fail ❌ | | PYTHON_MYPY | Fail ❌ | +| PYTHON_PYINK | Fail ❌ | | PYTHON_RUFF | Fail ❌ | | R | Fail ❌ | | RAKU | Fail ❌ | diff --git a/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-expect-failure-standard.md b/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-expect-failure-standard.md index 30579e2e84d..0122b866003 100644 --- a/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-expect-failure-standard.md +++ b/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-expect-failure-standard.md @@ -66,6 +66,7 @@ | PYTHON_FLAKE8 | Fail ❌ | | PYTHON_ISORT | Fail ❌ | | PYTHON_MYPY | Fail ❌ | +| PYTHON_PYINK | Fail ❌ | | PYTHON_RUFF | Fail ❌ | | R | Fail ❌ | | RAKU | Fail ❌ | diff --git a/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-expect-success-slim.md b/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-expect-success-slim.md index e36a14ac869..9b41f8eecbf 100644 --- a/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-expect-success-slim.md +++ b/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-expect-success-slim.md @@ -60,6 +60,7 @@ | PYTHON_FLAKE8 | Pass ✅ | | PYTHON_ISORT | Pass ✅ | | PYTHON_MYPY | Pass ✅ | +| PYTHON_PYINK | Pass ✅ | | PYTHON_RUFF | Pass ✅ | | R | Pass ✅ | | RAKU | Pass ✅ | diff --git a/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-expect-success-standard.md b/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-expect-success-standard.md index a0134357ab6..b7375845d46 100644 --- a/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-expect-success-standard.md +++ b/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-expect-success-standard.md @@ -66,6 +66,7 @@ | PYTHON_FLAKE8 | Pass ✅ | | PYTHON_ISORT | Pass ✅ | | PYTHON_MYPY | Pass ✅ | +| PYTHON_PYINK | Pass ✅ | | PYTHON_RUFF | Pass ✅ | | R | Pass ✅ | | RAKU | Pass ✅ | diff --git a/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-fix-mode-slim.md b/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-fix-mode-slim.md index 6cefc3d6d1f..9ab0be6fe1f 100644 --- a/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-fix-mode-slim.md +++ b/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-fix-mode-slim.md @@ -30,6 +30,7 @@ | PROTOBUF | Fail ❌ | | PYTHON_BLACK | Pass ✅ | | PYTHON_ISORT | Pass ✅ | +| PYTHON_PYINK | Pass ✅ | | PYTHON_RUFF | Pass ✅ | | RUBY | Fail ❌ | | SCALAFMT | Pass ✅ | diff --git a/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-fix-mode-standard.md b/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-fix-mode-standard.md index 7a98737b22f..3583eabf9c8 100644 --- a/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-fix-mode-standard.md +++ b/test/data/super-linter-summary/markdown/table/expected-summary-test-linters-fix-mode-standard.md @@ -35,6 +35,7 @@ | PROTOBUF | Fail ❌ | | PYTHON_BLACK | Pass ✅ | | PYTHON_ISORT | Pass ✅ | +| PYTHON_PYINK | Pass ✅ | | PYTHON_RUFF | Pass ✅ | | RUBY | Fail ❌ | | RUST_2015 | Pass ✅ | diff --git a/test/inspec/super-linter/controls/super_linter.rb b/test/inspec/super-linter/controls/super_linter.rb index 45db24e9292..7f8ba16059a 100644 --- a/test/inspec/super-linter/controls/super_linter.rb +++ b/test/inspec/super-linter/controls/super_linter.rb @@ -186,6 +186,7 @@ { linter_name: "protolint", version_option: "version"}, { linter_name: "psalm"}, { linter_name: "pwsh"}, + { linter_name: "pyink"}, { linter_name: "pylint"}, { linter_name: "R", version_command: "R --slave -e \"r_ver <- R.Version()\\$version.string; \ lintr_ver <- packageVersion('lintr'); \ @@ -405,6 +406,7 @@ "flake8", "isort", "mypy", + "pyink", "pylint", "ruff", "snakefmt", @@ -511,6 +513,7 @@ "/action/lib/.automation/.protolintrc.yml", "/action/lib/.automation/.python-black", "/action/lib/.automation/.python-lint", + "/action/lib/.automation/.python-pyink", "/action/lib/.automation/.ruby-lint.yml", "/action/lib/.automation/.ruff.toml", "/action/lib/.automation/.scalafmt.conf", diff --git a/test/linters/python_pyink/python_bad_1.py b/test/linters/python_pyink/python_bad_1.py new file mode 100644 index 00000000000..93bc7e9203e --- /dev/null +++ b/test/linters/python_pyink/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_pyink/python_good_1.py b/test/linters/python_pyink/python_good_1.py new file mode 100644 index 00000000000..0a96ed493f9 --- /dev/null +++ b/test/linters/python_pyink/python_good_1.py @@ -0,0 +1,4 @@ +a = 1 +b = 2 +c = a + b +print(c) diff --git a/test/testUtils.sh b/test/testUtils.sh index f18406e3ca6..1bb91b44a36 100755 --- a/test/testUtils.sh +++ b/test/testUtils.sh @@ -53,6 +53,7 @@ LANGUAGES_WITH_FIX_MODE=( "PROTOBUF" "PYTHON_BLACK" "PYTHON_ISORT" + "PYTHON_PYINK" "PYTHON_RUFF" "RUBY" "RUST_2015"