Skip to content
Open
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
6 changes: 3 additions & 3 deletions pylint_django/checkers/auth_user.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pylint import checkers
from pylint.checkers.utils import only_required_for_messages

from pylint_django.__pkginfo__ import BASE_ID
from pylint_django.compat import check_messages


class AuthUserChecker(checkers.BaseChecker):
Expand All @@ -20,14 +20,14 @@ class AuthUserChecker(checkers.BaseChecker):
),
}

@check_messages("hard-coded-auth-user")
@only_required_for_messages("hard-coded-auth-user")
def visit_const(self, node):
# for now we don't check if the parent is a ForeignKey field
# because the user model should not be hard-coded anywhere
if node.value == "auth.User":
self.add_message("hard-coded-auth-user", node=node)

@check_messages("imported-auth-user")
@only_required_for_messages("imported-auth-user")
def visit_importfrom(self, node):
if node.modname == "django.contrib.auth.models":
for imported_names in node.names:
Expand Down
4 changes: 2 additions & 2 deletions pylint_django/checkers/django_installed.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pylint.checkers import BaseChecker
from pylint.checkers.utils import only_required_for_messages

from pylint_django.__pkginfo__ import BASE_ID
from pylint_django.compat import check_messages


class DjangoInstalledChecker(BaseChecker):
Expand All @@ -23,7 +23,7 @@ class DjangoInstalledChecker(BaseChecker):
),
}

@check_messages("django-not-available")
@only_required_for_messages("django-not-available")
def open(self):
try:
__import__("django")
Expand Down
4 changes: 2 additions & 2 deletions pylint_django/checkers/foreign_key_strings.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import astroid
from pylint.checkers import BaseChecker
from pylint.checkers.utils import only_required_for_messages

from pylint_django.__pkginfo__ import BASE_ID
from pylint_django.compat import check_messages
from pylint_django.transforms import foreignkey


Expand Down Expand Up @@ -133,7 +133,7 @@ def open(self):
# duplicating the django_installed checker, it'll do for now. In the future, merging
# those two checkers together might make sense.

@check_messages("django-not-configured")
@only_required_for_messages("django-not-configured")
def visit_module(self, node):
if self._raise_warning:
# just add it to the first node we see... which isn't nice but not sure what else to do
Expand Down
4 changes: 2 additions & 2 deletions pylint_django/checkers/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from astroid.nodes import Assign, AssignName, ClassDef
from pylint.checkers import BaseChecker
from pylint.checkers.utils import only_required_for_messages

from pylint_django.__pkginfo__ import BASE_ID
from pylint_django.compat import check_messages
from pylint_django.utils import node_is_subclass


Expand All @@ -27,7 +27,7 @@ class FormChecker(BaseChecker):
)
}

@check_messages("modelform-uses-exclude")
@only_required_for_messages("modelform-uses-exclude")
def visit_classdef(self, node):
"""Class visitor."""
if not node_is_subclass(node, "django.forms.models.ModelForm", ".ModelForm"):
Expand Down
4 changes: 2 additions & 2 deletions pylint_django/checkers/json_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import astroid
from pylint import checkers
from pylint.checkers.utils import only_required_for_messages

from pylint_django.__pkginfo__ import BASE_ID
from pylint_django.compat import check_messages


class JsonResponseChecker(checkers.BaseChecker):
Expand Down Expand Up @@ -41,7 +41,7 @@ class JsonResponseChecker(checkers.BaseChecker):
),
}

@check_messages(
@only_required_for_messages(
"http-response-with-json-dumps",
"http-response-with-content-type-json",
"redundant-content-type-for-json-response",
Expand Down
6 changes: 3 additions & 3 deletions pylint_django/checkers/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

import astroid
from pylint import checkers
from pylint.checkers.utils import only_required_for_messages
from pylint_plugin_utils import suppress_message

from pylint_django import compat
from pylint_django.__pkginfo__ import BASE_ID
from pylint_django.compat import check_messages
from pylint_django.utils import is_migrations_module


Expand Down Expand Up @@ -84,7 +84,7 @@ def visit_call(self, node):
if node not in self._possible_offences[module]:
self._possible_offences[module].append(node)

@check_messages("new-db-field-with-default")
@only_required_for_messages("new-db-field-with-default")
def close(self):
def _path(node):
return node.path
Expand Down Expand Up @@ -121,7 +121,7 @@ class MissingBackwardsMigrationChecker(checkers.BaseChecker):
)
}

@check_messages("missing-backwards-migration-callable")
@only_required_for_messages("missing-backwards-migration-callable")
def visit_call(self, node):
try:
module = node.frame().parent
Expand Down
7 changes: 3 additions & 4 deletions pylint_django/checkers/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""Models."""

from astroid import Const
from astroid.nodes import Assign, AssignName, ClassDef, FunctionDef
from astroid.nodes import Assign, AssignName, ClassDef, Const, FunctionDef
from pylint.checkers import BaseChecker
from pylint.checkers.utils import only_required_for_messages

from pylint_django.__pkginfo__ import BASE_ID
from pylint_django.compat import check_messages
from pylint_django.utils import PY3, node_is_subclass

MESSAGES = {
Expand Down Expand Up @@ -78,7 +77,7 @@ class ModelChecker(BaseChecker):
name = "django-model-checker"
msgs = MESSAGES

@check_messages("model-missing-unicode")
@only_required_for_messages("model-missing-unicode")
def visit_classdef(self, node): # noqa: PLR0911
"""Class visitor."""
if not node_is_subclass(node, "django.db.models.base.Model", ".Model"):
Expand Down
5 changes: 0 additions & 5 deletions pylint_django/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
except ImportError:
from astroid.util import Uninferable

try:
from pylint.checkers.utils import only_required_for_messages as check_messages
except (ImportError, ModuleNotFoundError):
from pylint.checkers.utils import check_messages

import pylint

# pylint before version 2.3 does not support load_configuration() hook.
Expand Down
Loading