diff options
author | Michal Minar <miminar@redhat.com> | 2013-01-24 12:46:34 +0100 |
---|---|---|
committer | Michal Minar <miminar@redhat.com> | 2013-01-24 12:46:34 +0100 |
commit | ac4b92c339a8db0634637360cdc8637e9223f457 (patch) | |
tree | 31462cd13ab01c3fc2fc15fa9ad61caf2e134946 /tools/pylint | |
parent | a245eb3990843d24a30180c836602c265c71a709 (diff) | |
download | openlmi-providers-ac4b92c339a8db0634637360cdc8637e9223f457.tar.gz openlmi-providers-ac4b92c339a8db0634637360cdc8637e9223f457.tar.xz openlmi-providers-ac4b92c339a8db0634637360cdc8637e9223f457.zip |
made pylint more friendly
supressed:
* too short variable names (allowed 2 chars long)
* use of * and ** magic
* warnings about hierarchically nested classes under Values
* get_providers not required for each provider module
* too long method names
made 'i' a dummy variable
Diffstat (limited to 'tools/pylint')
-rw-r--r-- | tools/pylint/plugins/cim_provider_checker.py | 59 | ||||
-rw-r--r-- | tools/pylint/pylintrc | 8 |
2 files changed, 38 insertions, 29 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): """ diff --git a/tools/pylint/pylintrc b/tools/pylint/pylintrc index 45a25ea..b557774 100644 --- a/tools/pylint/pylintrc +++ b/tools/pylint/pylintrc @@ -33,7 +33,7 @@ load-plugins=unittest_checker,cim_provider_checker,allow_cmpi_logging # can either give multiple identifier separated by comma (,) or put this option # multiple time (only on the command line, not in the configuration file where # it should appear only once). -disable=I0011 +disable=I0011, W0142 [REPORTS] @@ -72,7 +72,7 @@ init-import=no # A regular expression matching the beginning of the name of dummy variables # (i.e. not used). -dummy-variables-rgx=_|dummy +dummy-variables-rgx=_|dummy|i # List of additional names supposed to be defined in builtins. Remember that # you should avoid to define new builtins when possible. @@ -125,7 +125,7 @@ class-rgx=(([A-Z_][a-zA-Z0-9]+)|([A-Z][a-zA-Z]*_[A-Z][a-zA-Z0-9]*))$ function-rgx=[a-z_][a-z0-9_]{2,30}$ # Regular expression which should only match correct method names -method-rgx=[a-z_][a-z0-9_]{2,30}$ +method-rgx=[a-z_][a-z0-9_]{2,49}$ # Regular expression which should only match correct instance attribute names attr-rgx=[a-z_][a-z0-9_]{2,30}$ @@ -134,7 +134,7 @@ attr-rgx=[a-z_][a-z0-9_]{2,30}$ argument-rgx=[a-z_][a-z0-9_]{2,30}$ # Regular expression which should only match correct variable names -variable-rgx=[a-z_][a-z0-9_]{2,30}$ +variable-rgx=[a-z_][a-z0-9_]{1,30}$ # Regular expression which should only match correct list comprehension / # generator expression variable names |