From 5acf23d469638ba46a9aacb7c5159f3d80442f0e Mon Sep 17 00:00:00 2001 From: Michael Franklin Date: Tue, 17 Oct 2023 13:08:38 +1100 Subject: [PATCH] Replace flake8 + pylint with ruff --- .flake8 | 19 ----------- .pre-commit-config.yaml | 75 ++++++++++++++++++----------------------- .pylintrc | 43 ----------------------- pyproject.toml | 28 +++++++++++++++ 4 files changed, 61 insertions(+), 104 deletions(-) delete mode 100644 .flake8 delete mode 100644 .pylintrc diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 252dac4..0000000 --- a/.flake8 +++ /dev/null @@ -1,19 +0,0 @@ -[flake8] -# We disable the following inspections: -# 1. F541: "f-string is missing placeholders" (we allow f-strings that don't do -# any formatting for consistent looks and for future safety) -# 2. Inspections incompatible with Black (see https://github.com/psf/black/blob/master/docs/compatible_configs.md#why-those-options-above-1): -# E203: whitespace before ':' -# 3. Q003 "Change outer quotes to avoid escaping inner quotes" -# 4. E501 "line too long" (covered by black) -# 5. W291 "trailing-whitespace" (covered by black) -# 6. W293 "blank line contains whitespace" (covered by black) -extend-ignore: F541,E203,Q003,E501,W291,W293 - -# Maximum number of characters on a single line. Default for black, see: -# https://black.readthedocs.io/en/stable/the_black_code_style.html#line-length -max-line-length: 88 - -inline-quotes = single -multiline-quotes = """ -docstring-quotes = """ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0061197..e315785 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,48 +1,39 @@ default_language_version: - python: python3.10 + python: python3.10 repos: -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.2.0 - hooks: - - id: check-yaml - exclude: '\.*conda/.*' - - id: end-of-file-fixer - - id: trailing-whitespace - exclude: '\.txt$|\.tsv$' - - id: check-case-conflict - - id: check-merge-conflict - - id: detect-private-key - - id: debug-statements - - id: check-added-large-files + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.2.0 + hooks: + - id: check-yaml + exclude: '\.*conda/.*' + - id: end-of-file-fixer + - id: trailing-whitespace + exclude: '\.txt$|\.tsv$' + - id: check-case-conflict + - id: check-merge-conflict + - id: detect-private-key + - id: debug-statements + - id: check-added-large-files -- repo: https://github.com/igorshubovych/markdownlint-cli - rev: v0.31.1 - hooks: - - id: markdownlint - args: ['--config', '.markdownlint.json'] + - repo: https://github.com/igorshubovych/markdownlint-cli + rev: v0.31.1 + hooks: + - id: markdownlint + args: ["--config", ".markdownlint.json"] -- repo: https://github.com/ambv/black - rev: '22.3.0' - hooks: - - id: black + - repo: https://github.com/ambv/black + rev: "22.3.0" + hooks: + - id: black -- repo: https://github.com/PyCQA/flake8 - rev: '5.0.4' - hooks: - - id: flake8 - additional_dependencies: [flake8-bugbear, flake8-quotes] + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.1.0 + hooks: + - id: ruff -# Using system installation of pylint to support checking python module imports -- repo: local - hooks: - - id: pylint - name: pylint - entry: pylint - language: system - types: [python] - -- repo: https://github.com/pre-commit/mirrors-mypy - rev: 'v0.960' - hooks: - - id: mypy - additional_dependencies: [ types-PyYAML==6.0.4, types-toml ] + - repo: https://github.com/pre-commit/mirrors-mypy + rev: "v0.960" + hooks: + - id: mypy + additional_dependencies: [types-PyYAML==6.0.4, types-toml] diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index 0e021ef..0000000 --- a/.pylintrc +++ /dev/null @@ -1,43 +0,0 @@ -[MESSAGES CONTROL] -# We disable the following inspections: -# 1. f-string-without-interpolation (we allow f-strings that don't do any -# formatting for consistent looks and for future safety) -# 2. inherit-non-class ("Inheriting 'NamedTuple', which is not a class" false -# positive, see: https://github.com/PyCQA/pylint/issues/3876) -# 3. too-few-public-methods (produces false positives) -# 4. inspections incompatible with Black (see -# https://github.com/psf/black/blob/master/docs/compatible_configs.md#why-those-options-above-2): -# 5. fixme (left 'TODO' lines) -# 6. logging-fstring-interpolation (forbids f-strings in logging functions) -# 7. trailing-whitespace -# 8. use-dict-literal -# 9. too-many-instance-attributes -# 10. line-too-long -# 11. no-else-return -# 12. redefined-builtin -# 13. arguments-renamed -# -# The following require installing the python modules imported in the source code. -# Add these if you don't want to include all dependencies into the dev environment: -# import-error ("Unable to import") -# no-member -# c-extension-no-member -# -disable=f-string-without-interpolation,inherit-non-class,too-few-public-methods,fixme,logging-fstring-interpolation,trailing-whitespace,use-dict-literal,too-many-instance-attributes,line-too-long,no-else-return,redefined-builtin,arguments-renamed - -# Overriding variable name patterns to allow short 1- or 2-letter variables -attr-rgx=[a-z_][a-z0-9_]{0,30}$ -argument-rgx=[a-z_][a-z0-9_]{0,30}$ -variable-rgx=[a-z_][a-z0-9_]{0,30}$ - -# Maximum number of characters on a single line. Default for black, see: -# https://black.readthedocs.io/en/stable/the_black_code_style.html#line-length -max-line-length=88 - -[DESIGN] -# Maximum number of locals for function / method body -max-locals=25 -# Maximum number of arguments for function / method -max-args=10 -# Maximum number of statements in function / method body -max-statements=100 diff --git a/pyproject.toml b/pyproject.toml index 9acad64..ecf1ada 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,31 @@ [tool.black] line-length = 88 skip-string-normalization = true + +[tool.isort] +py_version = 311 + +[tool.ruff] +line-length = 88 + +# ignore pydocstyle, flake8-boolean-trap (FBT) +select = ["A", "B", "C", "E", "F", "G", "I", "N", "Q", "S", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "ERA", "EXE", "ICN", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "UP", "YTT"] + +fixable = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "ERA", "EXE", "FBT", "ICN", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "UP", "YTT"] + +ignore = [ + "ANN101", # Missing type annotation for self in method + "ANN201", # Missing return type annotation for public function + "E501", # Line length too long + "E731", # Do not assign a lambda expression, use a def + "E741", # Ambiguous variable name + "G004", # Logging statement uses f-string + "PLR0911", # Too many return statements + "PLR0912", # Too many branches + "PLR0913", # Too many arguments to function call + "PLR0915", # Too many statements + "PLW0603", # Using the global statement to update `` is discouraged + "PT018", # Assertion should be broken down into multiple parts + "Q000", # Single quotes found but double quotes preferred + "S101", # Use of assert detected +]