Skip to content

Commit

Permalink
pre-commit: Add more ruff rules
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Feb 9, 2024
1 parent b85d900 commit 68bdd10
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 11 deletions.
7 changes: 0 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,8 @@ repos:
rev: v0.2.1
hooks:
- id: ruff
args: [ --select=I, --fix] # isort
- id: ruff-format

- repo: https://github.com/asottile/pyupgrade
rev: 'v3.15.0'
hooks:
- id: pyupgrade
args: [ --py38-plus ]

- repo: https://github.com/ikamensh/flynt/
rev: '1.0.1'
hooks:
Expand Down
89 changes: 89 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
[tool.ruff]
target-version = "py38"

[tool.ruff.lint]
select = [
"AIR", # Airflow
"ASYNC", # flake8-async
"BLE", # flake8-blind-except
"C90", # McCabe cyclomatic complexity
"DJ", # flake8-django
"EXE", # flake8-executable
"F", # Pyflakes
"FA", # flake8-future-annotations
"G", # flake8-logging-format
"I", # isort
"ICN", # flake8-import-conventions
"INT", # flake8-gettext
"LOG", # flake8-logging
"NPY", # NumPy-specific rules
"PLC", # Pylint conventions
"PLE", # Pylint errors
"PLR091", # Pylint Refactor just for max-args, max-branches, etc.
"PYI", # flake8-pyi
"Q", # flake8-quotes
"SLOT", # flake8-slots
"TCH", # flake8-type-checking
"TID", # flake8-tidy-imports
"TRIO", # flake8-trio
"UP", # pyupgrade
"W", # pycodestyle
"YTT", # flake8-2020
# "A", # flake8-builtins
# "ANN", # flake8-annotations
# "ARG", # flake8-unused-arguments
# "B", # flake8-bugbear
# "C4", # flake8-comprehensions
# "COM", # flake8-commas
# "CPY", # flake8-copyright
# "D", # pydocstyle
# "DTZ", # flake8-datetimez
# "E", # pycodestyle
# "EM", # flake8-errmsg
# "ERA", # eradicate
# "FBT", # flake8-boolean-trap
# "FIX", # flake8-fixme
# "FLY", # flynt
# "FURB", # refurb
# "INP", # flake8-no-pep420
# "ISC", # flake8-implicit-str-concat
# "N", # pep8-naming
# "PD", # pandas-vet
# "PERF", # Perflint
# "PGH", # pygrep-hooks
# "PIE", # flake8-pie
# "PL", # Pylint
# "PT", # flake8-pytest-style
# "PTH", # flake8-use-pathlib
# "RET", # flake8-return
# "RSE", # flake8-raise
# "RUF", # Ruff-specific rules
# "S", # flake8-bandit
# "SIM", # flake8-simplify
# "SLF", # flake8-self
# "T10", # flake8-debugger
# "T20", # flake8-print
# "TD", # flake8-todos
# "TRY", # tryceratops
]
ignore = [
"EXE001",
"F401",
"F811",
"F841",
"UP031",
]

[tool.ruff.lint.mccabe]
max-complexity = 45 # Default is 10

[tool.ruff.lint.per-file-ignores]
"src/whoosh/compat.py" = ["F821"]
"src/whoosh/filedb/filestore.py" = ["UP024"]
"src/whoosh/util/__init__.py" = ["F821"]

[tool.ruff.lint.pylint]
max-args = 22 # Default is 5
max-branches = 79 # Default is 12
max-returns = 16 # Default is 6
max-statements = 256 # Default is 50
8 changes: 7 additions & 1 deletion src/whoosh/lang/dmetaphone.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
silent_starts = re.compile("GN|KN|PN|WR|PS")


def double_metaphone(text):
def double_metaphone(text): # noqa: C901, PLR0912, PLR0915
"""
This function is too complex (125) -- ruff rule C901
This function has too many branches (181) -- ruff rule PLR0912
This function has too many statements (318) -- ruff rule PLR0915
Future edits to this function should reduce, not increase its complexity.
"""
text = text.upper()
slavo_germanic = bool(slavo_germ_exp.search(text))

Expand Down
6 changes: 5 additions & 1 deletion src/whoosh/lang/snowball/english.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class EnglishStemmer(_StandardStemmer):
"succeeding": "succeed",
}

def stem(self, word):
def stem(self, word): # noqa: C901, PLR0912
"""
Stem an English word and return the stemmed form.
Expand All @@ -151,6 +151,10 @@ def stem(self, word):
:return: The stemmed form.
:rtype: unicode
This method is too complex (91) -- ruff rule C901
This method has too many branches (117) -- ruff rule PLR0912
This method has too many statements (254) -- ruff rule PLR0915
Future edits to this method should reduce, not increase its complexity.
"""
word = word.lower()

Expand Down
6 changes: 5 additions & 1 deletion src/whoosh/lang/snowball/finnish.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class FinnishStemmer(_StandardStemmer):
u("ej\xE4"),
)

def stem(self, word):
def stem(self, word): # noqa: C901
"""
Stem a Finnish word and return the stemmed form.
Expand All @@ -137,6 +137,10 @@ def stem(self, word):
:return: The stemmed form.
:rtype: unicode
This method is too complex (51) -- ruff rule C901
This method has too many branches (58) -- ruff rule PLR0912
This method has too many statements (148) -- ruff rule PLR0915
Future edits to this method should reduce, not increase its complexity.
"""
word = word.lower()

Expand Down
6 changes: 5 additions & 1 deletion src/whoosh/lang/snowball/french.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class FrenchStemmer(_StandardStemmer):
)
__step4_suffixes = (u("i\xE8re"), u("I\xE8re"), "ion", "ier", "Ier", "e", u("\xEB"))

def stem(self, word):
def stem(self, word): # noqa: C901
"""
Stem a French word and return the stemmed form.
Expand All @@ -157,6 +157,10 @@ def stem(self, word):
:return: The stemmed form.
:rtype: unicode
This method is too complex (74) -- ruff rule C901
This method has too many branches (79) -- ruff rule PLR0912
This method has too many statements (160) -- ruff rule PLR0915
Future edits to this method should reduce, not increase its complexity.
"""
word = word.lower()

Expand Down

0 comments on commit 68bdd10

Please sign in to comment.