@@ -20,6 +20,28 @@ class PylintHelper(cli.CLIHelper):
2020
2121 _RCFILE_NAME = '.pylintrc'
2222
23+ def _GetVersion (self ):
24+ """Retrieves the pylint version.
25+
26+ Returns:
27+ tuple[int]: pylint version as a tuple of integers or (0, 0, 0) if
28+ not available.
29+ """
30+ version_tuple = (0 , 0 , 0 )
31+
32+ exit_code , output , _ = self .RunCommand ('pylint --version' )
33+ if exit_code == 0 :
34+ for line in output .split ('\n ' ):
35+ if line .startswith ('pylint ' ):
36+ _ , _ , version = line .partition (' ' )
37+ # Remove a trailing comma.
38+ version , _ , _ = version .partition (',' )
39+
40+ version_tuple = tuple ([
41+ int (digit , 10 ) for digit in version .split ('.' )])
42+
43+ return version_tuple
44+
2345 def CheckFiles (self , filenames , rcfile ):
2446 """Checks if the linting of the files is correct using pylint.
2547
@@ -30,12 +52,22 @@ def CheckFiles(self, filenames, rcfile):
3052 Returns:
3153 bool: True if the files were linted without errors.
3254 """
55+ version_tuple = self ._GetVersion ()
56+
3357 print ('Running linter on changed files.' )
3458 failed_filenames = []
3559 for filename in filenames :
3660 print ('Checking: {0:s}' .format (filename ))
3761
3862 command = 'pylint --rcfile="{0:s}" {1:s}' .format (rcfile , filename )
63+ # For now disable pylint 2.1.1 and later specific checks.
64+ if version_tuple >= (2 , 1 , 1 ):
65+ additional_checks = [
66+ 'assignment-from-none' , 'chained-comparison' ,
67+ 'useless-object-inheritance' ]
68+ command = '{0:s} --disable={1:s}' .format (
69+ command , ',' .join (additional_checks ))
70+
3971 exit_code = subprocess .call (command , shell = True )
4072 if exit_code != 0 :
4173 failed_filenames .append (filename )
@@ -53,19 +85,7 @@ def CheckUpToDateVersion(self):
5385 Returns:
5486 bool: True if the pylint version is up to date.
5587 """
56- exit_code , output , _ = self .RunCommand ('pylint --version' )
57- if exit_code != 0 :
58- return False
59-
60- version_tuple = (0 , 0 , 0 )
61- for line in output .split ('\n ' ):
62- if line .startswith ('pylint ' ):
63- _ , _ , version = line .partition (' ' )
64- # Remove a trailing comma.
65- version , _ , _ = version .partition (',' )
66-
67- version_tuple = tuple ([int (digit , 10 ) for digit in version .split ('.' )])
68-
88+ version_tuple = self ._GetVersion ()
6989 return version_tuple >= self ._MINIMUM_VERSION_TUPLE
7090
7191 def GetRCFile (self , project_path ):
0 commit comments