From 5d534e26551293d0af39cc5eacd8e305e6098f78 Mon Sep 17 00:00:00 2001 From: Markus Petke Date: Mon, 22 Jan 2024 11:42:52 +0100 Subject: [PATCH] use ruff as linter (#220) * use ruff as linter * fix review findings --- .devcontainer/devcontainer.json | 21 ++++++--------- .pre-commit-config.yaml | 48 +++++---------------------------- .velocitas.json | 4 +-- NOTICE.md | 11 +++++--- app/tests/unit/test_run.py | 3 ++- setup.cfg | 16 ----------- 6 files changed, 26 insertions(+), 77 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ff3407b5..1616a29b 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -25,13 +25,6 @@ "mypy.targets": [ "app" ], - // Security Linter - "python.linting.banditEnabled": true, - "python.linting.banditArgs": [ - "-c setup.cfg" - ], - // Style Checker for Python Docs - "python.linting.pydocstyleEnabled": true, "python.analysis.extraPaths": [ "./proto", "./src/vehicle_model" @@ -39,8 +32,12 @@ "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, "[python]": { - // Style Formatter - "editor.defaultFormatter": "ms-python.black-formatter" + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.fixAll": true, + "source.organizeImports": true + }, + "editor.defaultFormatter": "charliermarsh.ruff" }, "vs-kubernetes": { "vscode-kubernetes.kubectl-path.linux": "/usr/local/bin/kubectl", @@ -85,10 +82,8 @@ "ms-kubernetes-tools.vscode-kubernetes-tools", "matangover.mypy", "augustocdias.tasks-shell-input", - "ms-python.isort", - "ms-python.flake8", - "ms-python.black-formatter", - "ms-python.mypy-type-checker" + "ms-python.mypy-type-checker", + "charliermarsh.ruff" ] } }, diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c26e01c3..a9ad9d2d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -31,55 +31,21 @@ repos: )$ - id: check-merge-conflict - - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.13 hooks: - - id: isort - - - repo: https://github.com/psf/black - rev: 23.7.0 - hooks: - - id: black - - - repo: https://github.com/PyCQA/flake8 - rev: 6.1.0 - hooks: - - id: flake8 - exclude: > - (?x)^( - .*_pb2.py| - .*_pb2.pyi| - .*_pb2_grpc.py - )$ - additional_dependencies: - - flake8-bugbear - - flake8-unused-arguments - - - repo: https://github.com/PyCQA/bandit - rev: 1.7.5 - hooks: - - id: bandit - args: ["--skip=B101"] - types_or: [python] + - id: ruff + args: [--fix] + - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy - rev: "v1.5.1" + rev: "v1.8.0" hooks: - id: mypy args: [app] language: system pass_filenames: false - - repo: https://github.com/pycqa/pydocstyle - rev: 6.3.0 - hooks: - - id: pydocstyle - - - repo: https://github.com/gruntwork-io/pre-commit - rev: v0.1.22 - hooks: - - id: helmlint - - repo: https://github.com/Lucas-C/pre-commit-hooks rev: v1.5.4 hooks: diff --git a/.velocitas.json b/.velocitas.json index 7860e4c9..27e21b5f 100644 --- a/.velocitas.json +++ b/.velocitas.json @@ -2,7 +2,7 @@ "packages": [ { "name": "devenv-runtimes", - "version": "v2.2.3" + "version": "v2.2.4" }, { "name": "devenv-github-workflows", @@ -14,7 +14,7 @@ }, { "name": "devenv-devcontainer-setup", - "version": "v1.4.5" + "version": "v1.4.6" } ], "variables": { diff --git a/NOTICE.md b/NOTICE.md index 80a7bcbe..433c1d71 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -21,12 +21,15 @@ SPDX-License-Identifier: Apache-2.0 | Kubectl | https://github.com/kubernetes/kubectl/blob/master/LICENSE | | K9S | https://github.com/derailed/k9s/blob/master/LICENSE | | Redis | https://redis.com/legal/licenses/ | -| Mosquitto | https://github.com/eclipse/mosquitto/blob/master/LICENSE.txt | +| Mosquitto | https://github.com/eclipse/mosquitto/blob/master/LICENSE.txt | ### Development -| Software | License | -| :------: | :------------------------------------------------------------------: | -| GRPC | https://github.com/grpc/grpc/blob/master/LICENSE | +| Software | License | +| :------: | :------------------------------------------------------------------: | +| GRPC | https://github.com/grpc/grpc/blob/master/LICENSE | +| Pre-Commit | https://github.com/pre-commit/pre-commit/blob/main/LICENSE | +| Mypy | https://github.com/python/mypy/blob/master/LICENSE | +| Ruff | https://raw.githubusercontent.com/astral-sh/ruff/main/LICENSE | ### Further 3rd party licenses used in project * [Auto-generated 3rd party licenses](./NOTICE-3RD-PARTY-CONTENT.md) diff --git a/app/tests/unit/test_run.py b/app/tests/unit/test_run.py index a1bb0a86..94d801bd 100644 --- a/app/tests/unit/test_run.py +++ b/app/tests/unit/test_run.py @@ -48,7 +48,8 @@ async def test_for_publish_to_topic(): VehicleApp, "publish_mqtt_event", new_callable=mock.AsyncMock, return_value=-1 ): response = await VehicleApp.publish_mqtt_event( - str("sampleTopic"), get_sample_response_data() # type: ignore + str("sampleTopic"), # type: ignore + get_sample_response_data(), ) print(f"Received response: {response}") diff --git a/setup.cfg b/setup.cfg index f45dcac2..ff01a954 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,10 +1,3 @@ -[flake8] -max-line-length = 88 -max-complexity = 18 -extend-ignore = E203,W503 -# More information about aligning flake8 and black configs can be found at https://github.com/psf/black/blob/06ccb88bf2bd35a4dc5d591bb296b5b299d07323/docs/guides/using_black_with_other_tools.md#configuration -select = B,C,E,W,F,T4,B9,B950 - [mypy] python_version = 3.10 warn_unused_configs = True @@ -20,12 +13,3 @@ files = [mypy-vehicle_model.proto.*] ignore_errors = True - -[pydocstyle] -match = '(?!test_).*\.py' - -[isort] -profile = black - -[tool.bandit] -skips = ["B101"]