From 766abaa1a3a90df6b4d8bea26e0c22d94db66424 Mon Sep 17 00:00:00 2001 From: Tommy Ip Date: Thu, 6 Jul 2017 12:48:26 +0800 Subject: [PATCH] linter: Update external_linter visual output. --- tools/lint | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/tools/lint b/tools/lint index 5f32d7656f..e17ec1722c 100755 --- a/tools/lint +++ b/tools/lint @@ -8,6 +8,8 @@ import sys import optparse import subprocess +from linter_lib.printer import print_err, colors + # check for the venv from lib import sanity_check sanity_check.check_venv(__file__) @@ -128,14 +130,29 @@ def run(): If target_langs is empty, just runs the linter unconditionally. """ + color = next(colors) + def run_linter(): # type: () -> int - if len(target_langs) == 0: - return subprocess.call(command) - targets = [target for lang in target_langs for target in by_lang[lang]] - if len(targets) == 0: - return 0 - return subprocess.call(command + targets) + targets = [] # type: List[str] + if len(target_langs) != 0: + targets = [target for lang in target_langs for target in by_lang[lang]] + if len(targets) == 0: + # If we this linter has a list of languages, and + # no files in those languages are to be checked, + # then we can safely return success without + # invoking the external linter. + return 0 + + p = subprocess.Popen(command + targets, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + + for line in iter(p.stdout.readline, b''): + print_err(name, color, line) + + return p.wait() # Linter exit code + lint_functions[name] = run_linter with bright_red_output():