Bug 1743088 - Mozlint: add an option to run the linter on third party code r=linter-reviewers,ahal DONTBUILD

Differential Revision: https://phabricator.services.mozilla.com/D132234
This commit is contained in:
Sylvestre Ledru 2021-12-01 15:12:31 +00:00
Родитель f237aae352
Коммит 6ce7d233c4
3 изменённых файлов: 22 добавлений и 2 удалений

Просмотреть файл

@ -82,6 +82,15 @@ class MozlintParser(ArgumentParser):
"without needing to modify the config file.",
},
],
[
["--include-third-party"],
{
"dest": "include_third-party",
"default": False,
"action": "store_true",
"help": "Also run the linter(s) on third-party code",
},
],
[
["-o", "--outgoing"],
{

Просмотреть файл

@ -60,6 +60,11 @@ def _run_worker(config, paths, **lintargs):
):
lintargs["show_warnings"] = True
# Override ignore thirdparty
# Only deactivating include_thirdparty is set on a linter.yml in use
if config.get("include_thirdparty", False):
lintargs["include_thirdparty"] = True
func = supported_types[config["type"]]
start_time = time.time()
try:

Просмотреть файл

@ -41,9 +41,10 @@ def setup_argument_parser():
return cli.MozlintParser()
def get_global_excludes(topsrcdir):
def get_global_excludes(**lintargs):
# exclude misc paths
excludes = GLOBAL_EXCLUDES[:]
topsrcdir = lintargs["root"]
# exclude top level paths that look like objdirs
excludes.extend(
@ -54,6 +55,11 @@ def get_global_excludes(topsrcdir):
]
)
if lintargs.get("include_thirdparty"):
# For some linters, we want to include the thirdparty code too.
# Example: trojan-source linter should run also on third party code.
return excludes
for path in EXCLUSION_FILES + EXCLUSION_FILES_OPTIONAL:
with open(os.path.join(topsrcdir, path), "r") as fh:
excludes.extend([f.strip() for f in fh.readlines()])
@ -82,7 +88,7 @@ def lint(command_context, *runargs, **lintargs):
pass
lintargs.setdefault("root", command_context.topsrcdir)
lintargs["exclude"] = get_global_excludes(lintargs["root"])
lintargs["exclude"] = get_global_excludes(**lintargs)
lintargs["config_paths"].insert(0, here)
lintargs["virtualenv_bin_path"] = command_context.virtualenv_manager.bin_path
lintargs["virtualenv_manager"] = command_context.virtualenv_manager