Bug 1288432 - Use new mozlint configuration for eslint linter, r=standard8

MozReview-Commit-ID: HX0yA8U15Fw

--HG--
rename : tools/lint/eslint.lint.py => tools/lint/eslint/__init__.py
extra : rebase_source : f11e103038acd8b95b9586026c571a88587a79b2
This commit is contained in:
Andrew Halberstadt 2017-06-02 09:48:22 -04:00
Родитель c52fd7290e
Коммит e892c0600b
4 изменённых файлов: 36 добавлений и 21 удалений

10
tools/lint/eslint.yml Normal file
Просмотреть файл

@ -0,0 +1,10 @@
eslint:
description: JavaScript linter
# ESLint infra handles its own path filtering, so just include cwd
include: ['.']
exclude: []
# Make sure these are defined on the same line until the hack
# in hook_helper.py is fixed.
extensions: ['js', 'jsm', 'jsx', 'xml', 'html', 'xhtml']
type: external
payload: eslint:lint

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

@ -32,7 +32,7 @@ and try again.
""".strip()
def lint(paths, binary=None, fix=None, setup=None, **lintargs):
def lint(paths, config, binary=None, fix=None, setup=None, **lintargs):
"""Run eslint."""
global project_root
setup_helper.set_project_root(lintargs['root'])
@ -77,7 +77,7 @@ def lint(paths, binary=None, fix=None, setup=None, **lintargs):
# ESLint plugin (bug 1229874).
'--plugin', 'html',
# This keeps ext as a single argument.
'--ext', '[{}]'.format(','.join(setup_helper.EXTENSIONS)),
'--ext', '[{}]'.format(','.join(config['extensions'])),
'--format', 'json',
] + extra_args + paths
@ -122,18 +122,6 @@ def lint(paths, binary=None, fix=None, setup=None, **lintargs):
'path': obj['filePath'],
'rule': err.get('ruleId'),
})
results.append(result.from_linter(LINTER, **err))
results.append(result.from_config(config, **err))
return results
LINTER = {
'name': "eslint",
'description': "JavaScript linter",
# ESLint infra handles its own path filtering, so just include cwd
'include': ['.'],
'exclude': [],
'extensions': setup_helper.EXTENSIONS,
'type': 'external',
'payload': lint,
}

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

@ -3,13 +3,31 @@
# This file provides helper functions for the repository hooks for git/hg.
import os
import json
import os
import re
from subprocess import check_output, CalledProcessError
import setup_helper
ignored = 'File ignored because of a matching ignore pattern. Use "--no-ignore" to override.'
here = os.path.abspath(os.path.dirname(__file__))
config_path = os.path.join(here, '..', 'eslint.yml')
EXTENSIONS_RE = None
def get_extensions():
# This is a hacky way to avoid both re-defining extensions and
# depending on PyYaml in hg's python path. This will go away
# once the vcs hooks are using mozlint directly (bug 1361972)
with open(config_path) as fh:
line = [l for l in fh.readlines() if 'extensions' in l][0]
extensions = json.loads(line.split(':', 1)[1].replace('\'', '"'))
return [e.lstrip('.') for e in extensions]
def is_lintable(filename):
"""Determine if a file is lintable based on the file extension.
@ -17,7 +35,10 @@ def is_lintable(filename):
Keyword arguments:
filename -- the file to check.
"""
return setup_helper.EXTENSIONS_RE.match(filename)
global EXTENSIONS_RE
if not EXTENSIONS_RE:
EXTENSIONS_RE = re.compile(r'.+\.(?:%s)$' % '|'.join(get_extensions()))
return EXTENSIONS_RE.match(filename)
def display(print_func, output_json):

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

@ -39,10 +39,6 @@ Valid installation paths:
VERSION_RE = re.compile(r"^\d+\.\d+\.\d+$")
CARET_VERSION_RANGE_RE = re.compile(r"^\^((\d+)\.\d+\.\d+)$")
LINTED_EXTENSIONS = ['js', 'jsm', 'jsx', 'xml', 'html', 'xhtml']
EXTENSIONS = [".%s" % x for x in LINTED_EXTENSIONS]
EXTENSIONS_RE = re.compile(r'.+\.(?:%s)$' % '|'.join(LINTED_EXTENSIONS))
project_root = None