mirror of https://github.com/zulip/zulip.git
tools: Extract build_custom_checkers() in tools/lint-all.
This commit is contained in:
parent
f955991120
commit
c6a888561a
|
@ -12,7 +12,7 @@ import traceback
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import lister
|
import lister
|
||||||
from typing import cast, Any, Callable, Dict, List, Optional, Generator
|
from typing import cast, Any, Callable, Dict, List, Optional, Generator, Tuple
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
print("ImportError: {}".format(e))
|
print("ImportError: {}".format(e))
|
||||||
print("You need to run the Zulip linters inside a Zulip dev environment.")
|
print("You need to run the Zulip linters inside a Zulip dev environment.")
|
||||||
|
@ -99,38 +99,8 @@ def run_parallel(lint_functions):
|
||||||
failed = True
|
failed = True
|
||||||
return failed
|
return failed
|
||||||
|
|
||||||
|
def build_custom_checkers(by_lang):
|
||||||
def run():
|
# type: (Dict[str, List[str]]) -> Tuple[Callable[[], bool], Callable[[], bool]]
|
||||||
# type: () -> None
|
|
||||||
parser = optparse.OptionParser()
|
|
||||||
parser.add_option('--full',
|
|
||||||
action='store_true',
|
|
||||||
help='Check some things we typically ignore')
|
|
||||||
parser.add_option('--modified', '-m',
|
|
||||||
action='store_true',
|
|
||||||
help='Only check modified files')
|
|
||||||
parser.add_option('--verbose', '-v',
|
|
||||||
action='store_true',
|
|
||||||
help='Print verbose timing output')
|
|
||||||
(options, args) = parser.parse_args()
|
|
||||||
|
|
||||||
os.chdir(os.path.join(os.path.dirname(__file__), '..'))
|
|
||||||
|
|
||||||
|
|
||||||
by_lang = cast(Dict[str, List[str]], lister.list_files(args, modified_only=options.modified,
|
|
||||||
ftypes=['py', 'sh', 'js', 'pp', 'css', 'handlebars', 'html', 'json', 'md', 'txt', 'text'],
|
|
||||||
use_shebang=True, group_by_ftype=True, exclude=EXCLUDED_FILES))
|
|
||||||
|
|
||||||
# Invoke the appropriate lint checker for each language,
|
|
||||||
# and also check files for extra whitespace.
|
|
||||||
|
|
||||||
logging.basicConfig(format="%(asctime)s %(message)s")
|
|
||||||
logger = logging.getLogger()
|
|
||||||
if options.verbose:
|
|
||||||
logger.setLevel(logging.INFO)
|
|
||||||
else:
|
|
||||||
logger.setLevel(logging.WARNING)
|
|
||||||
|
|
||||||
RuleList = List[Dict[str, Any]]
|
RuleList = List[Dict[str, Any]]
|
||||||
|
|
||||||
def custom_check_file(fn, rules, skip_rules=None, max_length=None):
|
def custom_check_file(fn, rules, skip_rules=None, max_length=None):
|
||||||
|
@ -400,6 +370,41 @@ def run():
|
||||||
|
|
||||||
return failed
|
return failed
|
||||||
|
|
||||||
|
return (check_custom_checks_py, check_custom_checks_nonpy)
|
||||||
|
|
||||||
|
def run():
|
||||||
|
# type: () -> None
|
||||||
|
parser = optparse.OptionParser()
|
||||||
|
parser.add_option('--full',
|
||||||
|
action='store_true',
|
||||||
|
help='Check some things we typically ignore')
|
||||||
|
parser.add_option('--modified', '-m',
|
||||||
|
action='store_true',
|
||||||
|
help='Only check modified files')
|
||||||
|
parser.add_option('--verbose', '-v',
|
||||||
|
action='store_true',
|
||||||
|
help='Print verbose timing output')
|
||||||
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
|
os.chdir(os.path.join(os.path.dirname(__file__), '..'))
|
||||||
|
|
||||||
|
|
||||||
|
by_lang = cast(Dict[str, List[str]], lister.list_files(args, modified_only=options.modified,
|
||||||
|
ftypes=['py', 'sh', 'js', 'pp', 'css', 'handlebars', 'html', 'json', 'md', 'txt', 'text'],
|
||||||
|
use_shebang=True, group_by_ftype=True, exclude=EXCLUDED_FILES))
|
||||||
|
|
||||||
|
# Invoke the appropriate lint checker for each language,
|
||||||
|
# and also check files for extra whitespace.
|
||||||
|
|
||||||
|
logging.basicConfig(format="%(asctime)s %(message)s")
|
||||||
|
logger = logging.getLogger()
|
||||||
|
if options.verbose:
|
||||||
|
logger.setLevel(logging.INFO)
|
||||||
|
else:
|
||||||
|
logger.setLevel(logging.WARNING)
|
||||||
|
|
||||||
|
check_custom_checks_py, check_custom_checks_nonpy = build_custom_checkers(by_lang)
|
||||||
|
|
||||||
lint_functions = {} # type: Dict[str, Callable[[], int]]
|
lint_functions = {} # type: Dict[str, Callable[[], int]]
|
||||||
|
|
||||||
def lint(func):
|
def lint(func):
|
||||||
|
|
Loading…
Reference in New Issue