Bug 1289805 - Properly normalize all paths so they are absolute, r?smacleod
It's important to use absolute paths so lint errors for the same files don't show up in two
different places. For example, eslint will absolutize a relative path, whereas flake8 will
not.
This patch also makes sure all include/exclude paths are joined to the mozlint 'root' that
was previously calculated from vcs.
MozReview-Commit-ID: KYhC6SEySC3
--- a/python/mozlint/mozlint/pathutils.py
+++ b/python/mozlint/mozlint/pathutils.py
@@ -67,22 +67,28 @@ def filterpaths(paths, linter, **lintarg
:param paths: A starting list of paths to possibly lint.
:param linter: A linter definition.
:param lintargs: Extra arguments passed to the linter.
:returns: A list of file paths to lint.
"""
include = linter.get('include', [])
exclude = lintargs.get('exclude', [])
exclude.extend(linter.get('exclude', []))
+ root = lintargs['root']
if not lintargs.get('use_filters', True) or (not include and not exclude):
return paths
- include = map(FilterPath, include or [])
- exclude = map(FilterPath, exclude or [])
+ def normalize(path):
+ if not os.path.isabs(path):
+ path = os.path.join(root, path)
+ return FilterPath(path)
+
+ include = map(normalize, include)
+ exclude = map(normalize, exclude)
# Paths with and without globs will be handled separately,
# pull them apart now.
includepaths = [p for p in include if p.exists]
excludepaths = [p for p in exclude if p.exists]
includeglobs = [p for p in include if not p.exists]
excludeglobs = [p for p in exclude if not p.exists]
--- a/python/mozlint/mozlint/roller.py
+++ b/python/mozlint/mozlint/roller.py
@@ -104,16 +104,17 @@ class LintRoller(object):
raise LintersNotConfigured
# Calculate files from VCS
if rev:
paths.extend(self.vcs.by_rev(rev))
if workdir:
paths.extend(self.vcs.by_workdir())
paths = paths or ['.']
+ paths = map(os.path.abspath, paths)
# Set up multiprocessing
m = Manager()
queue = m.Queue()
for linter in self.linters:
queue.put(linter['path'])