Skip to content
This repository has been archived by the owner on Jan 31, 2018. It is now read-only.

Commit

Permalink
Add jshint to pre-commit hook
Browse files Browse the repository at this point in the history
Summary of changes:
* Define the node modules to be installed in package.json.
* Include 'jshint' as a dev dependency and 'less' as a
  dependency. 'less' is no longer installed globally.
* Since jshint doesn't include non-JavaScript files, specify the files and
  folders to be ignored in .jshintignore file.
* Install the node modules defined in package.json while provisioning.
* Add the node_modules/.bin/ folder to $PATH in ~/.bashrc.
* Rename the pre-commit hook script to a generic lint.pre-commit
* Refactor the calling of each lint tool into a separate function
  and include jshint.
* Modify the pre-commit script to call flake8 and jshint one after the
  other on the relevant files to be committed.
  • Loading branch information
lgp171188 committed Dec 15, 2014
1 parent a2a72bc commit 31c2f74
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
!(*.js)
vendor/
node_modules/
27 changes: 22 additions & 5 deletions bin/hooks/flake8_lint.pre-commit → bin/hooks/lint.pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@

DIR=$(dirname $0)

function lint() {
echo 'Linting...'
FILES_TO_LINT=$(git diff --cached --name-only --diff-filter=ACMR -- *.py **/*.py)
./bin/flake8_lint.sh $FILES_TO_LINT
function flake8_lint() {
PY_FILES_TO_LINT=$(git diff --cached --name-only --diff-filter=ACMR -- *.py **/*.py)
./bin/flake8_lint.sh $PY_FILES_TO_LINT
LINT_STATUS=$?
if [[ $LINT_STATUS -ne 0 ]]; then
echo
Expand All @@ -20,6 +19,24 @@ function lint() {
fi
}

function jshint_lint() {
JS_FILES_TO_LINT=$(git diff --cached --name-only --diff-filter=ACMR -- *.js **/*.js)
jshint $JS_FILES_TO_LINT
LINT_STATUS=$?
if [[ $LINT_STATUS -ne 0 ]]; then
echo
echo "Lint errors found. Please fix the above and retry."
echo "Alternatively, run 'git commit --no-verify' to ignore lint errors."
exit 1
fi
}

function lint() {
echo 'Linting...'
flake8_lint
jshint_lint
}

function install() {
echo -ne "Would you like to install the linter as a pre-commit hook? "
while true; do
Expand All @@ -37,7 +54,7 @@ function install() {
exit 1
fi

ln -s ../../bin/hooks/flake8_lint.pre-commit $GITDIR/hooks/pre-commit
ln -s ../../bin/hooks/lint.pre-commit $GITDIR/hooks/pre-commit
}

if echo $DIR | grep -E ".git/hooks$" > /dev/null; then
Expand Down
7 changes: 5 additions & 2 deletions bin/vagrant_provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ apt-get install -y -q npm
# Homogenize binary name with production RHEL:
ln -sf /usr/bin/nodejs /usr/local/bin/node

# Install LESSC
npm install -g less
# Install node modules from package.json
sudo -H -u vagrant npm install

# Install Python development-related things:
apt-get install -y -q libapache2-mod-wsgi python-pip libpython-dev
Expand Down Expand Up @@ -85,6 +85,9 @@ apt-get autoremove -y -q
# Activate the virtual environment in .bashrc
echo ". $VENV/bin/activate" >> /home/vagrant/.bashrc

# Add the 'bin' folder of local node modules to $PATH
echo "export PATH=$PATH:/home/vagrant/fjord/node_modules/.bin/" >> /home/vagrant/.bashrc

# FIXME: Change the motd file so that it has a link to Fjord docs,
# tells the user where the code is and lists common commands.

Expand Down
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Fjord",
"description": "Platform for Mozilla Input",
"repository": {
"type": "git",
"url": "git://github.com/mozilla/fjord.git"
},
"devDependencies": {
"jshint": "2.5.10"
},
"dependencies": {
"less": "1.7.0"
}

}

0 comments on commit 31c2f74

Please sign in to comment.