Skip to content

Commit

Permalink
Bug 1360595 - Make the ESLint Mercurial pre-commit hook be run in and…
Browse files Browse the repository at this point in the history
… pass flake8 validation. r=mossop

MozReview-Commit-ID: 1GW59lKpVrI

--HG--
extra : rebase_source : bad1919b52fc29a9874090f314ad682e72840f70
  • Loading branch information
Standard8 committed Apr 28, 2017
1 parent 7f43e4e commit 046debb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions tools/lint/flake8.lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def lint(files, **lintargs):
'testing/mochitest',
'testing/talos/',
'tools/lint',
'tools/mercurial',
'toolkit/components/telemetry',
],
'exclude': ['testing/mochitest/pywebsocket'],
Expand Down
11 changes: 8 additions & 3 deletions tools/mercurial/eslintvalidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
# 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:
Expand All @@ -22,10 +23,12 @@ def display(ui, output):
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:
Expand All @@ -50,15 +53,17 @@ def eslinthook(ui, repo, node=None, **opts):
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()
Expand Down

0 comments on commit 046debb

Please sign in to comment.