From 8fdbcc08b68521fd73ccdbcf62ffbfcdadb62223 Mon Sep 17 00:00:00 2001 From: Holt Skinner Date: Wed, 13 Nov 2024 10:49:15 -0600 Subject: [PATCH] feat: Add nbqa linter for Jupyter Notebooks --- Dockerfile | 1 + README.md | 11 ++++++ TEMPLATES/.jupyter-nbqa.toml | 0 dependencies/python/nbqa.txt | 1 + docs/add-new-linter.md | 4 +- lib/functions/buildFileList.sh | 7 ++++ lib/functions/linterCommands.sh | 6 +++ lib/globals/languages.sh | 6 +++ lib/globals/linterCommandsOptions.sh | 2 + lib/globals/linterRules.sh | 2 + scripts/linterVersions.sh | 3 +- ...ummary-test-linters-expect-failure-slim.md | 6 +++ ...ry-test-linters-expect-failure-standard.md | 6 +++ ...ummary-test-linters-expect-success-slim.md | 6 +++ ...ry-test-linters-expect-success-standard.md | 6 +++ .../super-linter/controls/super_linter.rb | 3 ++ .../jupyter_nbqa_black/jupyter_bad_1.ipynb | 32 ++++++++++++++++ .../jupyter_nbqa_black/jupyter_good_1.ipynb | 32 ++++++++++++++++ .../jupyter_nbqa_flake8/jupyter_bad_1.ipynb | 32 ++++++++++++++++ .../jupyter_nbqa_flake8/jupyter_good_1.ipynb | 32 ++++++++++++++++ .../jupyter_nbqa_isort/jupyter_bad_1.ipynb | 38 +++++++++++++++++++ .../jupyter_nbqa_isort/jupyter_good_1.ipynb | 32 ++++++++++++++++ .../jupyter_nbqa_mypy/nbqa_bad_1.ipynb | 32 ++++++++++++++++ .../jupyter_nbqa_mypy/nbqa_good_1.ipynb | 32 ++++++++++++++++ .../jupyter_nbqa_pylint/jupyter_bad_1.ipynb | 32 ++++++++++++++++ .../jupyter_nbqa_pylint/jupyter_good_1.ipynb | 32 ++++++++++++++++ .../jupyter_nbqa_ruff/jupyter_bad_1.ipynb | 33 ++++++++++++++++ .../jupyter_nbqa_ruff/jupyter_good_1.ipynb | 32 ++++++++++++++++ test/testUtils.sh | 3 ++ 29 files changed, 461 insertions(+), 3 deletions(-) create mode 100644 TEMPLATES/.jupyter-nbqa.toml create mode 100644 dependencies/python/nbqa.txt create mode 100644 test/linters/jupyter_nbqa_black/jupyter_bad_1.ipynb create mode 100644 test/linters/jupyter_nbqa_black/jupyter_good_1.ipynb create mode 100644 test/linters/jupyter_nbqa_flake8/jupyter_bad_1.ipynb create mode 100644 test/linters/jupyter_nbqa_flake8/jupyter_good_1.ipynb create mode 100644 test/linters/jupyter_nbqa_isort/jupyter_bad_1.ipynb create mode 100644 test/linters/jupyter_nbqa_isort/jupyter_good_1.ipynb create mode 100644 test/linters/jupyter_nbqa_mypy/nbqa_bad_1.ipynb create mode 100644 test/linters/jupyter_nbqa_mypy/nbqa_good_1.ipynb create mode 100644 test/linters/jupyter_nbqa_pylint/jupyter_bad_1.ipynb create mode 100644 test/linters/jupyter_nbqa_pylint/jupyter_good_1.ipynb create mode 100644 test/linters/jupyter_nbqa_ruff/jupyter_bad_1.ipynb create mode 100644 test/linters/jupyter_nbqa_ruff/jupyter_good_1.ipynb diff --git a/Dockerfile b/Dockerfile index 5d14dd17..0b57945e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -411,6 +411,7 @@ ENV PATH="${PATH}:/venvs/black/bin" ENV PATH="${PATH}:/venvs/checkov/bin" ENV PATH="${PATH}:/venvs/cfn-lint/bin" ENV PATH="${PATH}:/venvs/cpplint/bin" +ENV PATH="${PATH}:/venvs/nbqa/bin" ENV PATH="${PATH}:/venvs/flake8/bin" ENV PATH="${PATH}:/venvs/isort/bin" ENV PATH="${PATH}:/venvs/mypy/bin" diff --git a/README.md b/README.md index 20a4a062..62577a14 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ Super-linter supports the following tools: | **JSON** | [eslint-plugin-jsonc (configured for JSON)](https://www.npmjs.com/package/eslint-plugin-jsonc) (default), [eslint-plugin-json](https://www.npmjs.com/package/eslint-plugin-json) | [Prettier](https://prettier.io/) | | **JSONC**, **JSON5** | [eslint-plugin-jsonc](https://www.npmjs.com/package/eslint-plugin-jsonc) | [Prettier](https://prettier.io/) | | **JSX**, **TSX** | [eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y), [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) | [Prettier](https://prettier.io/) | +| **Jupyter Notebook** | [nbqa](https://nbqa.readthedocs.io/en/latest/index.html) | [nbqa](https://nbqa.readthedocs.io/en/latest/index.html) | | **Kubernetes** | [kubeconform](https://github.com/yannh/kubeconform), [Checkov](https://www.checkov.io/) | See YAML formatters | | **Kotlin** | [ktlint](https://github.com/pinterest/ktlint) | | | **LaTeX** | [ChkTex](https://www.nongnu.org/chktex/) | | @@ -249,6 +250,9 @@ You can configure Super-linter using the following environment variables: | **FIX_JSONC_PRETTIER** | `true` | Flag to enable or disable the formatting of JSONC and JSON5 files with Prettier. | | **FIX_JSX_PRETTIER** | `true` | Flag to enable or disable the formatting of JSX files with Prettier. | | **FIX_JSX** | `false` | Option to enable fix mode for `JSX`. | +| **FIX_JUPYTER_NBQA_BLACK** | `false` | Option to enable fix mode for `NBQA_BLACK`. | +| **FIX_JUPYTER_NBQA_ISORT** | `false` | Option to enable fix mode for `NBQA_ISORT`. | +| **FIX_JUPYTER_NBQA_RUFF** | `false` | Option to enable fix mode for `NBQA_RUFF`. | | **FIX_MARKDOWN_PRETTIER** | `true` | Flag to enable or disable the formatting of Markdown files with Prettier. | | **FIX_MARKDOWN** | `false` | Option to enable fix mode for `MARKDOWN`. | | **FIX_POWERSHELL** | `false` | Option to enable fix mode for `POWERSHELL`. | @@ -285,6 +289,7 @@ You can configure Super-linter using the following environment variables: | **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_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 | +| **JUPYTER_NBQA_CONFIG_FILE** | `.jupyter-nbqa.toml` | Filename for [nbqa configuration](https://nbqa.readthedocs.io/en/latest/configuration.html) | | **KUBERNETES_KUBECONFORM_OPTIONS** | `null` | Additional arguments to pass to the command-line when running **Kubernetes Kubeconform** (Example: --ignore-missing-schemas) | | **LINTER_RULES_PATH** | `.github/linters` | Directory for all linter configuration rules. | | **LOG_FILE** | `super-linter.log` | The filename for outputting logs. Super-linter saves the log file to `${DEFAULT_WORKSPACE}/${LOG_FILE}`. | @@ -373,6 +378,12 @@ You can configure Super-linter using the following environment variables: | **VALIDATE_JSONC_PRETTIER** | `true` | Flag to enable or disable checking the formatting of JSONC and JSON5 files with Prettier. | | **VALIDATE_JSX** | `true` | Flag to enable or disable the linting process for jsx files (Utilizing: ESLint) | | **VALIDATE_JSX_PRETTIER** | `true` | Flag to enable or disable checking the formatting of JSX files with Prettier. | +| **VALIDATE_JUPYTER_NBQA_BLACK** | `true` | Flag to enable or disable the linting process of Jupyter Notebooks. (Utilizing: nbqa black) | +| **VALIDATE_JUPYTER_NBQA_FLAKE8** | `true` | Flag to enable or disable the linting process of Jupyter Notebooks. (Utilizing: nbqa flake8) | +| **VALIDATE_JUPYTER_NBQA_ISORT** | `true` | Flag to enable or disable the linting process of Jupyter Notebooks. (Utilizing: nbqa isort) | +| **VALIDATE_JUPYTER_NBQA_MYPY** | `true` | Flag to enable or disable the linting process of Jupyter Notebooks. (Utilizing: nbqa mypy) | +| **VALIDATE_JUPYTER_NBQA_PYLINT** | `true` | Flag to enable or disable the linting process of Jupyter Notebooks. (Utilizing: nbqa pylint) | +| **VALIDATE_JUPYTER_NBQA_RUFF** | `true` | Flag to enable or disable the linting process of Jupyter Notebooks. (Utilizing: nbqa ruff) | | **VALIDATE_KOTLIN** | `true` | Flag to enable or disable the linting process of the Kotlin language. | | **VALIDATE_KUBERNETES_KUBECONFORM** | `true` | Flag to enable or disable the linting process of Kubernetes descriptors with Kubeconform | | **VALIDATE_LATEX** | `true` | Flag to enable or disable the linting process of the LaTeX language. | diff --git a/TEMPLATES/.jupyter-nbqa.toml b/TEMPLATES/.jupyter-nbqa.toml new file mode 100644 index 00000000..e69de29b diff --git a/dependencies/python/nbqa.txt b/dependencies/python/nbqa.txt new file mode 100644 index 00000000..a3faa232 --- /dev/null +++ b/dependencies/python/nbqa.txt @@ -0,0 +1 @@ +nbqa==1.9.0 diff --git a/docs/add-new-linter.md b/docs/add-new-linter.md index b1491b51..617abfdd 100644 --- a/docs/add-new-linter.md +++ b/docs/add-new-linter.md @@ -20,8 +20,8 @@ tool, do the following. violations that the fix mode can automatically fix. Avoid test cases that fail only because of syntax errors, when possible. 4. Update expected summary reports: `test/data/super-linter-summary`. -5. If the tool supports check-only mode or fix mode, add the `` to - the `LANGUAGES_WITH_FIX_MODE` array in `test/testUtils.sh` +5. If the tool supports check-only mode or fix mode, add the `` to the + `LANGUAGES_WITH_FIX_MODE` array in `test/testUtils.sh` ## Update the test suite diff --git a/lib/functions/buildFileList.sh b/lib/functions/buildFileList.sh index 6b4a9b3f..7821481d 100755 --- a/lib/functions/buildFileList.sh +++ b/lib/functions/buildFileList.sh @@ -457,6 +457,13 @@ BuildFileArrays() { elif [ "${FILE_TYPE}" == "jsx" ]; then echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-JSX" echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-JSX_PRETTIER" + elif [ "${FILE_TYPE}" == "ipynb" ]; then + echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-JUPYTER_NBQA_BLACK" + echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-JUPYTER_NBQA_FLAKE8" + echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-JUPYTER_NBQA_ISORT" + echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-JUPYTER_NBQA_PYLINT" + echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-JUPYTER_NBQA_MYPY" + echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-JUPYTER_NBQA_RUFF" elif [ "${FILE_TYPE}" == "kt" ] || [ "${FILE_TYPE}" == "kts" ]; then echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-KOTLIN" elif [ "$FILE_TYPE" == "lua" ]; then diff --git a/lib/functions/linterCommands.sh b/lib/functions/linterCommands.sh index 4c659c80..e23cee6e 100755 --- a/lib/functions/linterCommands.sh +++ b/lib/functions/linterCommands.sh @@ -104,6 +104,12 @@ LINTER_COMMANDS_ARRAY_JSONC=(eslint -c "${JAVASCRIPT_ES_LINTER_RULES}" --ext '.j LINTER_COMMANDS_ARRAY_JSONC_PRETTIER=("${PRETTIER_COMMAND[@]}") LINTER_COMMANDS_ARRAY_JSX=(eslint -c "${JSX_LINTER_RULES}") LINTER_COMMANDS_ARRAY_JSX_PRETTIER=("${PRETTIER_COMMAND[@]}") +LINTER_COMMANDS_ARRAY_JUPYTER_NBQA_BLACK=(nbqa black) +LINTER_COMMANDS_ARRAY_JUPYTER_NBQA_PYLINT=(nbqa pylint) +LINTER_COMMANDS_ARRAY_JUPYTER_NBQA_FLAKE8=(nbqa flake8) +LINTER_COMMANDS_ARRAY_JUPYTER_NBQA_ISORT=(nbqa isort) +LINTER_COMMANDS_ARRAY_JUPYTER_NBQA_MYPY=(nbqa mypy) +LINTER_COMMANDS_ARRAY_JUPYTER_NBQA_RUFF=(nbqa ruff check) LINTER_COMMANDS_ARRAY_KOTLIN=(ktlint "{/}") LINTER_COMMANDS_ARRAY_KUBERNETES_KUBECONFORM=(kubeconform -strict) if [ "${KUBERNETES_KUBECONFORM_OPTIONS}" != "null" ] && [ -n "${KUBERNETES_KUBECONFORM_OPTIONS}" ]; then diff --git a/lib/globals/languages.sh b/lib/globals/languages.sh index a0d672cb..9831576c 100755 --- a/lib/globals/languages.sh +++ b/lib/globals/languages.sh @@ -28,6 +28,12 @@ LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'BASH_EXEC' 'CHECKOV' 'CLANG_FORMAT' "JSONC_PRETTIER" 'JSX' "JSX_PRETTIER" + "JUPYTER_NBQA_BLACK" + "JUPYTER_NBQA_PYLINT" + "JUPYTER_NBQA_FLAKE8" + "JUPYTER_NBQA_ISORT" + "JUPYTER_NBQA_MYPY" + "JUPYTER_NBQA_RUFF" 'KUBERNETES_KUBECONFORM' 'KOTLIN' 'LATEX' 'LUA' 'MARKDOWN' "MARKDOWN_PRETTIER" 'NATURAL_LANGUAGE' 'OPENAPI' 'PERL' 'PHP_BUILTIN' 'PHP_PHPCS' 'PHP_PHPSTAN' diff --git a/lib/globals/linterCommandsOptions.sh b/lib/globals/linterCommandsOptions.sh index 1301a00b..160f3dac 100755 --- a/lib/globals/linterCommandsOptions.sh +++ b/lib/globals/linterCommandsOptions.sh @@ -24,6 +24,8 @@ JAVASCRIPT_PRETTIER_CHECK_ONLY_MODE_OPTIONS=("${PRETTIER_CHECK_ONLY_MODE_OPTIONS JSON_PRETTIER_CHECK_ONLY_MODE_OPTIONS=("${PRETTIER_CHECK_ONLY_MODE_OPTIONS[@]}") JSONC_PRETTIER_CHECK_ONLY_MODE_OPTIONS=("${PRETTIER_CHECK_ONLY_MODE_OPTIONS[@]}") JSX_PRETTIER_CHECK_ONLY_MODE_OPTIONS=("${PRETTIER_CHECK_ONLY_MODE_OPTIONS[@]}") +JUPYTER_NBQA_BLACK_CHECK_ONLY_MODE_OPTIONS=(--diff --check) +JUPYTER_NBQA_ISORT_CHECK_ONLY_MODE_OPTIONS=(--diff --check) 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) diff --git a/lib/globals/linterRules.sh b/lib/globals/linterRules.sh index 2aee44ae..27cb81c1 100755 --- a/lib/globals/linterRules.sh +++ b/lib/globals/linterRules.sh @@ -54,6 +54,8 @@ MARKDOWN_CUSTOM_RULE_GLOBS="${MARKDOWN_CUSTOM_RULE_GLOBS:-""}" # shellcheck disable=SC2034 # Variable is referenced indirectly MARKDOWN_FILE_NAME="${MARKDOWN_CONFIG_FILE:-.markdown-lint.yml}" # shellcheck disable=SC2034 # Variable is referenced indirectly +JUPYTER_NBQA_FILE_NAME="${JUPYTER_NBQA_CONFIG_FILE:-.jupyter-nbqa.toml}" +# shellcheck disable=SC2034 # Variable is referenced indirectly OPENAPI_FILE_NAME=".openapirc.yml" # shellcheck disable=SC2034 # Variable is referenced indirectly PERL_PERLCRITIC_OPTIONS="${PERL_PERLCRITIC_OPTIONS:-null}" diff --git a/scripts/linterVersions.sh b/scripts/linterVersions.sh index db599f9d..7a6323bc 100755 --- a/scripts/linterVersions.sh +++ b/scripts/linterVersions.sh @@ -47,6 +47,7 @@ LINTER_NAMES_ARRAY['JSONC']="eslint" LINTER_NAMES_ARRAY['JSONC_PRETTIER']="prettier" LINTER_NAMES_ARRAY['JSX']="eslint" LINTER_NAMES_ARRAY['JSX_PRETTIER']="prettier" +LINTER_NAMES_ARRAY['JUPYTER_NBQA']="nbqa" LINTER_NAMES_ARRAY['KOTLIN']="ktlint" LINTER_NAMES_ARRAY['KUBERNETES_KUBECONFORM']="kubeconform" LINTER_NAMES_ARRAY['LATEX']="chktex" @@ -231,7 +232,7 @@ for LANGUAGE in "${!LINTER_NAMES_ARRAY[@]}"; do elif [[ "${LINTER}" == "yamllint" ]]; then GET_VERSION_CMD="$("${LINTER}" --version | awk '{ print $2 }')" # Some linters don't support a "get version" command - elif [[ ${LINTER} == "bash-exec" ]] || [[ ${LINTER} == "gherkin-lint" ]]; then + elif [[ ${LINTER} == "bash-exec" ]] || [[ ${LINTER} == "nbqa" ]] || [[ ${LINTER} == "gherkin-lint" ]]; then GET_VERSION_CMD="Version command not supported" else GET_VERSION_CMD="$("${LINTER}" --version 2>&1)" 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 dc6ce1bf..f8870575 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 @@ -50,6 +50,12 @@ | MARKDOWN | Fail ❌ | | MARKDOWN_PRETTIER | Fail ❌ | | NATURAL_LANGUAGE | Fail ❌ | +| JUPYTER_NBQA_BLACK | Fail ❌ | +| JUPYTER_NBQA_PYLINT | Fail ❌ | +| JUPYTER_NBQA_FLAKE8 | Fail ❌ | +| JUPYTER_NBQA_ISORT | Fail ❌ | +| JUPYTER_NBQA_MYPY | Fail ❌ | +| JUPYTER_NBQA_RUFF | Fail ❌ | | OPENAPI | Fail ❌ | | PERL | Fail ❌ | | PHP_BUILTIN | 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 cad30a61..ca89f069 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 @@ -55,6 +55,12 @@ | MARKDOWN | Fail ❌ | | MARKDOWN_PRETTIER | Fail ❌ | | NATURAL_LANGUAGE | Fail ❌ | +| JUPYTER_NBQA_BLACK | Fail ❌ | +| JUPYTER_NBQA_PYLINT | Fail ❌ | +| JUPYTER_NBQA_FLAKE8 | Fail ❌ | +| JUPYTER_NBQA_ISORT | Fail ❌ | +| JUPYTER_NBQA_MYPY | Fail ❌ | +| JUPYTER_NBQA_RUFF | Fail ❌ | | OPENAPI | Fail ❌ | | PERL | Fail ❌ | | PHP_BUILTIN | 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 f72663bd..3230032f 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 @@ -50,6 +50,12 @@ | MARKDOWN | Pass ✅ | | MARKDOWN_PRETTIER | Pass ✅ | | NATURAL_LANGUAGE | Pass ✅ | +| JUPYTER_NBQA_BLACK | Pass ✅ | +| JUPYTER_NBQA_PYLINT | Pass ✅ | +| JUPYTER_NBQA_FLAKE8 | Pass ✅ | +| JUPYTER_NBQA_ISORT | Pass ✅ | +| JUPYTER_NBQA_MYPY | Pass ✅ | +| JUPYTER_NBQA_RUFF | Pass ✅ | | OPENAPI | Pass ✅ | | PERL | Pass ✅ | | PHP_BUILTIN | 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 9dbb00b0..174f644e 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 @@ -55,6 +55,12 @@ | MARKDOWN | Pass ✅ | | MARKDOWN_PRETTIER | Pass ✅ | | NATURAL_LANGUAGE | Pass ✅ | +| JUPYTER_NBQA_BLACK | Pass ✅ | +| JUPYTER_NBQA_PYLINT | Pass ✅ | +| JUPYTER_NBQA_FLAKE8 | Pass ✅ | +| JUPYTER_NBQA_ISORT | Pass ✅ | +| JUPYTER_NBQA_MYPY | Pass ✅ | +| JUPYTER_NBQA_RUFF | Pass ✅ | | OPENAPI | Pass ✅ | | PERL | Pass ✅ | | PHP_BUILTIN | Pass ✅ | diff --git a/test/inspec/super-linter/controls/super_linter.rb b/test/inspec/super-linter/controls/super_linter.rb index d72acd27..0c3101f2 100644 --- a/test/inspec/super-linter/controls/super_linter.rb +++ b/test/inspec/super-linter/controls/super_linter.rb @@ -181,6 +181,7 @@ control "super-linter-installed-commands" do { linter_name: "lua", version_option: "-v"}, { linter_name: "markdownlint"}, { linter_name: "mypy"}, + { linter_name: "nbqa"}, { linter_name: "npm-groovy-lint"}, { linter_name: "perl"}, { linter_name: "php"}, @@ -411,6 +412,7 @@ control "super-linter-installed-pypi-packages" do "flake8", "isort", "mypy", + "nbqa", "pyink", "pylint", "ruff", @@ -512,6 +514,7 @@ control "super-linter-validate-files" do "/action/lib/.automation/.luacheckrc", "/action/lib/.automation/.markdown-lint.yml", "/action/lib/.automation/.mypy.ini", + "/action/lib/.automation/.jupyter-nbqa.toml", "/action/lib/.automation/.openapirc.yml", "/action/lib/.automation/.perlcriticrc", "/action/lib/.automation/.powershell-psscriptanalyzer.psd1", diff --git a/test/linters/jupyter_nbqa_black/jupyter_bad_1.ipynb b/test/linters/jupyter_nbqa_black/jupyter_bad_1.ipynb new file mode 100644 index 00000000..8260e312 --- /dev/null +++ b/test/linters/jupyter_nbqa_black/jupyter_bad_1.ipynb @@ -0,0 +1,32 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "hHETjoFLGZmM" + }, + "outputs": [], + "source": [ + "a=1;b=2\n", + "c=a+b\n", + "BROKEN_VAR=BROKEN_VAR\n", + "print(c)" + ] + } + ] +} diff --git a/test/linters/jupyter_nbqa_black/jupyter_good_1.ipynb b/test/linters/jupyter_nbqa_black/jupyter_good_1.ipynb new file mode 100644 index 00000000..b75828cd --- /dev/null +++ b/test/linters/jupyter_nbqa_black/jupyter_good_1.ipynb @@ -0,0 +1,32 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "hHETjoFLGZmM" + }, + "outputs": [], + "source": [ + "a = 1\n", + "b = 2\n", + "c = a + b\n", + "print(c)" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/test/linters/jupyter_nbqa_flake8/jupyter_bad_1.ipynb b/test/linters/jupyter_nbqa_flake8/jupyter_bad_1.ipynb new file mode 100644 index 00000000..23ae443d --- /dev/null +++ b/test/linters/jupyter_nbqa_flake8/jupyter_bad_1.ipynb @@ -0,0 +1,32 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "hHETjoFLGZmM" + }, + "outputs": [], + "source": [ + "a=1;b=2\n", + "c=a+b\n", + "BROKEN_VAR=BROKEN_VAR\n", + "print(c)" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/test/linters/jupyter_nbqa_flake8/jupyter_good_1.ipynb b/test/linters/jupyter_nbqa_flake8/jupyter_good_1.ipynb new file mode 100644 index 00000000..b75828cd --- /dev/null +++ b/test/linters/jupyter_nbqa_flake8/jupyter_good_1.ipynb @@ -0,0 +1,32 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "hHETjoFLGZmM" + }, + "outputs": [], + "source": [ + "a = 1\n", + "b = 2\n", + "c = a + b\n", + "print(c)" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/test/linters/jupyter_nbqa_isort/jupyter_bad_1.ipynb b/test/linters/jupyter_nbqa_isort/jupyter_bad_1.ipynb new file mode 100644 index 00000000..789a7236 --- /dev/null +++ b/test/linters/jupyter_nbqa_isort/jupyter_bad_1.ipynb @@ -0,0 +1,38 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "hHETjoFLGZmM" + }, + "outputs": [], + "source": [ + "import json\n", + "from os import getenv, path\n", + "from pprint import pprint\n", + "import sys\n", + "\n", + "\n", + "a=1;b=2\n", + "c=a+b\n", + "BROKEN_VAR=BROKEN_VAR\n", + "print(c)" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/test/linters/jupyter_nbqa_isort/jupyter_good_1.ipynb b/test/linters/jupyter_nbqa_isort/jupyter_good_1.ipynb new file mode 100644 index 00000000..b75828cd --- /dev/null +++ b/test/linters/jupyter_nbqa_isort/jupyter_good_1.ipynb @@ -0,0 +1,32 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "hHETjoFLGZmM" + }, + "outputs": [], + "source": [ + "a = 1\n", + "b = 2\n", + "c = a + b\n", + "print(c)" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/test/linters/jupyter_nbqa_mypy/nbqa_bad_1.ipynb b/test/linters/jupyter_nbqa_mypy/nbqa_bad_1.ipynb new file mode 100644 index 00000000..23ae443d --- /dev/null +++ b/test/linters/jupyter_nbqa_mypy/nbqa_bad_1.ipynb @@ -0,0 +1,32 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "hHETjoFLGZmM" + }, + "outputs": [], + "source": [ + "a=1;b=2\n", + "c=a+b\n", + "BROKEN_VAR=BROKEN_VAR\n", + "print(c)" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/test/linters/jupyter_nbqa_mypy/nbqa_good_1.ipynb b/test/linters/jupyter_nbqa_mypy/nbqa_good_1.ipynb new file mode 100644 index 00000000..b75828cd --- /dev/null +++ b/test/linters/jupyter_nbqa_mypy/nbqa_good_1.ipynb @@ -0,0 +1,32 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "hHETjoFLGZmM" + }, + "outputs": [], + "source": [ + "a = 1\n", + "b = 2\n", + "c = a + b\n", + "print(c)" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/test/linters/jupyter_nbqa_pylint/jupyter_bad_1.ipynb b/test/linters/jupyter_nbqa_pylint/jupyter_bad_1.ipynb new file mode 100644 index 00000000..23ae443d --- /dev/null +++ b/test/linters/jupyter_nbqa_pylint/jupyter_bad_1.ipynb @@ -0,0 +1,32 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "hHETjoFLGZmM" + }, + "outputs": [], + "source": [ + "a=1;b=2\n", + "c=a+b\n", + "BROKEN_VAR=BROKEN_VAR\n", + "print(c)" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/test/linters/jupyter_nbqa_pylint/jupyter_good_1.ipynb b/test/linters/jupyter_nbqa_pylint/jupyter_good_1.ipynb new file mode 100644 index 00000000..eafe24f4 --- /dev/null +++ b/test/linters/jupyter_nbqa_pylint/jupyter_good_1.ipynb @@ -0,0 +1,32 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "hHETjoFLGZmM" + }, + "outputs": [], + "source": [ + "A = 1\n", + "B = 2\n", + "C = A + B\n", + "print(C)" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/test/linters/jupyter_nbqa_ruff/jupyter_bad_1.ipynb b/test/linters/jupyter_nbqa_ruff/jupyter_bad_1.ipynb new file mode 100644 index 00000000..36f0c63d --- /dev/null +++ b/test/linters/jupyter_nbqa_ruff/jupyter_bad_1.ipynb @@ -0,0 +1,33 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "hHETjoFLGZmM" + }, + "outputs": [], + "source": [ + "import pandas\n", + "import numpy as np\n", + "\n", + "c = 1 + 2\n", + "print(c)" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/test/linters/jupyter_nbqa_ruff/jupyter_good_1.ipynb b/test/linters/jupyter_nbqa_ruff/jupyter_good_1.ipynb new file mode 100644 index 00000000..b75828cd --- /dev/null +++ b/test/linters/jupyter_nbqa_ruff/jupyter_good_1.ipynb @@ -0,0 +1,32 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "hHETjoFLGZmM" + }, + "outputs": [], + "source": [ + "a = 1\n", + "b = 2\n", + "c = a + b\n", + "print(c)" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/test/testUtils.sh b/test/testUtils.sh index a5faa6e0..372bee7f 100755 --- a/test/testUtils.sh +++ b/test/testUtils.sh @@ -53,6 +53,9 @@ LANGUAGES_WITH_FIX_MODE=( "JSONC_PRETTIER" "JSX" "JSX_PRETTIER" + "JUPYTER_NBQA_BLACK" + "JUPYTER_NBQA_ISORT" + "JUPYTER_NBQA_RUFF" "MARKDOWN" "MARKDOWN_PRETTIER" "NATURAL_LANGUAGE"