5656
5757__VERSION__ = '0.0.6.1'
5858
59+ ERROR = termcolor .colored ('ERROR' , 'red' , attrs = ('bold' ,))
60+ SKIPPED = termcolor .colored ('SKIPPED' , 'yellow' , attrs = ('bold' ,))
61+ OK = termcolor .colored ('OK' , 'green' , attrs = ('bold' ,))
62+
5963
6064def find_invalid_filenames (filenames , repository_root ):
6165 """Find files that does not exist, are not in the repo or are directories.
@@ -179,7 +183,7 @@ def main(argv, stdout=sys.stdout, stderr=sys.stderr):
179183 vcs , repository_root = get_vcs_root ()
180184
181185 if vcs is None :
182- stderr .write ('fatal: Not a git repository' + os . linesep )
186+ stderr .write ('fatal: Not a git repository' + linesep )
183187 return 128
184188
185189 commit = None
@@ -192,7 +196,7 @@ def main(argv, stdout=sys.stdout, stderr=sys.stderr):
192196 if invalid_filenames :
193197 invalid_filenames .append (('' , '' ))
194198 stderr .write (
195- os . linesep .join (invalid [1 ] for invalid in invalid_filenames ))
199+ linesep .join (invalid [1 ] for invalid in invalid_filenames ))
196200 return 2
197201
198202 changed_files = vcs .modified_files (repository_root ,
@@ -213,9 +217,6 @@ def main(argv, stdout=sys.stdout, stderr=sys.stderr):
213217 gitlint_config = get_config (repository_root )
214218 json_result = {}
215219
216- error = termcolor .colored ('ERROR' , 'red' , attrs = ('bold' ,))
217- skipped = termcolor .colored ('SKIPPED' , 'yellow' , attrs = ('bold' ,))
218-
219220 for filename in sorted (modified_files .keys ()):
220221 rel_filename = os .path .relpath (filename )
221222 if not json_output :
@@ -233,31 +234,30 @@ def main(argv, stdout=sys.stdout, stderr=sys.stderr):
233234 filename , modified_lines , gitlint_config )
234235 result = result [filename ]
235236
236- output = ''
237+ output_lines = []
237238 if result .get ('error' ):
238- output += os . linesep . join (
239- '%s: %s' % (error , reason ) for reason in result .get ('error' )
239+ output_lines . extend (
240+ '%s: %s' % (ERROR , reason ) for reason in result .get ('error' )
240241 )
241242 linter_not_found = True
242243 if result .get ('skipped' ):
243- output += os . linesep . join (
244- '%s: %s' % (skipped , reason ) for reason in result .get ('skipped' )
244+ output_lines . extend (
245+ '%s: %s' % (SKIPPED , reason ) for reason in result .get ('skipped' )
245246 )
246247 if result .get ('comments' , []) == []:
247- if not output :
248- output += termcolor . colored ( 'OK' , 'green' , attrs = ( 'bold' ,) )
248+ if not output_lines :
249+ output_lines . append ( OK )
249250 else :
250251 files_with_problems += 1
251- messages = []
252252 for data in result ['comments' ]:
253253 formatted_message = format_comment (data )
254- messages .append (formatted_message )
254+ output_lines .append (formatted_message )
255255 data ['formatted_message' ] = formatted_message
256- output += os .linesep .join (messages )
257256
258257 if json_output :
259258 json_result [filename ] = result
260259 else :
260+ output = linesep .join (output_lines )
261261 stdout .write (output )
262262 stdout .write (linesep + linesep )
263263
0 commit comments