mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-08 20:28:42 +02:00
This integrates 'eslint' with the mozlint framework. The old |mach eslint| command is kept around
for backwards compatibility and will simply dispatch to |mach lint|. But |mach lint| should be
preferred as the old command may eventually be removed.
The old |mach eslint| command should be mostly backwards compatible with a few exceptions:
1. Can no longer define --extensions on the command line, this is instead hardcoded into
eslint.lint.
2. No longer using eslint formatters. However, the default mozlint formatter should be
identical to the default eslint formatter, so developers should not notice a change.
This does mean that non-default eslint formatters can no longer be used unless a mozlint
copy of them is created.
3. Installs dependencies automatically without prompting the user. This was necessary due to
python multiprocessing limitations, but is actually also a better UX. Because the npm
dependencies aren't global anymore, there isn't really any reason *not* to install them
automatically.
Apart from that, any difference from the old |mach eslint| I'd consider a bug.
The main eslint implementation now lives in tools/lint/eslint.lint instead of
tools/lint/mach_commands.py.
MozReview-Commit-ID: KYhC6SEySC3
--HG--
extra : rebase_source : 36d06b1a3fced764e17154cc53091d7722919b67
60 lines
2.1 KiB
Python
60 lines
2.1 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/.
|
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
import argparse
|
|
import os
|
|
|
|
from mozbuild.base import (
|
|
MachCommandBase,
|
|
)
|
|
|
|
|
|
from mach.decorators import (
|
|
CommandArgument,
|
|
CommandProvider,
|
|
Command,
|
|
)
|
|
|
|
|
|
here = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
|
|
def setup_argument_parser():
|
|
from mozlint import cli
|
|
return cli.MozlintParser()
|
|
|
|
|
|
@CommandProvider
|
|
class MachCommands(MachCommandBase):
|
|
|
|
@Command(
|
|
'lint', category='devenv',
|
|
description='Run linters.',
|
|
parser=setup_argument_parser)
|
|
def lint(self, *runargs, **lintargs):
|
|
"""Run linters."""
|
|
from mozlint import cli
|
|
lintargs['exclude'] = ['obj*']
|
|
cli.SEARCH_PATHS.append(here)
|
|
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/components/loop' 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(self, paths, **kwargs):
|
|
self._mach_context.commands.dispatch('lint', self._mach_context,
|
|
linters=['eslint'], paths=paths, **kwargs)
|