Skip to content

Commit

Permalink
modify saltpylint for pylint 3.0.3
Browse files Browse the repository at this point in the history
Current saltpylint works with pylint==2.13.9. It does not work with
newer versions of pylint such as 2.17 ... 3.0.3. Pylint 3.0.3 includes
many code changes, such as remove exposed checker interfaces, remove
some @utils fucitons, remove checker member functions (config)  .. The
submitted pr removes those disappeared functions. Review is required to
make sure it does not remove necessary checks as a result.

This commit will fix issues
- #48
- #47
  • Loading branch information
MaxBear committed Jan 30, 2024
1 parent 24a082f commit 904a3a9
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 82 deletions.
33 changes: 0 additions & 33 deletions saltpylint/blacklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# Import pylint libs
import astroid
from saltpylint.checkers import BaseChecker, utils
from pylint.interfaces import IAstroidChecker

BLACKLISTED_IMPORTS_MSGS = {
'E9402': ('Uses of a blacklisted module %r: %s',
Expand All @@ -46,8 +45,6 @@

class BlacklistedImportsChecker(BaseChecker):

__implements__ = IAstroidChecker

name = 'blacklisted-imports'
msgs = BLACKLISTED_IMPORTS_MSGS
priority = -2
Expand All @@ -62,7 +59,6 @@ def open(self):
'unittest',
'unittest2')

@utils.check_messages('blacklisted-imports')
def visit_import(self, node):
'''triggered when an import statement is seen'''
module_filename = node.root().file
Expand All @@ -75,7 +71,6 @@ def visit_import(self, node):
for name in names:
self._check_blacklisted_module(node, name)

@utils.check_messages('blacklisted-imports')
def visit_importfrom(self, node):
'''triggered when a from statement is seen'''
module_filename = node.root().file
Expand Down Expand Up @@ -238,8 +233,6 @@ def _check_blacklisted_module(self, node, mod_path):

class BlacklistedLoaderModulesUsageChecker(BaseChecker):

__implements__ = IAstroidChecker

name = 'blacklisted-unmocked-patching'
msgs = BLACKLISTED_LOADER_USAGE_MSGS
priority = -2
Expand All @@ -259,21 +252,18 @@ def close(self):
self.process_module = False
self.imported_salt_modules = {}

@utils.check_messages('blacklisted-unmocked-patching')
def visit_module(self, node):
module_filename = node.root().file
if not fnmatch.fnmatch(os.path.basename(module_filename), 'test_*.py*'):
return
self.process_module = True

@utils.check_messages('blacklisted-unmocked-patching')
def leave_module(self, node):
if self.process_module:
# Reset
self.process_module = False
self.imported_salt_modules = {}

@utils.check_messages('blacklisted-unmocked-patching')
def visit_import(self, node):
'''triggered when an import statement is seen'''
if self.process_module:
Expand All @@ -287,7 +277,6 @@ def visit_import(self, node):
if module not in self.imported_salt_modules:
self.imported_salt_modules[module] = module

@utils.check_messages('blacklisted-unmocked-patching')
def visit_importfrom(self, node):
'''triggered when a from statement is seen'''
if self.process_module:
Expand All @@ -301,7 +290,6 @@ def visit_importfrom(self, node):
if module not in self.imported_salt_modules:
self.imported_salt_modules[module] = module

@utils.check_messages('blacklisted-loader-usage')
def visit_assign(self, node, *args):
if not self.process_module:
return
Expand Down Expand Up @@ -363,8 +351,6 @@ def visit_assign(self, node, *args):

class ResourceLeakageChecker(BaseChecker):

__implements__ = IAstroidChecker

name = 'resource-leakage'
msgs = RESOURCE_LEAKAGE_MSGS
priority = -2
Expand Down Expand Up @@ -413,8 +399,6 @@ def visit_call(self, node):

class MovedTestCaseClassChecker(BaseChecker):

__implements__ = IAstroidChecker

name = 'moved-test-case-class'
msgs = MOVED_TEST_CASE_CLASSES_MSGS
priority = -2
Expand All @@ -425,20 +409,17 @@ def open(self):
def close(self):
self.process_module = False

@utils.check_messages('moved-test-case-class')
def visit_module(self, node):
module_filename = node.root().file
if not fnmatch.fnmatch(os.path.basename(module_filename), 'test_*.py*'):
return
self.process_module = True

@utils.check_messages('moved-test-case-class')
def leave_module(self, node):
if self.process_module:
# Reset
self.process_module = False

@utils.check_messages('moved-test-case-class')
def visit_importfrom(self, node):
'''triggered when a from statement is seen'''
if self.process_module:
Expand All @@ -451,7 +432,6 @@ def visit_importfrom(self, node):
continue
self._check_moved_imports(node, module)

@utils.check_messages('moved-test-case-class')
def visit_classdef(self, node):
for base in node.bases:
if not hasattr(base, 'attrname'):
Expand Down Expand Up @@ -488,8 +468,6 @@ def _check_moved_imports(self, node, module, import_as=None):

class BlacklistedFunctionsChecker(BaseChecker):

__implements__ = IAstroidChecker

name = 'blacklisted-functions'
msgs = BLACKLISTED_FUNCTIONS_MSGS
priority = -2
Expand All @@ -505,16 +483,6 @@ class BlacklistedFunctionsChecker(BaseChecker):

def open(self):
self.blacklisted_functions = {}
blacklist = [
x.strip() for x in self.config.blacklisted_functions.split(',')]
for item in [x.strip() for x in
self.config.blacklisted_functions.split(',')]:
try:
key, val = [x.strip() for x in item.split('=')]
except ValueError:
pass
else:
self.blacklisted_functions[key] = val

def _get_full_name(self, node):
try:
Expand Down Expand Up @@ -542,7 +510,6 @@ def _get_full_name(self, node):
# full name for the function.
return '.'.join(ret[::-1])

@utils.check_messages('blacklisted-functions')
def visit_call(self, node):
if self.blacklisted_functions:
full_name = self._get_full_name(node)
Expand Down
3 changes: 0 additions & 3 deletions saltpylint/fileperms.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import stat

# Import PyLint libs
from pylint.interfaces import IRawChecker
from saltpylint.checkers import BaseChecker


Expand All @@ -29,8 +28,6 @@ class FilePermsChecker(BaseChecker):
Check for files with undesirable permissions
'''

__implements__ = IRawChecker

name = 'fileperms'
msgs = {'E0599': ('Module file has the wrong file permissions(expected %s): %s',
'file-perms',
Expand Down
3 changes: 0 additions & 3 deletions saltpylint/minpyver.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import sys

# Import PyLint libs
from pylint.interfaces import IRawChecker
from saltpylint.checkers import BaseChecker

# Import 3rd-party libs
Expand All @@ -40,8 +39,6 @@ class MininumPythonVersionChecker(BaseChecker):
Check the minimal required python version
'''

__implements__ = IRawChecker

name = 'mininum-python-version'
msgs = {'E0598': ('Incompatible Python %s code found: %s',
'minimum-python-version',
Expand Down
3 changes: 0 additions & 3 deletions saltpylint/pep263.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import itertools

# Import PyLint libs
from pylint.interfaces import IRawChecker
from saltpylint.checkers import BaseChecker

# Import 3rd-party libs
Expand All @@ -28,8 +27,6 @@ class FileEncodingChecker(BaseChecker):
Check for PEP263 compliant file encoding in file.
'''

__implements__ = IRawChecker

name = 'pep263'
msgs = {'W9901': ('PEP263: Multiple file encodings',
'multiple-encoding-in-file',
Expand Down
3 changes: 0 additions & 3 deletions saltpylint/pep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import six

# Import PyLint libs
from pylint.interfaces import IRawChecker
from pylint.__pkginfo__ import numversion as pylint_version_info
from saltpylint.checkers import BaseChecker

Expand Down Expand Up @@ -64,8 +63,6 @@ def error(self, line_number, offset, text, check):

class _PEP8BaseChecker(BaseChecker):

__implements__ = IRawChecker

name = 'pep8'

priority = -1
Expand Down
3 changes: 0 additions & 3 deletions saltpylint/py3modernize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
)

# Import PyLint libs
from pylint.interfaces import IRawChecker
from saltpylint.checkers import BaseChecker

if HAS_REQUIRED_LIBS:
Expand Down Expand Up @@ -95,8 +94,6 @@ class Py3Modernize(BaseChecker):
Check for PEP263 compliant file encoding in file.
'''

__implements__ = IRawChecker

name = 'modernize'
msgs = {'W1698': ('Unable to run modernize. Parse Error: %s',
'modernize-parse-error',
Expand Down
23 changes: 2 additions & 21 deletions saltpylint/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@
from saltpylint.checkers import BaseChecker, utils
from pylint.checkers import BaseTokenChecker

try:
# >= pylint 1.0
from pylint.interfaces import IAstroidChecker
except ImportError: # < pylint 1.0
from pylint.interfaces import IASTNGChecker as IAstroidChecker # pylint: disable=no-name-in-module

from pylint.interfaces import ITokenChecker, IRawChecker
from astroid.exceptions import InferenceError
try:
from astroid.exceptions import NameInferenceError
Expand Down Expand Up @@ -71,8 +64,6 @@ class NameInferenceError(Exception):

class StringCurlyBracesFormatIndexChecker(BaseChecker):

__implements__ = IAstroidChecker

name = 'string'
msgs = STRING_FORMAT_MSGS
priority = -1
Expand All @@ -93,11 +84,7 @@ class StringCurlyBracesFormatIndexChecker(BaseChecker):
),
)

@utils.check_messages(*(STRING_FORMAT_MSGS.keys()))
def visit_binop(self, node):
if not self.config.enforce_string_formatting_over_substitution:
return

if node.op != '%':
return

Expand All @@ -112,10 +99,7 @@ def visit_binop(self, node):
return

if required_keys or required_num_args:
if self.config.string_substitutions_usage_is_an_error:
msgid = 'E1321'
else:
msgid = 'W1321'
msgid = 'W1321'
self.add_message(
msgid, node=node.left, args=node.left.value
)
Expand All @@ -125,7 +109,6 @@ def visit_binop(self, node):
'E1322', node=node.left, args=node.left.value
)

@utils.check_messages(*(STRING_FORMAT_MSGS.keys()))
def visit_call(self, node):
func = utils.safe_infer(node.func)
if isinstance(func, astroid.BoundMethod) and func.name == 'format':
Expand All @@ -151,8 +134,7 @@ def visit_call(self, node):
)

if BAD_FORMATTING_SLOT.findall(inferred.value):
if self.config.un_indexed_curly_braces_always_error or \
sys.version_info[:2] < (2, 7):
if sys.version_info[:2] < (2, 7):
self.add_message(
'E1320', node=inferred, args=inferred.value
)
Expand Down Expand Up @@ -212,7 +194,6 @@ class StringLiteralChecker(BaseTokenChecker):
'''
Check string literals
'''
__implements__ = (ITokenChecker, IRawChecker)
name = 'string_literal'
msgs = STRING_LITERALS_MSGS

Expand Down
14 changes: 1 addition & 13 deletions saltpylint/thirdparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import astroid.exceptions
import pkgutil
from astroid.modutils import is_relative, is_standard_module
from pylint.interfaces import IAstroidChecker
from saltpylint.checkers import BaseChecker, utils

MSGS = {
Expand All @@ -49,8 +48,6 @@ def get_import_package(modname):

class ThirdPartyImportsChecker(BaseChecker):

__implements__ = IAstroidChecker

name = '3rd-party-imports'
msgs = MSGS
priority = -2
Expand Down Expand Up @@ -83,46 +80,37 @@ def __init__(self, linter=None):
self._inside_try_except = False
self._inside_funcdef = False
self._inside_if = False
self.cwd = self.allowed_3rd_party_modules = None
self.cwd = self.allowed_3rd_party_modules = []

def open(self):
super(ThirdPartyImportsChecker, self).open()
self.cwd = os.getcwd()
self.allowed_3rd_party_modules = set(self.config.allowed_3rd_party_modules) # pylint: disable=no-member

# pylint: disable=unused-argument
@utils.check_messages('3rd-party-imports')
def visit_if(self, node):
self._inside_if = True

@utils.check_messages('3rd-party-imports')
def leave_if(self, node):
self._inside_if = True

@utils.check_messages('3rd-party-imports')
def visit_tryexcept(self, node):
self._inside_try_except = True

@utils.check_messages('3rd-party-imports')
def leave_tryexcept(self, node):
self._inside_try_except = False

@utils.check_messages('3rd-party-imports')
def visit_functiondef(self, node):
self._inside_funcdef = True

@utils.check_messages('3rd-party-imports')
def leave_functiondef(self, node):
self._inside_funcdef = False
# pylint: enable=unused-argument

@utils.check_messages('3rd-party-imports')
def visit_import(self, node):
names = [name for name, _ in node.names]
for name in names:
self._check_third_party_import(node, name)

@utils.check_messages('3rd-party-imports')
def visit_importfrom(self, node):
self._check_third_party_import(node, node.modname)

Expand Down

0 comments on commit 904a3a9

Please sign in to comment.