Bug 1623320 - Add support to run mozlint on dotfile r=linter-reviewers,ahal

Differential Revision: https://phabricator.services.mozilla.com/D67316

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Sylvestre Ledru 2020-03-20 21:51:03 +00:00
parent b672b3f331
commit 7cfa120eb9
5 changed files with 25 additions and 5 deletions

View File

@ -82,6 +82,7 @@ Each ``.yml`` file must have at least one linter defined in it. Here are the sup
* extensions - A list of file extensions to be considered (optional)
* setup - A function that sets up external dependencies (optional)
* support-files - A list of glob patterns matching configuration files (optional)
* find-dotfiles - If set to ``true``, run on dot files (.*) (optional)
In addition to the above, some ``.yml`` files correspond to a single lint rule. For these, the
following additional keys may be specified:

View File

@ -269,6 +269,7 @@ def expand_exclusions(paths, config, root):
Generator which generates list of paths that weren't excluded.
"""
extensions = [e.lstrip('.') for e in config.get('extensions', [])]
find_dotfiles = config.get('find-dotfiles', False)
def normalize(path):
path = mozpath.normpath(path)
@ -291,7 +292,7 @@ def expand_exclusions(paths, config, root):
ignore = [e[len(path):].lstrip('/') for e in exclude
if mozpath.commonprefix((path, e)) == path]
finder = FileFinder(path, ignore=ignore)
finder = FileFinder(path, ignore=ignore, find_dotfiles=find_dotfiles)
_, ext = os.path.splitext(path)
ext.lstrip('.')

View File

@ -0,0 +1,5 @@
// Dot file to verify that it works
// without license
"use strict";

View File

@ -0,0 +1,11 @@
============
Coding style
==========
foo bar
~~~~~
This file has error but should not be there
as we don't analyze dot files

View File

@ -8,15 +8,17 @@ LINTER = 'license'
def test_lint_license(lint, paths):
results = lint(paths())
print(results)
assert len(results) == 2
assert len(results) == 3
assert "No matching license strings" in results[0].message
assert results[0].level == "error"
assert "bad.c" in results[0].relpath
assert "No matching license strings" in results[1].message
assert results[1].level == "error"
assert "bad.js" in results[1].relpath
assert ".eslintrc.js" in results[1].relpath
assert "No matching license strings" in results[2].message
assert results[2].level == "error"
assert "bad.js" in results[2].relpath
if __name__ == '__main__':