Skip to content

Instantly share code, notes, and snippets.

@mikewest
Created April 8, 2010 14:46
Show Gist options
  • Save mikewest/360139 to your computer and use it in GitHub Desktop.
Save mikewest/360139 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ -n "${1}" ] && [ -n "${2}" ]; then
LINTEE=$1
REPORT_ROOT=$2
LINTEE_BASENAME=`echo "${LINTEE}" | sed "s#.*\/\(.*\)\.js\\\$#\1#"`
TEST_BASENAME="de.sueddeutsche.static.js.${LINTEE_BASENAME}"
REPORT_FILENAME="${REPORT_ROOT}/${TEST_BASENAME}.xml"
mkdir -p $REPORT_ROOT
LINT_TIME=`{ time java -jar ./scripts/lib/js.jar ./scripts/lib/jslint.js "${LINTEE}" 2>&1 1> ${REPORT_FILENAME}.tmp; } 2>&1 | grep real | sed 's#.*m\(.*\)s#\1#'`
LINT_RESULTS=$(<"${REPORT_FILENAME}.tmp")
WAS_FAILURE=`cat "${REPORT_FILENAME}.tmp" | grep -v 'No problems found in'`
rm "${REPORT_FILENAME}.tmp"
if [ "---${WAS_FAILURE}---" != "------" ]; then
echo "<testsuite failures='1' time='${LINT_TIME}' errors='1' tests='1' skipped='0' name='${TEST_BASENAME}'>" > $REPORT_FILENAME
echo " <testcase time='${LINT_TIME}' name='testJSLint' classname='${TEST_BASENAME}'>" >> $REPORT_FILENAME
echo " <error message='${LINTEE_BASENAME} failed JSLint.'><![CDATA[${LINT_RESULTS}]]></error>" >> $REPORT_FILENAME
echo " </testcase>" >> $REPORT_FILENAME
echo "</testsuite>" >> $REPORT_FILENAME
else
echo "<testsuite failures='0' time='${LINT_TIME}' errors='0' tests='1' skipped='0' name='${TEST_BASENAME}'>" > $REPORT_FILENAME
echo " <testcase time='${LINT_TIME}' name='testJSLint' classname='${TEST_BASENAME}'>" >> $REPORT_FILENAME
echo " </testcase>" >> $REPORT_FILENAME
echo "</testsuite>" >> $REPORT_FILENAME
fi
else
echo "Usage: ${0} <file to lint> <path to reports>"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment