|
| 1 | +# SPDX-License-Identifier: MIT |
| 2 | +# Copyright 2024 Beslogic Inc. |
| 3 | + |
| 4 | +# The source skeleton for this configuration can be found at |
| 5 | +# https://github.com/BesLogic/shared-configs/blob/main/ruff.toml |
| 6 | +# Modifications to this file that are not project-specific should also be done upstream. |
| 7 | +# These configs are incompatible with ruff<0.5.7 |
| 8 | + |
| 9 | +# https://docs.astral.sh/ruff/configuration/ |
| 10 | +target-version = "py310" # Change this to the oldest supported version by your application |
| 11 | +line-length = 100 |
| 12 | +preview = true |
| 13 | + |
| 14 | +[lint] |
| 15 | +select = ["ALL"] |
| 16 | +# https://docs.astral.sh/ruff/rules/ |
| 17 | +ignore = [ |
| 18 | + ### |
| 19 | + # Not needed or wanted |
| 20 | + ### |
| 21 | + "D1", # pydocstyle Missing doctring |
| 22 | + "D401", # pydocstyle: non-imperative-mood |
| 23 | + "EM", # flake8-errmsg |
| 24 | + "EXE", # flake8-executable |
| 25 | + # This is often something we can't control: https://github.com/astral-sh/ruff/issues/9497 |
| 26 | + # Also false-positive with positional-only arguments: https://github.com/astral-sh/ruff/issues/3247 |
| 27 | + "FBT003", # flake8-boolean-trap: boolean-positional-value-in-call |
| 28 | + "INP", # flake8-no-pep420 |
| 29 | + "ISC003", # flake8-implicit-str-concat: explicit-string-concatenation |
| 30 | + # Short messages are still considered "long" messages |
| 31 | + "TRY003", # tryceratops : raise-vanilla-args |
| 32 | + # Don't remove commented code, also too inconsistant |
| 33 | + "ERA001", # eradicate: commented-out-code |
| 34 | + # contextlib.suppress is roughly 3x slower than try/except |
| 35 | + "SIM105", # flake8-simplify: use-contextlib-suppress |
| 36 | + # Negative performance impact and more verbose https://github.com/astral-sh/ruff/issues/7871 |
| 37 | + "UP038", # non-pep604-isinstance |
| 38 | + # deprecated and is actually slower for cases relevant to unpacking: https://github.com/astral-sh/ruff/issues/12754 |
| 39 | + "UP027", # unpacked-list-comprehension |
| 40 | + # Checked by type-checker (pyright/mypy) |
| 41 | + "ANN", # flake-annotations |
| 42 | + "PGH003", # blanket-type-ignore |
| 43 | + "TCH", # flake8-type-checking |
| 44 | + # Already shown by Pylance, checked by pyright, and can be caused by overloads. |
| 45 | + "ARG002", # Unused method argument |
| 46 | + # We want D213: multi-line-summary-second-line and D211: no-blank-line-before-class |
| 47 | + "D203", # pydocstyle: one-blank-line-before-class |
| 48 | + "D212", # pydocstyle: multi-line-summary-first-line |
| 49 | + # Allow differentiating between broken (FIXME) and to be done/added/completed (TODO) |
| 50 | + "TD001", # flake8-todos: invalid-todo-tag |
| 51 | + |
| 52 | + ### |
| 53 | + # These should be warnings (https://github.com/astral-sh/ruff/issues/1256 & https://github.com/astral-sh/ruff/issues/1774) |
| 54 | + ### |
| 55 | + "FIX", # flake8-fixme |
| 56 | + # Not all TODOs are worth an issue, this would be better as a warning |
| 57 | + "TD003", # flake8-todos: missing-todo-link |
| 58 | + |
| 59 | + # False-positives |
| 60 | + "TCH004", # https://github.com/astral-sh/ruff/issues/3821 |
| 61 | + |
| 62 | + ### |
| 63 | + # Conflict with formatter (you can remove this section if you don't use Ruff as a formatter) |
| 64 | + ### |
| 65 | + # "COM812", # missing-trailing-comma |
| 66 | + # "ISC001", # single-line-implicit-string-concatenation |
| 67 | + |
| 68 | + ### |
| 69 | + # Rules about missing special documentation. Up to you if you wanna enable these, you must also disable D406, D407 |
| 70 | + ### |
| 71 | + "DOC201", # docstring-missing-returns |
| 72 | + "DOC402", # docstring-missing-yields |
| 73 | + "DOC501", # docstring-missing-exception |
| 74 | + # "D406", # new-line-after-section-name, conflicts with DOC |
| 75 | + # "D407", # dashed-underline-after-section, conflicts with DOC |
| 76 | + |
| 77 | + ### |
| 78 | + # Specific to this project |
| 79 | + ### |
| 80 | + "D205", # Not all docstrings have a short description + desrciption |
| 81 | + # TODO: Consider for more complete doc |
| 82 | + "DOC201", # docstring-extraneous-returns |
| 83 | + "DOC501", # docstring-missing-exception |
| 84 | + # We have some Pascal case module names |
| 85 | + "N999", # pep8-naming: Invalid module name |
| 86 | + # Print are used as debug logs |
| 87 | + "T20", # flake8-print |
| 88 | + # This is a relatively small, low contributors project. Git blame suffice. |
| 89 | + "TD002", # missing-todo-author |
| 90 | + # Python 3.11, introduced "zero cost" exception handling |
| 91 | + "PERF203", # try-except-in-loop |
| 92 | + |
| 93 | + ### |
| 94 | + # FIXME/TODO: I'd normally set them as temporarily warnings, but no warnings in Ruff yet: |
| 95 | + # https://github.com/astral-sh/ruff/issues/1256 & https://github.com/astral-sh/ruff/issues/1774): |
| 96 | + ### |
| 97 | + "CPY001", # flake8-copyright |
| 98 | + "PTH", # flake8-use-pathlib |
| 99 | + # Ignore until linux support |
| 100 | + "EXE", # flake8-executable |
| 101 | +] |
| 102 | + |
| 103 | +# https://docs.astral.sh/ruff/settings/#flake8-implicit-str-concat |
| 104 | +[lint.flake8-implicit-str-concat] |
| 105 | +allow-multiline = false |
| 106 | + |
| 107 | +# https://docs.astral.sh/ruff/settings/#isort |
| 108 | +[lint.isort] |
| 109 | +combine-as-imports = true |
| 110 | +split-on-trailing-comma = false |
| 111 | +# This should be automatically detected in src layout, but somehow pre-commit messes it up |
| 112 | +known-first-party = ["gen"] |
| 113 | + |
| 114 | +# https://docs.astral.sh/ruff/settings/#mccabe |
| 115 | +[lint.mccabe] |
| 116 | +# Arbitrary to 2 bytes, same as SonarLint |
| 117 | +max-complexity = 15 |
| 118 | + |
| 119 | +[lint.pylint] |
| 120 | +# Arbitrary to 1 byte, same as SonarLint |
| 121 | +max-args = 7 |
| 122 | +# At least same as max-complexity |
| 123 | +max-branches = 15 |
| 124 | + |
| 125 | +[lint.per-file-ignores] |
| 126 | +"**/typings/**/*.pyi" = [ |
| 127 | + "F811", # Re-exports false positives |
| 128 | + # The following can't be controlled for external libraries: |
| 129 | + "A", # Shadowing builtin names |
| 130 | + "E741", # ambiguous variable name |
| 131 | + "F403", # `from . import *` used; unable to detect undefined names |
| 132 | + "FBT", # flake8-boolean-trap |
| 133 | + "ICN001", # unconventional-import-alias |
| 134 | + "N8", # Naming conventions |
| 135 | + "PLC2701", # Private name import |
| 136 | + "PLR0904", # Too many public methods |
| 137 | + "PLR0913", # Argument count |
| 138 | + "PLR0917", # Too many positional arguments |
| 139 | + "PLW3201", # misspelled dunder method name |
| 140 | + "PYI042", # CamelCase TypeAlias |
| 141 | + # Stubs can sometimes re-export entire modules. |
| 142 | + # Issues with using a star-imported name will be caught by type-checkers. |
| 143 | + "F405", # may be undefined, or defined from star imports |
| 144 | +] |
| 145 | + |
| 146 | +[lint.flake8-tidy-imports.banned-api] |
| 147 | +"cv2.imread".msg = """\ |
| 148 | +it doesn't support special characters. \ |
| 149 | +Use `cv2.imdecode(np.fromfile(filename, dtype=np.uint8), flags)` instead. |
| 150 | +https://github.com/opencv/opencv/issues/4292#issuecomment-2266019697""" |
| 151 | +"cv2.imwrite".msg = """\ |
| 152 | +it doesn't support special characters. \ |
| 153 | +Use `cv2.imencode(os.path.splitext(filename)[1], img)[1].tofile(filename)` instead. |
| 154 | +https://github.com/opencv/opencv/issues/4292#issuecomment-2266019697""" |
0 commit comments