--- a/tools/lint/mach_commands.py
+++ b/tools/lint/mach_commands.py
@@ -11,16 +11,17 @@ import os
import platform
import subprocess
import sys
import which
from distutils.version import LooseVersion
from mozbuild.base import (
MachCommandBase,
+ MachCommandConditions as conditions,
)
from mach.decorators import (
CommandArgument,
CommandProvider,
Command,
SubCommand,
@@ -65,36 +66,45 @@ Valid installation paths:
@CommandProvider
class MachCommands(MachCommandBase):
@Command(
'lint', category='devenv',
description='Run linters.')
@CommandArgument(
- 'paths', nargs='*', default=None,
+ 'paths', nargs='*', default=[],
help="Paths to file or directories to lint, like "
"'browser/components/loop' or 'mobile/android'. "
"Defaults to the current directory if not given.")
@CommandArgument(
'-l', '--linter', dest='linters', default=None, action='append',
help="Linters to run, e.g 'eslint'. By default all linters are run "
"for all the appropriate files.")
@CommandArgument(
'-f', '--format', dest='fmt', default='stylish',
help="Formatter to use. Defaults to 'stylish'.")
@CommandArgument(
'-n', '--no-filter', dest='use_filters', default=True, action='store_false',
help="Ignore all filtering. This is useful for quickly testing a "
"directory that otherwise wouldn't be run, without needing to "
"modify the config file.")
- def lint(self, paths, linters=None, fmt='stylish', **lintargs):
+ @CommandArgument(
+ '-r', '--rev', dest='rev', default=None,
+ help="Only lint files touched by the given revision(s). This is either "
+ "forwarded to `hg log -T {files} -r` or `git diff --name-only`.")
+ def lint(self, paths, linters, fmt, rev, **lintargs):
"""Run linters."""
from mozlint import LintRoller, formatters
+ if rev and conditions.is_hg(self):
+ paths.extend(subprocess.check_output(['hg', 'log', '-T={files}', '-r', rev]).split())
+ elif rev and conditions.is_git(self):
+ paths.extend(subprocess.check_output(['git', 'status', '--names-only', rev]).split())
+ pass
paths = paths or ['.']
lint_files = self.find_linters(linters)
lintargs['exclude'] = ['obj*']
lint = LintRoller(**lintargs)
lint.read(lint_files)