Skip to content

Commit

Permalink
Add ruff checker rules and fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
martonilles committed Oct 31, 2023
1 parent cbb5609 commit 6d14af0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cpematcher/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(
self.version_end_including = Version(version_end_including)
self.version_end_excluding = Version(version_end_excluding)

def matches(self, another_cpe):
def matches(self, another_cpe): # noqa: C901
"""Verify if `another_cpe` matches, first through field comparison and
then using the border constraints.
Expand Down Expand Up @@ -131,7 +131,7 @@ class CPEOperation:

def _get_value(self, cpe_dict, key):
for k in self.VERSION_MAP[key]:
if k in cpe_dict.keys():
if k in cpe_dict:
return cpe_dict[k]

return None
Expand Down
7 changes: 4 additions & 3 deletions cpematcher/utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import contextlib


# heavily inspired by https://stackoverflow.com/a/21882672
def split_cpe_string(string):
ret = []
current = []
itr = iter(string)
for ch in itr:
if ch == "\\":
try:
with contextlib.suppress(StopIteration):
# skip the next character; it has been escaped!
current.append(next(itr))
except StopIteration:
pass
elif ch == ":":
# split! (add current to the list and reset it)
ret.append("".join(current))
Expand Down
34 changes: 34 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,37 @@ pre-commit = "^3.5.0"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.ruff]
target-version = "py311"

select = [
"C90", # mccabe
"C4", # flake8-comprehensions
"COM818", # flake8-commas; trailing-comma-on-bare-tuple
"E", # pycodestyle (errors)
"F", # pyflakes
"I", # isort
"ISC", # flake8-implicit-str-concats
"PIE", # flake8-pie
"RUF", # ruff's own lints
"SIM", # flake8-simplify
"UP", # pyupgrade
"W", # pycodestyle (warnings)
]

ignore = [
"E501", # line-too-long: Let black handle line length violations
"RUF012", # mutable-class-default: Wants to annotate things like `__mapper_args__` with `ClassVar`, producing noise
]

# Do not remove unused imports automatically in __init__.py files
ignore-init-module-imports = true

[tool.ruff.per-file-ignores]
"*/__init__.py" = [
"F401"
]

[tool.ruff.mccabe]
max-complexity = 5

0 comments on commit 6d14af0

Please sign in to comment.