gecko-dev/tools/lint/mach_commands.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

170 строки
4.7 KiB
Python
Исходник Обычный вид История

# This Source Code Form is subject to the terms of the Mozilla Public
# 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/.
Bug 1271734 - Move all eslint related infrastructure to tools/lint, r=miker This commit simply moves 'testing/eslint' to 'tools/lint/eslint' and the eslint related mach command from 'python/mach_commands.py' to 'tools/lint/mach_commands.py'. It shouldn't have any functional change on running eslint, either through mach or taskcluster. This is in preparation for bug 1258341, to make the diffs there a little easier to read. MozReview-Commit-ID: K03sn9lv9Lv --HG-- rename : testing/eslint/eslint-plugin-mozilla/LICENSE => tools/lint/eslint/eslint-plugin-mozilla/LICENSE rename : testing/eslint/eslint-plugin-mozilla/docs/balanced-listeners.rst => tools/lint/eslint/eslint-plugin-mozilla/docs/balanced-listeners.rst rename : testing/eslint/eslint-plugin-mozilla/docs/import-browserjs-globals.rst => tools/lint/eslint/eslint-plugin-mozilla/docs/import-browserjs-globals.rst rename : testing/eslint/eslint-plugin-mozilla/docs/import-globals.rst => tools/lint/eslint/eslint-plugin-mozilla/docs/import-globals.rst rename : testing/eslint/eslint-plugin-mozilla/docs/import-headjs-globals.rst => tools/lint/eslint/eslint-plugin-mozilla/docs/import-headjs-globals.rst rename : testing/eslint/eslint-plugin-mozilla/docs/index.rst => tools/lint/eslint/eslint-plugin-mozilla/docs/index.rst rename : testing/eslint/eslint-plugin-mozilla/docs/mark-test-function-used.rst => tools/lint/eslint/eslint-plugin-mozilla/docs/mark-test-function-used.rst rename : testing/eslint/eslint-plugin-mozilla/docs/no-aArgs.rst => tools/lint/eslint/eslint-plugin-mozilla/docs/no-aArgs.rst rename : testing/eslint/eslint-plugin-mozilla/docs/no-cpows-in-tests.rst => tools/lint/eslint/eslint-plugin-mozilla/docs/no-cpows-in-tests.rst rename : testing/eslint/eslint-plugin-mozilla/docs/reject-importGlobalProperties.rst => tools/lint/eslint/eslint-plugin-mozilla/docs/reject-importGlobalProperties.rst rename : testing/eslint/eslint-plugin-mozilla/docs/var-only-at-top-level.rst => tools/lint/eslint/eslint-plugin-mozilla/docs/var-only-at-top-level.rst rename : testing/eslint/eslint-plugin-mozilla/lib/globals.js => tools/lint/eslint/eslint-plugin-mozilla/lib/globals.js rename : testing/eslint/eslint-plugin-mozilla/lib/helpers.js => tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js rename : testing/eslint/eslint-plugin-mozilla/lib/index.js => tools/lint/eslint/eslint-plugin-mozilla/lib/index.js rename : testing/eslint/eslint-plugin-mozilla/lib/processors/xbl-bindings.js => tools/lint/eslint/eslint-plugin-mozilla/lib/processors/xbl-bindings.js rename : testing/eslint/eslint-plugin-mozilla/lib/rules/.eslintrc => tools/lint/eslint/eslint-plugin-mozilla/lib/rules/.eslintrc rename : testing/eslint/eslint-plugin-mozilla/lib/rules/balanced-listeners.js => tools/lint/eslint/eslint-plugin-mozilla/lib/rules/balanced-listeners.js rename : testing/eslint/eslint-plugin-mozilla/lib/rules/import-browserjs-globals.js => tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-browserjs-globals.js rename : testing/eslint/eslint-plugin-mozilla/lib/rules/import-globals.js => tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-globals.js rename : testing/eslint/eslint-plugin-mozilla/lib/rules/import-headjs-globals.js => tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-headjs-globals.js rename : testing/eslint/eslint-plugin-mozilla/lib/rules/mark-test-function-used.js => tools/lint/eslint/eslint-plugin-mozilla/lib/rules/mark-test-function-used.js rename : testing/eslint/eslint-plugin-mozilla/lib/rules/no-aArgs.js => tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-aArgs.js rename : testing/eslint/eslint-plugin-mozilla/lib/rules/no-cpows-in-tests.js => tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-cpows-in-tests.js rename : testing/eslint/eslint-plugin-mozilla/lib/rules/reject-importGlobalProperties.js => tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-importGlobalProperties.js rename : testing/eslint/eslint-plugin-mozilla/lib/rules/var-only-at-top-level.js => tools/lint/eslint/eslint-plugin-mozilla/lib/rules/var-only-at-top-level.js rename : testing/eslint/eslint-plugin-mozilla/moz.build => tools/lint/eslint/eslint-plugin-mozilla/moz.build rename : testing/eslint/eslint-plugin-mozilla/package.json => tools/lint/eslint/eslint-plugin-mozilla/package.json rename : testing/eslint/manifest.tt => tools/lint/eslint/manifest.tt rename : testing/eslint/npm-shrinkwrap.json => tools/lint/eslint/npm-shrinkwrap.json rename : testing/eslint/package.json => tools/lint/eslint/package.json rename : testing/eslint/update => tools/lint/eslint/update extra : rebase_source : bb44b6285acf4625079cb6a3aaca7d9ada778c3a
2016-06-02 22:38:36 +03:00
import argparse
import copy
import os
from mozbuild.base import (
BuildEnvironmentNotFoundException,
MachCommandConditions as conditions,
)
from mach.decorators import (
CommandArgument,
Command,
)
here = os.path.abspath(os.path.dirname(__file__))
EXCLUSION_FILES = [
os.path.join("tools", "rewriting", "Generated.txt"),
os.path.join("tools", "rewriting", "ThirdPartyPaths.txt"),
]
EXCLUSION_FILES_OPTIONAL = []
thunderbird_excludes = os.path.join("comm", "tools", "lint", "GlobalExclude.txt")
if os.path.exists(thunderbird_excludes):
EXCLUSION_FILES_OPTIONAL.append(thunderbird_excludes)
GLOBAL_EXCLUDES = ["node_modules", "tools/lint/test/files", ".hg", ".git"]
VALID_FORMATTERS = {"black", "clang-format", "rustfmt"}
VALID_ANDROID_FORMATTERS = {"android-format"}
def setup_argument_parser():
from mozlint import cli
return cli.MozlintParser()
def get_global_excludes(topsrcdir):
# exclude misc paths
excludes = GLOBAL_EXCLUDES[:]
# exclude top level paths that look like objdirs
excludes.extend(
[
name
for name in os.listdir(topsrcdir)
if name.startswith("obj") and os.path.isdir(name)
]
)
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()])
return excludes
@Command(
"lint",
category="devenv",
description="Run linters.",
parser=setup_argument_parser,
)
def lint(command_context, *runargs, **lintargs):
"""Run linters."""
command_context.activate_virtualenv()
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)
lintargs["exclude"] = get_global_excludes(lintargs["root"])
lintargs["config_paths"].insert(0, here)
lintargs["virtualenv_bin_path"] = command_context.virtualenv_manager.bin_path
lintargs["virtualenv_manager"] = command_context.virtualenv_manager
for path in EXCLUSION_FILES:
parser.GLOBAL_SUPPORT_FILES.append(
os.path.join(command_context.topsrcdir, path)
)
return cli.run(*runargs, **lintargs)
@Command(
"eslint",
category="devenv",
description="Run eslint or help configure eslint for optimal development.",
)
@CommandArgument(
"paths",
default=None,
nargs="*",
help="Paths to file or directories to lint, like "
"'browser/' Defaults to the "
"current directory if not given.",
)
@CommandArgument(
"-s",
"--setup",
default=False,
action="store_true",
help="Configure eslint for optimal development.",
)
@CommandArgument("-b", "--binary", default=None, help="Path to eslint binary.")
@CommandArgument(
"--fix",
default=False,
action="store_true",
help="Request that eslint automatically fix errors, where possible.",
)
@CommandArgument(
"extra_args",
nargs=argparse.REMAINDER,
help="Extra args that will be forwarded to eslint.",
)
def eslint(command_context, paths, extra_args=[], **kwargs):
command_context._mach_context.commands.dispatch(
"lint",
command_context._mach_context,
linters=["eslint"],
paths=paths,
argv=extra_args,
**kwargs
)
@Command(
"format",
category="devenv",
description="Format files, alternative to 'lint --fix' ",
parser=setup_argument_parser,
)
def format_files(command_context, paths, extra_args=[], **kwargs):
linters = kwargs["linters"]
formatters = VALID_FORMATTERS
if conditions.is_android(command_context):
formatters |= VALID_ANDROID_FORMATTERS
if not linters:
linters = formatters
else:
invalid_linters = set(linters) - formatters
if invalid_linters:
print(
"error: One or more linters passed are not valid formatters. "
"Note that only the following linters are valid formatters:"
)
print("\n".join(sorted(formatters)))
return 1
Bug 1271734 - Move all eslint related infrastructure to tools/lint, r=miker This commit simply moves 'testing/eslint' to 'tools/lint/eslint' and the eslint related mach command from 'python/mach_commands.py' to 'tools/lint/mach_commands.py'. It shouldn't have any functional change on running eslint, either through mach or taskcluster. This is in preparation for bug 1258341, to make the diffs there a little easier to read. MozReview-Commit-ID: K03sn9lv9Lv --HG-- rename : testing/eslint/eslint-plugin-mozilla/LICENSE => tools/lint/eslint/eslint-plugin-mozilla/LICENSE rename : testing/eslint/eslint-plugin-mozilla/docs/balanced-listeners.rst => tools/lint/eslint/eslint-plugin-mozilla/docs/balanced-listeners.rst rename : testing/eslint/eslint-plugin-mozilla/docs/import-browserjs-globals.rst => tools/lint/eslint/eslint-plugin-mozilla/docs/import-browserjs-globals.rst rename : testing/eslint/eslint-plugin-mozilla/docs/import-globals.rst => tools/lint/eslint/eslint-plugin-mozilla/docs/import-globals.rst rename : testing/eslint/eslint-plugin-mozilla/docs/import-headjs-globals.rst => tools/lint/eslint/eslint-plugin-mozilla/docs/import-headjs-globals.rst rename : testing/eslint/eslint-plugin-mozilla/docs/index.rst => tools/lint/eslint/eslint-plugin-mozilla/docs/index.rst rename : testing/eslint/eslint-plugin-mozilla/docs/mark-test-function-used.rst => tools/lint/eslint/eslint-plugin-mozilla/docs/mark-test-function-used.rst rename : testing/eslint/eslint-plugin-mozilla/docs/no-aArgs.rst => tools/lint/eslint/eslint-plugin-mozilla/docs/no-aArgs.rst rename : testing/eslint/eslint-plugin-mozilla/docs/no-cpows-in-tests.rst => tools/lint/eslint/eslint-plugin-mozilla/docs/no-cpows-in-tests.rst rename : testing/eslint/eslint-plugin-mozilla/docs/reject-importGlobalProperties.rst => tools/lint/eslint/eslint-plugin-mozilla/docs/reject-importGlobalProperties.rst rename : testing/eslint/eslint-plugin-mozilla/docs/var-only-at-top-level.rst => tools/lint/eslint/eslint-plugin-mozilla/docs/var-only-at-top-level.rst rename : testing/eslint/eslint-plugin-mozilla/lib/globals.js => tools/lint/eslint/eslint-plugin-mozilla/lib/globals.js rename : testing/eslint/eslint-plugin-mozilla/lib/helpers.js => tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js rename : testing/eslint/eslint-plugin-mozilla/lib/index.js => tools/lint/eslint/eslint-plugin-mozilla/lib/index.js rename : testing/eslint/eslint-plugin-mozilla/lib/processors/xbl-bindings.js => tools/lint/eslint/eslint-plugin-mozilla/lib/processors/xbl-bindings.js rename : testing/eslint/eslint-plugin-mozilla/lib/rules/.eslintrc => tools/lint/eslint/eslint-plugin-mozilla/lib/rules/.eslintrc rename : testing/eslint/eslint-plugin-mozilla/lib/rules/balanced-listeners.js => tools/lint/eslint/eslint-plugin-mozilla/lib/rules/balanced-listeners.js rename : testing/eslint/eslint-plugin-mozilla/lib/rules/import-browserjs-globals.js => tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-browserjs-globals.js rename : testing/eslint/eslint-plugin-mozilla/lib/rules/import-globals.js => tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-globals.js rename : testing/eslint/eslint-plugin-mozilla/lib/rules/import-headjs-globals.js => tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-headjs-globals.js rename : testing/eslint/eslint-plugin-mozilla/lib/rules/mark-test-function-used.js => tools/lint/eslint/eslint-plugin-mozilla/lib/rules/mark-test-function-used.js rename : testing/eslint/eslint-plugin-mozilla/lib/rules/no-aArgs.js => tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-aArgs.js rename : testing/eslint/eslint-plugin-mozilla/lib/rules/no-cpows-in-tests.js => tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-cpows-in-tests.js rename : testing/eslint/eslint-plugin-mozilla/lib/rules/reject-importGlobalProperties.js => tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-importGlobalProperties.js rename : testing/eslint/eslint-plugin-mozilla/lib/rules/var-only-at-top-level.js => tools/lint/eslint/eslint-plugin-mozilla/lib/rules/var-only-at-top-level.js rename : testing/eslint/eslint-plugin-mozilla/moz.build => tools/lint/eslint/eslint-plugin-mozilla/moz.build rename : testing/eslint/eslint-plugin-mozilla/package.json => tools/lint/eslint/eslint-plugin-mozilla/package.json rename : testing/eslint/manifest.tt => tools/lint/eslint/manifest.tt rename : testing/eslint/npm-shrinkwrap.json => tools/lint/eslint/npm-shrinkwrap.json rename : testing/eslint/package.json => tools/lint/eslint/package.json rename : testing/eslint/update => tools/lint/eslint/update extra : rebase_source : bb44b6285acf4625079cb6a3aaca7d9ada778c3a
2016-06-02 22:38:36 +03:00
kwargs["linters"] = list(linters)
kwargs["fix"] = True
command_context._mach_context.commands.dispatch(
"lint", command_context._mach_context, paths=paths, argv=extra_args, **kwargs
)