Add ruff for linting and code quality checks
Replace pyupgrade with ruff in the pre-commit configuration and add ruff configuration to pyproject.toml. Ruff is configured to enforce: - McCabe complexity checking (max complexity: 25) - Pyflakes rules (unused imports, undefined names, etc.) - Selected pycodestyle rules (imports, line length) - 79 character line length (OpenStack standard) - Python 3.10+ as the target version Fix lambda assignment in ceilometer/polling/manager.py to comply with ruff's E731 rule (do not assign a lambda expression, use a def). Change-Id: I897d03cd42d0eb7c92384e363ac25fcae838ada4 Signed-off-by: Emma Foley <efoley@redhat.com>
This commit is contained in:
@@ -32,11 +32,6 @@ repos:
|
||||
rev: v2.0.0
|
||||
hooks:
|
||||
- id: doc8
|
||||
- repo: https://github.com/asottile/pyupgrade
|
||||
rev: v3.20.0
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
args: [--py310-plus]
|
||||
- repo: https://github.com/openstack/bashate
|
||||
rev: 2.1.1
|
||||
hooks:
|
||||
@@ -48,3 +43,11 @@ repos:
|
||||
hooks:
|
||||
- id: codespell
|
||||
args: ['--ignore-words=doc/dictionary.txt']
|
||||
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.15.7
|
||||
hooks:
|
||||
- id: ruff-check
|
||||
args: ['--fix', '--unsafe-fixes', '--show-fixes'] #--diff']
|
||||
# Add this after submitting a commit for ruff check, then one that fixes linting, then one to move autopep to after this.
|
||||
#- id: ruff-format
|
||||
|
||||
@@ -203,7 +203,8 @@ class PollingTask:
|
||||
|
||||
# we relate the static resources and per-source discovery to
|
||||
# each combination of pollster and matching source
|
||||
resource_factory = lambda: Resources(agent_manager) # noqa: E731
|
||||
def resource_factory():
|
||||
return Resources(agent_manager)
|
||||
self.resources = collections.defaultdict(resource_factory)
|
||||
|
||||
conf = self.manager.conf
|
||||
|
||||
@@ -12,3 +12,48 @@ ignore = ["E731"]
|
||||
skip = "*.po,*.js,*.css,*.html,*.svg,HACKING.py,*hacking*,*build*,*_static*,doc/dictionary.txt,*.pyc,*.inv,*.gz,*.jpg,*.png,*.vsd,*.graffle,*.json,*telemetry-measurements.rst"
|
||||
count = true
|
||||
quiet-level = 4
|
||||
|
||||
[tool.ruff]
|
||||
line-length = 79
|
||||
target-version = "py310"
|
||||
|
||||
[tool.ruff.lint]
|
||||
select = [
|
||||
# mcabe complexity checks
|
||||
"C90",
|
||||
# multiple-imports-on-one-line, module-import-not-at-top-of-file
|
||||
"E4",
|
||||
# line-too-long, redundant-backslash
|
||||
"E5",
|
||||
"E7",
|
||||
"E9",
|
||||
# pyflakes
|
||||
"F",
|
||||
"W",
|
||||
]
|
||||
external = ["H"]
|
||||
ignore = [
|
||||
# we only use asserts for type narrowing
|
||||
"S101",
|
||||
# we do not use random number geneerators for crypto
|
||||
"S311",
|
||||
# S104 Possible binding to all interfaces
|
||||
"S104",
|
||||
# S105 Possible hardcoded password assigned to variable"
|
||||
"S105",
|
||||
# S106 Possible hardcoded password assigned to argument
|
||||
"S106",
|
||||
# S110 `try`-`except`-`pass` detected, consider logging the exception
|
||||
"S110",
|
||||
# UP031 % format — defer f-string migration to a later pass
|
||||
"UP031",
|
||||
# UP032 f-string — defer migration to a later pass
|
||||
"UP032",
|
||||
]
|
||||
|
||||
[tool.ruff.lint.per-file-ignores]
|
||||
"doc/*" = ["E501"]
|
||||
|
||||
[tool.ruff.lint.mccabe]
|
||||
# Flag errors (`C901`) whenever the complexity level exceeds 25.
|
||||
max-complexity = 25
|
||||
|
||||
@@ -83,6 +83,7 @@ ignore-path = .venv,.git,.tox,.eggs,*ceilometer/locale*,*lib/python*,ceilometer.
|
||||
# W503 line break before binary operator
|
||||
# W504 line break after binary operator
|
||||
ignore = E123,W503,W504
|
||||
select = H
|
||||
exclude=.venv,.git,.tox,.eggs,dist,doc,*lib/python*,*egg,build,install-guide
|
||||
# [H106] Do not put vim configuration in source files.
|
||||
# [H203] Use assertIs(Not)None to check for None.
|
||||
|
||||
Reference in New Issue
Block a user