Bug 1289805 - Properly normalize all paths so they are absolute, r?smacleod draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Tue, 19 Jul 2016 13:09:38 -0400
changeset 401285 afb7528b2859a7251f84f1b9ab752ade9095dea3
parent 401284 947cba3fd850e62baf36c981bc99ece05b582595
child 528452 d718cc88feeef2a1cff4c0e42e22f1a63039ede5
push id26420
push userahalberstadt@mozilla.com
push dateTue, 16 Aug 2016 20:20:10 +0000
reviewerssmacleod
bugs1289805
milestone51.0a1
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
python/mozlint/mozlint/pathutils.py
python/mozlint/mozlint/roller.py
--- 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'])