Bug 1375166 - [mozlint] Don't require leading '.' in extensions, r?standard8
This was a regression from
bug 1288432. The 'extensions' config in mozlint required a
leading period, but eslint requires them without the period (and this got copied over
to the linter definition). The result was mozlint filtering out any files (not dirs)
that were passed in.
This just modifies mozlint to strip out the period so both are acceptable.
MozReview-Commit-ID: CbNynYzrbGz
--- a/python/mozlint/mozlint/parser.py
+++ b/python/mozlint/mozlint/parser.py
@@ -36,16 +36,19 @@ class Parser(object):
raise LinterParseError(linter['path'], "Invalid type '{}'".format(linter['type']))
for attr in ('include', 'exclude'):
if attr in linter and (not isinstance(linter[attr], list) or
not all(isinstance(a, basestring) for a in linter[attr])):
raise LinterParseError(linter['path'], "The {} directive must be a "
"list of strings!".format(attr))
+ if 'extensions' in linter:
+ linter['extensions'] = [e.strip('.') for e in linter['extensions']]
+
def parse(self, path):
"""Read a linter and return its LINTER definition.
:param path: Path to the linter.
:returns: List of linter definitions ([dict])
:raises: LinterNotFound, LinterParseError
"""
if not os.path.isfile(path):
--- a/python/mozlint/mozlint/pathutils.py
+++ b/python/mozlint/mozlint/pathutils.py
@@ -22,17 +22,17 @@ class FilterPath(object):
if self._finder:
return self._finder
self._finder = FileFinder(
self.path, ignore=self.exclude)
return self._finder
@property
def ext(self):
- return os.path.splitext(self.path)[1]
+ return os.path.splitext(self.path)[1].strip('.')
@property
def exists(self):
return os.path.exists(self.path)
@property
def isfile(self):
return os.path.isfile(self.path)
--- a/python/mozlint/test/linters/string.yml
+++ b/python/mozlint/test/linters/string.yml
@@ -1,8 +1,9 @@
StringLinter:
description: Make sure the string foobar never appears in browser js files because it is bad
rule: no-foobar
include:
- '**/*.js'
- '**/*.jsm'
type: string
+ extensions: ['.js', 'jsm']
payload: foobar
--- a/python/mozlint/test/test_parser.py
+++ b/python/mozlint/test/test_parser.py
@@ -30,16 +30,18 @@ def test_parse_valid_linter(parse):
assert len(lintobj) == 1
lintobj = lintobj[0]
assert isinstance(lintobj, dict)
assert 'name' in lintobj
assert 'description' in lintobj
assert 'type' in lintobj
assert 'payload' in lintobj
+ assert 'extensions' in lintobj
+ assert set(lintobj['extensions']) == set(['js', 'jsm'])
@pytest.mark.parametrize('linter', [
'invalid_type.yml',
'invalid_extension.ym',
'invalid_include.yml',
'invalid_exclude.yml',
'missing_attrs.yml',
--- a/tools/lint/flake8.yml
+++ b/tools/lint/flake8.yml
@@ -13,11 +13,11 @@ flake8:
- testing/mochitest
- testing/talos/
- tools/git
- tools/lint
- tools/mercurial
- toolkit/components/telemetry
exclude:
- testing/mochitest/pywebsocket
- extensions: ['.py']
+ extensions: ['py']
type: external
payload: flake8_:lint