gecko-dev/tools/mercurial/eslintvalidate.py
Mark Banner 72059d82da Bug 1360595 - Add a git pre-commit hook for running ESLint. r=mossop
MozReview-Commit-ID: 1YJL5Sd4dlb

--HG--
rename : tools/mercurial/eslintvalidate.py => tools/lint/eslint/hook_helper.py
extra : rebase_source : eec3ee2761dd7178de1562229bfda24c0859b4ae
2017-04-28 12:19:15 +01:00

28 lines
824 B
Python

# 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
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "lint", "eslint"))
from hook_helper import is_lintable, runESLint
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)]
if len(files) == 0:
return
if not runESLint(ui.warn, files):
ui.warn("Note: ESLint failed, but the commit will still happen. "
"Please fix before pushing.\n")
def reposetup(ui, repo):
ui.setconfig('hooks', 'commit.eslint', eslinthook)