lint: Combine functions in custom_rules into RuleList class.

This makes linting rules in zulint more general. Make necessary
changes in tools/lint and tools/custom_check.py to run with the new
RuleList class.

Modify tests for `RuleList` class. Tests only include minor changes to
test with the new class.
This commit is contained in:
Aman Agrawal
2019-05-30 21:11:23 +05:30
committed by Tim Abbott
parent fd25ced43c
commit db25c0c2ca
4 changed files with 507 additions and 493 deletions

View File

@@ -10,6 +10,7 @@ import argparse
from lib import sanity_check
sanity_check.check_venv(__file__)
from linter_lib.custom_check import python_rules, non_py_rules
from zulint import lister
from zulint.command import add_default_linter_arguments, LinterConfig
from typing import cast, Dict, List
@@ -44,7 +45,6 @@ def run():
root_dir = os.path.dirname(tools_dir)
sys.path.insert(0, root_dir)
from tools.linter_lib.custom_check import build_custom_checkers
from tools.linter_lib.exclude import EXCLUDED_FILES, PUPPET_CHECK_RULES_TO_EXCLUDE
from tools.linter_lib.pyflakes import check_pyflakes
from tools.linter_lib.pep8 import check_pep8
@@ -85,8 +85,6 @@ def run():
else:
logger.setLevel(logging.WARNING)
check_custom_checks_py, check_custom_checks_nonpy = build_custom_checkers(by_lang)
linter_config = LinterConfig(by_lang)
linter_config.external_linter('add_class', ['tools/find-add-class'], ['js'])
linter_config.external_linter('css', ['node', 'node_modules/.bin/stylelint'], ['css', 'scss'])
@@ -111,13 +109,15 @@ def run():
@linter_config.lint
def custom_py():
# type: () -> int
failed = check_custom_checks_py()
failed = python_rules.check(by_lang)
return 1 if failed else 0
@linter_config.lint
def custom_nonpy():
# type: () -> int
failed = check_custom_checks_nonpy()
failed = False
for rule in non_py_rules:
failed = failed or rule.check(by_lang)
return 1 if failed else 0
@linter_config.lint