diff options
Diffstat (limited to 'tools/pylint/plugins/cim_provider_checker.py')
-rw-r--r-- | tools/pylint/plugins/cim_provider_checker.py | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/tools/pylint/plugins/cim_provider_checker.py b/tools/pylint/plugins/cim_provider_checker.py index a1b557b..6dd09db 100644 --- a/tools/pylint/plugins/cim_provider_checker.py +++ b/tools/pylint/plugins/cim_provider_checker.py @@ -36,24 +36,37 @@ _RE_PROVIDER_MODULE_NAME = re.compile( _RE_COMMON_MODULE_NAME = re.compile( r'^([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+)$') +def recursively_clean_cls_values(linter, node): + """ + Values class under provider defines property values, under + nested classes that are popular target of pylint messages. Since + these are generated and known to any developper, we don't want + to be bothered by these warnings. + + Supress them for any nested class recursively. + """ + # class has too few public methods + linter.disable('R0903', scope='module', line=node.lineno) + # class has not docstring + linter.disable('C0111', scope='module', line=node.lineno) + for child in node.get_children(): + if isinstance(child, scoped_nodes.Class): + recursively_clean_cls_values(linter, child) + def supress_cim_provider_messages(linter, node): """ Supress some warnings for CIMProvider2 subclass. @param node is a subclass of CIMProvider2 """ assert isinstance(node, scoped_nodes.Class) + # class has too many public methods + linter.disable('R0904', scope='module', line=node.lineno) if '__init__' in node: - linter.disable('W0231', scope='module', - line=node['__init__'].lineno) + # __init__ not called for base class + linter.disable('W0231', scope='module', line=node['__init__'].lineno) if ( 'Values' in node and isinstance(node['Values'], scoped_nodes.Class)): - linter.disable('R0903', scope='module', line=node['Values'].lineno) - linter.disable('C0111', scope='module', line=node['Values'].lineno) - for child in node['Values'].get_children(): - if not isinstance(child, scoped_nodes.Class): - continue - linter.disable('R0903', scope='module', line=child.lineno) - linter.disable('C0111', scope='module', line=child.lineno) + recursively_clean_cls_values(linter, node['Values']) generated_methods = ( 'get_instance', @@ -84,8 +97,6 @@ class CIMProviderChecker(BaseChecker): "CamelCased strings."), 'C9906': ('Prefixes of module and class does not match: %s != %s', "Module prefix has to match provider class prefix."), - 'E9907': ("Missing get_providers function in module %s", - "Provider module must contain get_providers function."), 'W9908': ("get_providers in module %s is not a function", "get_providers should be a callable function."), 'W9909': ("Missing provider name \"%s\" in providers dictionary.", @@ -122,20 +133,18 @@ class CIMProviderChecker(BaseChecker): args=(modm.group('prefix'), clsm.group('prefix'))) if clsm and clsm.group('prefix') != 'LMI': self.add_message('C9910', node=node, args=clsm.group('prefix')) - if not 'get_providers' in parent.keys(): - self.add_message('E9907', node=parent, args=parent.name) - return - getprovs = parent['get_providers'] - if not isinstance(getprovs, scoped_nodes.Function): - self.add_message('W9908', node=getprovs, args=parent.name) - ret = getprovs.last_child() - if not isinstance(ret, node_classes.Return): - return - dictionary = ret.get_children().next() - if not isinstance(dictionary, node_classes.Dict): - return - if not node.name in [i[0].value for i in dictionary.items]: - self.add_message('W9909', node=getprovs, args=node.name) + if 'get_providers' in parent.keys(): + getprovs = parent['get_providers'] + if not isinstance(getprovs, scoped_nodes.Function): + self.add_message('W9908', node=getprovs, args=parent.name) + ret = getprovs.last_child() + if not isinstance(ret, node_classes.Return): + return + dictionary = ret.get_children().next() + if not isinstance(dictionary, node_classes.Dict): + return + if not node.name in [i[0].value for i in dictionary.items]: + self.add_message('W9909', node=getprovs, args=node.name) def visit_module(self, node): """ |