Bug 1869405 - mach commlint should not use unconfigured linters. r=dandarnell

This change will ensure that `mach commlint` only presents linters with config
files in /comm/tools/lint as valid. There is no fallback to using configs in
/tools/lint.

Originally mach commlint was set up to use linter config files from /tools/lint
(mozilla-central) as a fallback when a linter had no file in /comm/tools/lint.

Thunderbird's needs have evolved since, and using linter configs from gecko cause
more problems than useful feedback, mostly due to missing path excludes.

Differential Revision: https://phabricator.services.mozilla.com/D196197

--HG--
extra : amend_source : 57490f4ed2869df09ee834586cde6d5a3aa7419d
extra : histedit_source : 5244b076909ee856b240a88fac334df6d2f5a7bd
This commit is contained in:
Rob Lemley 2023-12-12 11:16:29 -05:00
Родитель 14eec52348
Коммит 9e2790ddf3
3 изменённых файлов: 66 добавлений и 31 удалений

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

@ -33,9 +33,8 @@ codespell:
tier: 2
run:
mach: >
lint -v -l codespell -f treeherder
commlint -v -l codespell -f treeherder
-f json:/builds/worker/mozlint.json
--config-path=comm/tools/lint
comm/*
optimization:
skip-unless-mozlint:
@ -70,9 +69,8 @@ file-perm:
tier: 2
run:
mach: >
lint -v -l file-perm -f treeherder
commlint -v -l file-perm -f treeherder
-f json:/builds/worker/mozlint.json
--config-path=comm/tools/lint
comm/*
optimization:
skip-unless-mozlint:
@ -89,9 +87,8 @@ file-whitespace:
tier: 2
run:
mach: >
lint -v -l file-whitespace -f treeherder
commlint -v -l file-whitespace -f treeherder
-f json:/builds/worker/mozlint.json
--config-path=comm/tools/lint
comm/*
optimization:
skip-unless-mozlint:
@ -104,9 +101,8 @@ fluent-lint:
symbol: l10n(fluent)
run:
mach: >
lint -l fluent-lint -f treeherder
commlint -l fluent-lint -f treeherder
-f json:/builds/worker/mozlint.json
--config-path=comm/tools/lint
comm/*
optimization:
skip-unless-mozlint:
@ -119,9 +115,8 @@ license:
symbol: pedantic(license)
run:
mach: >
lint -v -l license -f treeherder
commlint -v -l license -f treeherder
-f json:/builds/worker/mozlint.json
--config-path=comm/tools/lint
comm/*
optimization:
skip-unless-mozlint:
@ -136,9 +131,8 @@ l10n-conflicts:
run-on-projects: []
run:
mach: >
lint -W -l l10n -f treeherder
commlint -W -l l10n -f treeherder
-f json:/builds/worker/mozlint.json
--config-path=comm/tools/lint
comm/*
optimization:
skip-unless-mozlint:
@ -151,8 +145,7 @@ localization:
symbol: l10n(l1nt)
run:
mach: >
lint -v -l l10n -f treeherder
--config-path=comm/tools/lint
commlint -v -l l10n -f treeherder
comm/*
attributes:
code-review: false
@ -167,9 +160,8 @@ lintpref:
symbol: misc(pref)
run:
mach: >
lint -v -l lintpref -f treeherder
commlint -v -l lintpref -f treeherder
-f json:/builds/worker/mozlint.json
--config-path=comm/tools/lint
comm/*
optimization:
skip-unless-mozlint:
@ -182,9 +174,8 @@ mingw-cap:
symbol: misc(mingw)
run:
mach: >
lint -v -l mingw-capitalization -f treeherder
commlint -v -l mingw-capitalization -f treeherder
-f json:/builds/worker/mozlint.json
--config-path=comm/tools/lint
comm/*
optimization:
skip-unless-mozlint:
@ -197,9 +188,8 @@ py-black:
symbol: py(black)
run:
mach: >
lint -v -l black -f treeherder
commlint -v -l black -f treeherder
-f json:/builds/worker/mozlint.json
--config-path=comm/tools/lint
comm/*
optimization:
skip-unless-mozlint:
@ -227,9 +217,8 @@ shellcheck:
run-on-projects: []
run:
mach: >
lint -v -l shellcheck -f treeherder
commlint -v -l shellcheck -f treeherder
-f json:/builds/worker/mozlint.json
--config-path=comm/tools/lint
comm/*
optimization:
skip-unless-mozlint:
@ -260,9 +249,8 @@ trojan-source:
symbol: misc(trojan-source)
run:
mach: >
lint -v -l trojan-source -f treeherder
commlint -v -l trojan-source -f treeherder
-f json:/builds/worker/mozlint.json
--config-path=comm/tools/lint
comm/*
optimization:
skip-unless-mozlint:
@ -275,9 +263,8 @@ yaml:
symbol: pedantic(yaml)
run:
mach: >
lint -v -l yaml -f treeherder
commlint -v -l yaml -f treeherder
-f json:/builds/worker/mozlint.json
--config-path=comm/tools/lint
comm/mail/config
comm/taskcluster
comm/.*.yml

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

@ -2,7 +2,16 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import copy
import os
import sys
from mozfile import load_source
from mach.decorators import Command
from mozbuild.base import BuildEnvironmentNotFoundException
HERE = os.path.abspath(os.path.dirname(__file__))
def setup_argument_parser():
@ -16,9 +25,44 @@ def setup_argument_parser():
category="thunderbird",
description="Run linters with Thunderbird configurations.",
parser=setup_argument_parser,
virtualenv_name="lint",
)
def commlint(command_context, paths, extra_args=[], **kwargs):
kwargs["config_paths"].insert(0, "comm/tools/lint")
return command_context._mach_context.commands.dispatch(
"lint", command_context._mach_context, paths=paths, argv=extra_args, **kwargs
def lint(command_context, *runargs, **lintargs):
"""Run linters."""
command_context.activate_virtualenv()
mach_lint = load_source(
"mach_lint", os.path.join(command_context.topsrcdir, "tools/lint/mach_commands.py")
)
from mozlint import cli, parser
try:
buildargs = {}
buildargs["substs"] = copy.deepcopy(dict(command_context.substs))
buildargs["defines"] = copy.deepcopy(dict(command_context.defines))
buildargs["topobjdir"] = command_context.topobjdir
lintargs.update(buildargs)
except BuildEnvironmentNotFoundException:
pass
lintargs.setdefault("root", command_context.topsrcdir)
if lintargs["extra_args"] is None:
lintargs["extra_args"] = []
lintargs["exclude"] = mach_lint.get_global_excludes(**lintargs)
# Add the linter code from gecko to sys.path. Normally handled by "config_paths"
sys.path.insert(0, mach_lint.here)
lintargs["config_paths"].insert(0, HERE)
lintargs["virtualenv_bin_path"] = command_context.virtualenv_manager.bin_path
lintargs["virtualenv_manager"] = command_context.virtualenv_manager
if mach_lint.REPORT_WARNINGS and lintargs.get("show_warnings") is None:
lintargs["show_warnings"] = "soft"
for path in mach_lint.EXCLUSION_FILES:
parser.GLOBAL_SUPPORT_FILES.append(os.path.join(command_context.topsrcdir, path))
setupargs = {
"mach_command_context": command_context,
}
return cli.run(*runargs, setupargs=setupargs, **lintargs)

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

@ -2,7 +2,11 @@
yamllint:
description: YAML linter
include:
- comm/
- comm/mail/config
- comm/taskcluster
- comm/.cron.yml
- comm/.gecko_rev.yml
- comm/.taskcluster.yml
extensions: ['yml', 'yaml']
support-files:
- '**/.yamllint'