Bug 1360595 - Make the ESLint Mercurial pre-commit hook be run in and pass flake8 validation. r?Mossop draft
authorMark Banner <standard8@mozilla.com>
Fri, 28 Apr 2017 12:15:56 +0100
changeset 571858 aa248eeef420a9fd5075d5635e539d4b4514d58b
parent 571808 82c2d17e74ef9cdf38a5d5ac4eb3ae846ec30ba4
child 571859 133a4d2590b34a70221412c7e9be2e9005cb19ba
child 572155 8b741664e70044c056cd97713c746194909b372d
push id56928
push usermbanner@mozilla.com
push dateWed, 03 May 2017 10:24:07 +0000
reviewersMossop
bugs1360595
milestone55.0a1
Bug 1360595 - Make the ESLint Mercurial pre-commit hook be run in and pass flake8 validation. r?Mossop MozReview-Commit-ID: 1GW59lKpVrI
tools/lint/flake8.lint.py
tools/mercurial/eslintvalidate.py
--- a/tools/lint/flake8.lint.py
+++ b/tools/lint/flake8.lint.py
@@ -183,15 +183,16 @@ LINTER = {
         'testing/firefox-ui',
         'testing/marionette/client',
         'testing/marionette/harness',
         'testing/marionette/puppeteer',
         'testing/mozbase',
         'testing/mochitest',
         'testing/talos/',
         'tools/lint',
+        'tools/mercurial',
         'toolkit/components/telemetry',
     ],
     'exclude': ['testing/mochitest/pywebsocket'],
     'extensions': EXTENSIONS,
     'type': 'external',
     'payload': lint,
 }
--- a/tools/mercurial/eslintvalidate.py
+++ b/tools/mercurial/eslintvalidate.py
@@ -1,36 +1,39 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
 import os
-import sys
 import re
 import json
 from subprocess import check_output, CalledProcessError
 
 lintable = re.compile(r'.+\.(?:js|jsm|jsx|xml|html)$')
 ignored = 'File ignored because of a matching ignore pattern. Use "--no-ignore" to override.'
 
+
 def is_lintable(filename):
     return lintable.match(filename)
 
+
 def display(ui, output):
     results = json.loads(output)
     for file in results:
         path = os.path.relpath(file["filePath"])
         for message in file["messages"]:
             if message["message"] == ignored:
                 continue
 
             if "line" in message:
-                ui.warn("%s:%d:%d %s\n" % (path, message["line"], message["column"], message["message"]))
+                ui.warn("%s:%d:%d %s\n" % (path, message["line"], message["column"],
+                        message["message"]))
             else:
                 ui.warn("%s: %s\n" % (path, message["message"]))
 
+
 def eslinthook(ui, repo, node=None, **opts):
     ctx = repo[node]
     if len(ctx.parents()) > 1:
         return 0
 
     deleted = repo.status(ctx.p1().node(), ctx.node()).deleted
     files = [f for f in ctx.files() if f not in deleted and is_lintable(f)]
 
@@ -45,25 +48,27 @@ def eslinthook(ui, repo, node=None, **op
 
         dir = os.path.join(basepath, "node_modules", ".bin")
 
         eslint_path = os.path.join(dir, "eslint")
         if os.path.exists(os.path.join(dir, "eslint.cmd")):
             eslint_path = os.path.join(dir, "eslint.cmd")
         output = check_output([eslint_path,
                                "--format", "json", "--plugin", "html"] + files,
-                               cwd=basepath)
+                              cwd=basepath)
         display(ui, output)
     except CalledProcessError as ex:
         display(ui, ex.output)
         ui.warn("ESLint found problems in your changes, please correct them.\n")
 
+
 def reposetup(ui, repo):
     ui.setconfig('hooks', 'commit.eslint', eslinthook)
 
+
 def get_project_root():
     file_found = False
     folder = os.getcwd()
 
     while (folder):
         if os.path.exists(os.path.join(folder, 'mach')):
             file_found = True
             break