Permalink
Browse files

Add linting tools.

* scripts/lint.sh
* scripts/hook/lint.pre-commit
  • Loading branch information...
1 parent 8326118 commit b64557eb177342c68d21e74d916a900ab6b05031 @mythmon mythmon committed Jan 6, 2014
Showing with 85 additions and 0 deletions.
  1. +47 −0 scripts/hooks/lint.pre-commit
  2. +38 −0 scripts/lint.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+#
+# Run the Kitsune linters.
+#
+# If this file is not in the `.git/hooks` directory, executing it will
+# prompt to install it.
+
+DIR=$(dirname $0)
+
+function lint() {
+ echo 'Linting...'
+ FILES_TO_LINT=$(git diff-index --no-commit-id --name-only -r HEAD | sort | uniq)
+ ./scripts/lint.sh $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 install() {
+ echo -ne "Would you like to install the linter as a pre-commit hook? "
+ while true; do
+ read yn
+ case $yn in
+ [Yy]* ) break;;
+ [Nn]* ) exit 1;;
+ * ) echo "Please enter 'y' or 'n'."
+ esac
+ done
+
+ GITDIR=$(git rev-parse --git-dir)
+ if [[ -e $GITDIR/hooks/pre-commit ]]; then
+ echo "You already have a git pre-commit hook. Bailing."
+ exit 1
+ fi
+
+ ln -s ../../scripts/hooks/lint.pre-commit $GITDIR/hooks/pre-commit
+}
+
+if echo $DIR | grep -E ".git/hooks$" > /dev/null; then
+ lint
+else
+ install
+fi
View
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+# This file runs a serious of lints against the code base, each of which
+# has been configured to our liking. This is intended to be run as part
+# of a continuous integration suite, and all new code should pass these
+# tests. The currently run lint programs are:
+#
+# - pep8
+# - pyflakes
+#
+# Generated code such as migrations are ignored, as are any other files
+# that would be unreasonable to lint. Think carefully before adding a
+# new file to the list of ignores.
+
+FLAKE8_IGNORE=(
+ 'migrations'
+ 'kitsune/settings*'
+ 'kitsune/sumo/db_strings.py'
+ 'kitsune/sumo/static/js/libs/ace/kitchen-sink/docs/python.py'
+)
+
+# Files to lint is either the list of arguments to this script, or the
+# kitsune directory.
+FILES="$@"
+FLAKE8_FILES=()
+
+for f in $FILES; do
+ # If it is a directory, or if it is a python file, lint it with flake8.
+ if [[ -d $f ]] || echo $f | grep -E '.py$' > /dev/null; then
+ FLAKE8_FILES+=($f)
+ fi
+done
+
+FLAKE8_IGNORE=$(IFS=,; echo "${FLAKE8_IGNORE[*]}")
+flake8 --exclude=$FLAKE8_IGNORE ${FLAKE8_FILES[*]}
+FLAKE_RETURN=$?
+
+exit $FLAKE_RETURN

0 comments on commit b64557e

Please sign in to comment.