2016-03-18 20:54:07 +03:00
|
|
|
# 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
|
|
|
|
|
2016-06-02 22:38:36 +03:00
|
|
|
import argparse
|
2016-03-18 20:54:07 +03:00
|
|
|
import os
|
|
|
|
|
|
|
|
from mozbuild.base import (
|
|
|
|
MachCommandBase,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
from mach.decorators import (
|
|
|
|
CommandArgument,
|
|
|
|
CommandProvider,
|
|
|
|
Command,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
here = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
|
|
|
|
|
2016-06-24 21:06:22 +03:00
|
|
|
def setup_argument_parser():
|
|
|
|
from mozlint import cli
|
|
|
|
return cli.MozlintParser()
|
|
|
|
|
|
|
|
|
2016-03-18 20:54:07 +03:00
|
|
|
@CommandProvider
|
|
|
|
class MachCommands(MachCommandBase):
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
'lint', category='devenv',
|
2016-06-24 21:06:22 +03:00
|
|
|
description='Run linters.',
|
|
|
|
parser=setup_argument_parser)
|
2016-06-24 21:09:58 +03:00
|
|
|
def lint(self, *runargs, **lintargs):
|
2016-03-18 20:54:07 +03:00
|
|
|
"""Run linters."""
|
2016-06-24 21:06:22 +03:00
|
|
|
from mozlint import cli
|
2016-05-06 00:21:12 +03:00
|
|
|
lintargs['exclude'] = ['obj*']
|
2016-06-24 21:06:22 +03:00
|
|
|
cli.SEARCH_PATHS.append(here)
|
2016-06-24 21:09:58 +03:00
|
|
|
return cli.run(*runargs, **lintargs)
|
2016-06-02 22:38:36 +03:00
|
|
|
|
|
|
|
@Command('eslint', category='devenv',
|
|
|
|
description='Run eslint or help configure eslint for optimal development.')
|
2016-08-30 21:28:56 +03:00
|
|
|
@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.")
|
2016-06-02 22:38:36 +03:00
|
|
|
@CommandArgument('-s', '--setup', default=False, action='store_true',
|
2016-07-23 02:18:58 +03:00
|
|
|
help='Configure eslint for optimal development.')
|
2016-06-02 22:38:36 +03:00
|
|
|
@CommandArgument('-b', '--binary', default=None,
|
|
|
|
help='Path to eslint binary.')
|
2016-08-04 02:18:55 +03:00
|
|
|
@CommandArgument('--fix', default=False, action='store_true',
|
|
|
|
help='Request that eslint automatically fix errors, where possible.')
|
2016-08-30 21:28:56 +03:00
|
|
|
@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)
|