Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more ruff checks and fix the ruff configuration #442

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions pylint_django/augmentations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,11 @@ class ModelB(models.Model):
# if this is a X_set method, that's a pretty strong signal that this is the default
# Django name, rather than one set by related_name
quack = True
else:
# we will
if isinstance(node.parent, Attribute):
func_name = getattr(node.parent, "attrname", None)
if func_name in MANAGER_ATTRS:
quack = True
# we will
elif isinstance(node.parent, Attribute):
func_name = getattr(node.parent, "attrname", None)
if func_name in MANAGER_ATTRS:
quack = True

if quack:
children = list(node.get_children())
Expand Down Expand Up @@ -522,7 +521,7 @@ def _attribute_is_magic(node, attrs, parents):
try:
for cls in node.last_child().inferred():
if isinstance(cls, Super):
cls = cls._self_class # pylint: disable=protected-access
cls = cls._self_class # pylint: disable=protected-access # noqa:PLW2901
if node_is_subclass(cls, *parents) or cls.qname() in parents:
return True
except InferenceError:
Expand Down
3 changes: 2 additions & 1 deletion pylint_django/checkers/foreign_key_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def open(self):
import django # pylint: disable=import-outside-toplevel

django.setup()
from django.apps import apps # noqa pylint: disable=import-outside-toplevel,unused-import
# pylint: disable-next=import-outside-toplevel,unused-import
from django.apps import apps # noqa: F401

except ImproperlyConfigured:
# this means that Django wasn't able to configure itself using some defaults
Expand Down
2 changes: 1 addition & 1 deletion pylint_django/checkers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ModelChecker(BaseChecker):
msgs = MESSAGES

@check_messages("model-missing-unicode")
def visit_classdef(self, node):
def visit_classdef(self, node): # noqa: PLR0911
"""Class visitor."""
if not node_is_subclass(node, "django.db.models.base.Model", ".Model"):
# we only care about models
Expand Down
2 changes: 1 addition & 1 deletion pylint_django/tests/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, test_file):
# if hasattr(test_file, 'option_file') and test_file.option_file is None:
# pylint: disable=super-with-arguments
# TODO Fix this and the CI (?)
super(PylintDjangoLintModuleTest, self).__init__(test_file) # noqa
super(PylintDjangoLintModuleTest, self).__init__(test_file) # noqa: UP008
self._linter.load_plugin_modules(["pylint_django"])
self._linter.load_plugin_configuration()

Expand Down
33 changes: 23 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,30 @@ line-length = 120

[tool.ruff]
line-length = 120
select = [
"E", # pycodestyle
"F", # pyflakes
"W", # pycodestyle
"B", # bugbear
"I", # isort
"RUF", # ruff
"UP", # pyupgrade
lint.select = [
"B", # bugbear
"E", # pycodestyle
"F", # pyflakes
"FA100", # add future annotations
"I", # isort
"PGH004", # pygrep-hooks - Use specific rule codes when using noqa
"PIE", # flake8-pie
"PLC", # pylint convention
"PLE", # pylint error
"PLR", # pylint refactor
"PLR1714", # Consider merging multiple comparisons
"PLW", # pylint warning
"PYI", # flake8-pyi
"RUF", # ruff
"T100", # flake8-debugger
"UP", # pyupgrade
"W", # pycodestyle
]
ignore = [
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
lint.ignore = [
"PLR0912", # Too many branches, worse than C901
"PLR0915", # Too many statements, worse than C901
"PLR2004", # Magic value used in comparison, opinionated
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
]

[tool.isort]
Expand Down