diff --git a/kiwi_lint/api_distinct.py b/kiwi_lint/api_distinct.py index 7ed38dbd13..7b543ce1b4 100644 --- a/kiwi_lint/api_distinct.py +++ b/kiwi_lint/api_distinct.py @@ -1,8 +1,8 @@ -# Copyright (c) 2021 Alexander Todorov +# Copyright (c) 2021,2023 Alexander Todorov # Licensed under the GPL 2.0: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -from pylint import checkers, interfaces +from pylint import checkers from .utils import is_api_function @@ -15,8 +15,6 @@ class APIDistinctChecker(checkers.BaseChecker): current_api_method = None distinct_found = False - __implements__ = (interfaces.IAstroidChecker,) - name = "api-distinct-checker" msgs = { diff --git a/kiwi_lint/auto_field.py b/kiwi_lint/auto_field.py index 5e72252e95..9ac6a5bcad 100644 --- a/kiwi_lint/auto_field.py +++ b/kiwi_lint/auto_field.py @@ -1,10 +1,8 @@ -from pylint import checkers, interfaces +from pylint import checkers from pylint.checkers import utils class AutoFieldChecker(checkers.BaseChecker): - __implements__ = (interfaces.IAstroidChecker,) - name = "auto-field-checker" msgs = { @@ -15,7 +13,7 @@ class AutoFieldChecker(checkers.BaseChecker): ) } - @utils.check_messages("avoid-auto-field") + @utils.only_required_for_messages("avoid-auto-field") def visit_attribute(self, node): if node.attrname == "AutoField": self.add_message("avoid-auto-field", node=node) diff --git a/kiwi_lint/bulk_create.py b/kiwi_lint/bulk_create.py index 093c56b8e8..ebe81c841d 100644 --- a/kiwi_lint/bulk_create.py +++ b/kiwi_lint/bulk_create.py @@ -1,14 +1,12 @@ -# Copyright (c) 2018 Alexander Todorov +# Copyright (c) 2018,2023 Alexander Todorov # Licensed under the GPL 2.0: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -from pylint import checkers, interfaces +from pylint import checkers from pylint.checkers import utils class BulkCreateChecker(checkers.BaseChecker): - __implements__ = (interfaces.IAstroidChecker,) - name = "bulk-create-checker" msgs = { @@ -20,7 +18,7 @@ class BulkCreateChecker(checkers.BaseChecker): ) } - @utils.check_messages("bulk-create-used") + @utils.only_required_for_messages("bulk-create-used") def visit_attribute(self, node): if node.attrname == "bulk_create": self.add_message("bulk-create-used", node=node) diff --git a/kiwi_lint/datetime.py b/kiwi_lint/datetime.py index 5ddfe02edc..84d12a9303 100644 --- a/kiwi_lint/datetime.py +++ b/kiwi_lint/datetime.py @@ -5,12 +5,10 @@ """ from astroid import nodes -from pylint import checkers, interfaces +from pylint import checkers class DatetimeChecker(checkers.BaseChecker): - __implements__ = (interfaces.IAstroidChecker,) - name = "datetime-checker" msgs = { diff --git a/kiwi_lint/db_column.py b/kiwi_lint/db_column.py index 46ca591d0a..11b4dfb776 100644 --- a/kiwi_lint/db_column.py +++ b/kiwi_lint/db_column.py @@ -1,10 +1,8 @@ -from pylint import checkers, interfaces +from pylint import checkers from pylint.checkers import utils class DbColumnChecker(checkers.BaseChecker): - __implements__ = (interfaces.IAstroidChecker,) - name = "db-column-used" msgs = { @@ -16,7 +14,7 @@ class DbColumnChecker(checkers.BaseChecker): ) } - @utils.check_messages("db-column-used") + @utils.only_required_for_messages("db-column-used") def visit_keyword(self, node): if node.arg == "db_column": self.add_message("db-column-used", node=node) diff --git a/kiwi_lint/docstring.py b/kiwi_lint/docstring.py index 2582211c1a..3ed502a731 100644 --- a/kiwi_lint/docstring.py +++ b/kiwi_lint/docstring.py @@ -1,19 +1,14 @@ -# Copyright (c) 2018 Alexander Todorov +# Copyright (c) 2018,2023 Alexander Todorov # Licensed under the GPL 2.0: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html import tokenize -from pylint import checkers, interfaces +from pylint import checkers from pylint.checkers import utils class DocstringChecker(checkers.BaseTokenChecker): - __implements__ = ( - interfaces.ITokenChecker, - interfaces.IAstroidChecker, - ) - name = "docstring-checker" msgs = { @@ -61,9 +56,9 @@ def visit_classdef(self, node): def visit_functiondef(self, node): self._check_docstring(node) - @utils.check_messages("use-triple-double-quotes") + @utils.only_required_for_messages("use-triple-double-quotes") def _check_docstring(self, node): - if node.doc in self._string_tokens: - token = self._string_tokens[node.doc] + if node.doc_node and node.doc_node.value in self._string_tokens: + token = self._string_tokens[node.doc_node.value] if not token.startswith('"""'): self.add_message("use-triple-double-quotes", node=node) diff --git a/kiwi_lint/dunder_attributes.py b/kiwi_lint/dunder_attributes.py index 810a23ac41..2d38105678 100644 --- a/kiwi_lint/dunder_attributes.py +++ b/kiwi_lint/dunder_attributes.py @@ -1,15 +1,13 @@ -# Copyright (c) 2018 Alexander Todorov +# Copyright (c) 2018,2023 Alexander Todorov # Licensed under the GPL 2.0: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html import astroid -from pylint import checkers, interfaces +from pylint import checkers from pylint.checkers import utils class DunderClassAttributeChecker(checkers.BaseChecker): - __implements__ = (interfaces.IAstroidChecker,) - name = "dunder-class-attribute-checker" msgs = { @@ -21,7 +19,7 @@ class DunderClassAttributeChecker(checkers.BaseChecker): ) } - @utils.check_messages("dunder-class-attribute") + @utils.only_required_for_messages("dunder-class-attribute") def visit_classdef(self, node): """Detect when class attributes use double underscores.""" # we can redefine special methods (e.g. __iter__) and some attributes, diff --git a/kiwi_lint/empty.py b/kiwi_lint/empty.py index 9d4e546654..af7742b392 100644 --- a/kiwi_lint/empty.py +++ b/kiwi_lint/empty.py @@ -1,17 +1,15 @@ -# Copyright (c) 2018 Alexander Todorov +# Copyright (c) 2018,2023 Alexander Todorov # Licensed under the GPL 2.0: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html import os import astroid -from pylint import checkers, interfaces +from pylint import checkers from pylint.checkers import utils class EmptyModuleChecker(checkers.BaseChecker): - __implements__ = (interfaces.IAstroidChecker,) - name = "empty-module-checker" msgs = { @@ -23,15 +21,13 @@ class EmptyModuleChecker(checkers.BaseChecker): ) } - @utils.check_messages("remove-empty-module") + @utils.only_required_for_messages("remove-empty-module") def visit_module(self, node): if not node.body and not node.path[0].endswith("__init__.py"): self.add_message("remove-empty-module", node=node) class ModuleInDirectoryWithoutInitChecker(checkers.BaseChecker): - __implements__ = (interfaces.IAstroidChecker,) - name = "dir-without-init-checker" msgs = { @@ -73,7 +69,7 @@ def visit_module(self, node): for file_name in node.path: self.discovered_python_files.add(file_name) - @utils.check_messages("module-in-directory-without-init") + @utils.only_required_for_messages("module-in-directory-without-init") def close(self): diff = self.all_python_files - self.discovered_python_files diff = list(diff) @@ -86,8 +82,6 @@ def close(self): class EmptyClassChecker(checkers.BaseChecker): - __implements__ = (interfaces.IAstroidChecker,) - name = "empty-class-checker" msgs = { @@ -99,7 +93,7 @@ class EmptyClassChecker(checkers.BaseChecker): ) } - @utils.check_messages("remove-empty-class") + @utils.only_required_for_messages("remove-empty-class") def visit_classdef(self, node): if not node.body: self.add_message("remove-empty-class", node=node) diff --git a/kiwi_lint/forms.py b/kiwi_lint/forms.py index e3aa93e2f3..18546b307a 100644 --- a/kiwi_lint/forms.py +++ b/kiwi_lint/forms.py @@ -1,10 +1,8 @@ -from pylint import checkers, interfaces +from pylint import checkers from pylint_django.utils import node_is_subclass class FormFieldChecker(checkers.BaseChecker): - __implements__ = (interfaces.IAstroidChecker,) - name = "form-field-label-checker" msgs = { @@ -38,8 +36,6 @@ class ModelFormChecker(checkers.BaseChecker): Check to ensure that all forms inherit from ModelForm. """ - __implements__ = (interfaces.IAstroidChecker,) - name = "model-form-checker" msgs = { diff --git a/kiwi_lint/generic_foreign_key.py b/kiwi_lint/generic_foreign_key.py index c7666241cd..108b33b1b5 100644 --- a/kiwi_lint/generic_foreign_key.py +++ b/kiwi_lint/generic_foreign_key.py @@ -1,11 +1,8 @@ import astroid from pylint.checkers import BaseChecker, utils -from pylint.interfaces import IAstroidChecker class GenericForeignKeyChecker(BaseChecker): - __implements__ = (IAstroidChecker,) - name = "generic-foreign-key-checker" msgs = { @@ -17,7 +14,7 @@ class GenericForeignKeyChecker(BaseChecker): ) } - @utils.check_messages("avoid-generic-foreign-key") + @utils.only_required_for_messages("avoid-generic-foreign-key") def visit_call(self, node): if ( isinstance(node.func, astroid.Name) diff --git a/kiwi_lint/list_comprehension.py b/kiwi_lint/list_comprehension.py index b17f947aeb..7b94f010a0 100644 --- a/kiwi_lint/list_comprehension.py +++ b/kiwi_lint/list_comprehension.py @@ -1,14 +1,12 @@ -# Copyright (c) 2018 Alexander Todorov +# Copyright (c) 2018,2023 Alexander Todorov # Licensed under the GPL 2.0: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -from pylint import checkers, interfaces +from pylint import checkers from pylint.checkers import utils class ListComprehensionChecker(checkers.BaseChecker): - __implements__ = (interfaces.IAstroidChecker,) - name = "list-comprehension-checker" msgs = { @@ -19,6 +17,6 @@ class ListComprehensionChecker(checkers.BaseChecker): ) } - @utils.check_messages("avoid-list-comprehension") + @utils.only_required_for_messages("avoid-list-comprehension") def visit_listcomp(self, node): self.add_message("avoid-list-comprehension", node=node) diff --git a/kiwi_lint/missing_permissions.py b/kiwi_lint/missing_permissions.py index 1004ab65c5..374ef61150 100644 --- a/kiwi_lint/missing_permissions.py +++ b/kiwi_lint/missing_permissions.py @@ -1,9 +1,9 @@ -# Copyright (c) 2019-2021 Alexander Todorov +# Copyright (c) 2019-2021,2023 Alexander Todorov # Licensed under the GPL 2.0: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html import astroid -from pylint import checkers, interfaces +from pylint import checkers from .utils import is_api_function @@ -22,8 +22,6 @@ class MissingPermissionsChecker(checkers.BaseChecker): ] inside_views_module = False - __implements__ = (interfaces.IAstroidChecker,) - name = "mising-permissions-checker" msgs = { @@ -96,8 +94,6 @@ class MissingAPIPermissionsChecker(checkers.BaseChecker): Will inspect API functions for the presence of permissions decorator! """ - __implements__ = (interfaces.IAstroidChecker,) - name = "mising-api-permissions-checker" msgs = { diff --git a/kiwi_lint/nested_definition.py b/kiwi_lint/nested_definition.py index 360f5da983..4425241a8e 100644 --- a/kiwi_lint/nested_definition.py +++ b/kiwi_lint/nested_definition.py @@ -1,15 +1,13 @@ -# Copyright (c) 2019 Alexander Todorov +# Copyright (c) 2019,2023 Alexander Todorov # Licensed under the GPL 2.0: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html import astroid -from pylint import checkers, interfaces +from pylint import checkers from pylint.checkers import utils class NestedDefinitionChecker(checkers.BaseChecker): - __implements__ = (interfaces.IAstroidChecker,) - name = "nested-definition-checker" msgs = { @@ -25,12 +23,12 @@ class NestedDefinitionChecker(checkers.BaseChecker): ), } - @utils.check_messages("nested-function-found") + @utils.only_required_for_messages("nested-function-found") def visit_functiondef(self, node): if not isinstance(node.parent, (astroid.Module, astroid.ClassDef)): self.add_message("nested-function-found", node=node) - @utils.check_messages("nested-class-found") + @utils.only_required_for_messages("nested-class-found") def visit_classdef(self, node): if not isinstance(node.parent, astroid.Module) and node.name not in [ "Meta", diff --git a/kiwi_lint/objects_update.py b/kiwi_lint/objects_update.py index 1760a74e13..7eb49a0c79 100644 --- a/kiwi_lint/objects_update.py +++ b/kiwi_lint/objects_update.py @@ -1,14 +1,12 @@ -# Copyright (c) 2018 Alexander Todorov +# Copyright (c) 2018,2023 Alexander Todorov # Licensed under the GPL 2.0: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -from pylint import checkers, interfaces +from pylint import checkers from pylint.checkers import utils class ObjectsUpdateChecker(checkers.BaseChecker): - __implements__ = (interfaces.IAstroidChecker,) - name = "objects-update-checker" msgs = { @@ -19,7 +17,7 @@ class ObjectsUpdateChecker(checkers.BaseChecker): ) } - @utils.check_messages("objects-update-used") + @utils.only_required_for_messages("objects-update-used") def visit_attribute(self, node): """ Note: this checker will produce false-positives on diff --git a/kiwi_lint/one_to_one_field.py b/kiwi_lint/one_to_one_field.py index 7cf45c984e..51f9dc225c 100644 --- a/kiwi_lint/one_to_one_field.py +++ b/kiwi_lint/one_to_one_field.py @@ -1,10 +1,8 @@ -from pylint import checkers, interfaces +from pylint import checkers from pylint.checkers import utils class OneToOneFieldChecker(checkers.BaseChecker): - __implements__ = (interfaces.IAstroidChecker,) - name = "one-to-one-field-checker" msgs = { @@ -16,7 +14,7 @@ class OneToOneFieldChecker(checkers.BaseChecker): ) } - @utils.check_messages("one-to-one-field") + @utils.only_required_for_messages("one-to-one-field") def visit_attribute(self, node): if node.attrname == "OneToOneField": self.add_message("one-to-one-field", node=node) diff --git a/kiwi_lint/raw_sql.py b/kiwi_lint/raw_sql.py index 3565fab257..d94dfb5a7c 100644 --- a/kiwi_lint/raw_sql.py +++ b/kiwi_lint/raw_sql.py @@ -1,15 +1,13 @@ -# Copyright (c) 2018 Alexander Todorov +# Copyright (c) 2018,2023 Alexander Todorov # Licensed under the GPL 2.0: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html import astroid -from pylint import checkers, interfaces +from pylint import checkers from pylint.checkers import utils class RawSQLChecker(checkers.BaseChecker): - __implements__ = (interfaces.IAstroidChecker,) - name = "raw-sql-checker" msgs = { @@ -20,7 +18,7 @@ class RawSQLChecker(checkers.BaseChecker): ) } - @utils.check_messages("avoid-raw-sql") + @utils.only_required_for_messages("avoid-raw-sql") def visit_attribute(self, node): # looking for .extra(select={}) patterns if node.attrname == "extra" and isinstance(node.parent, astroid.Call): diff --git a/kiwi_lint/similar_string.py b/kiwi_lint/similar_string.py index 2f0c63b771..ac37b0ee48 100644 --- a/kiwi_lint/similar_string.py +++ b/kiwi_lint/similar_string.py @@ -4,12 +4,10 @@ import astroid from pylint.checkers import BaseChecker, utils -from pylint.interfaces import IAstroidChecker from textdistance import levenshtein class SimilarStringChecker(BaseChecker): - __implements__ = (IAstroidChecker,) name = "similar-string-checker" msgs = { @@ -65,7 +63,7 @@ def check_similar_string(self, translation_string): return key, similarity return None, None - @utils.check_messages("similar-string") + @utils.only_required_for_messages("similar-string") def visit_call(self, node): if not ( isinstance(node.func, astroid.Name) @@ -89,7 +87,7 @@ def check_similar_and_add_error_message( if similar_string: if isinstance(node, str): - error_message["node"] = astroid.Module(node, file=node, doc=None) + error_message["node"] = astroid.Module(node, file=node) else: error_message["node"] = node error_message["args"] = ( diff --git a/kiwi_lint/tags.py b/kiwi_lint/tags.py index 66b52ccbdc..67e885b665 100644 --- a/kiwi_lint/tags.py +++ b/kiwi_lint/tags.py @@ -1,15 +1,13 @@ -# Copyright (c) 2018 Alexander Todorov +# Copyright (c) 2018,2023 Alexander Todorov # Licensed under the GPL 2.0: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html import astroid -from pylint import checkers, interfaces +from pylint import checkers from pylint.checkers import utils class TagsChecker(checkers.BaseChecker): - __implements__ = (interfaces.IAstroidChecker,) - name = "tags-checker" msgs = { @@ -21,7 +19,7 @@ class TagsChecker(checkers.BaseChecker): ) } - @utils.check_messages("tag-objects-get_or_create") + @utils.only_required_for_messages("tag-objects-get_or_create") def visit_attribute(self, node): if ( node.attrname == "get_or_create" diff --git a/kiwi_lint/views.py b/kiwi_lint/views.py index e4ebb96913..2a2064925a 100644 --- a/kiwi_lint/views.py +++ b/kiwi_lint/views.py @@ -8,7 +8,7 @@ import django from django.conf import settings from django.urls.resolvers import URLPattern, URLResolver -from pylint import checkers, interfaces +from pylint import checkers class DjangoViewsChecker(checkers.BaseChecker): @@ -89,8 +89,6 @@ class ClassBasedViewChecker(DjangoViewsChecker): this project be class based! """ - __implements__ = (interfaces.IAstroidChecker,) - name = "class-based-view-checker" msgs = { diff --git a/requirements/readthedocs.txt b/requirements/readthedocs.txt index 61e09797a6..cc0f89c5f4 100644 --- a/requirements/readthedocs.txt +++ b/requirements/readthedocs.txt @@ -12,6 +12,6 @@ factory_boy mock pydot # linting tools -pylint-django==2.5.3 +pylint-django==2.5.5 twine pyOpenSSL