Skip to content
This repository has been archived by the owner on Sep 14, 2021. It is now read-only.

Commit

Permalink
Adding jshint and Makefile for it.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbisbee committed Nov 2, 2011
1 parent 8d80a8f commit 61f059a
Show file tree
Hide file tree
Showing 3 changed files with 3,950 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Makefile
@@ -0,0 +1,12 @@
NODE := `which node nodejs`

JSHINT_CHECK := ./build/jshint-check.js

all: hint

hint:
@@for file in `find . -name "*.js" | grep -v '^\./build/'`; do \
echo "Hinting: $$file"; \
${NODE} ${JSHINT_CHECK} $$file; \
echo "--------------------------"; \
done
52 changes: 52 additions & 0 deletions build/jshint-check.js
@@ -0,0 +1,52 @@
var JSHINT = require("./lib/jshint/jshint.js").JSHINT,
print = require("sys").print,
src = require("fs").readFileSync(process.argv[2], "utf8");

JSHINT(
src,
{
evil: true,
forin: true,
maxerr: 100,
noempty: true,
nomen: true,
node: true
}
);

var ok = {

// w.reason
"Expected an identifier and instead saw 'undefined' (a reserved word).": true,
"Use '===' to compare with 'null'.": true,
"Use '!==' to compare with 'null'.": true,
"Expected an assignment or function call and instead saw an expression.": true,
"Expected a 'break' statement before 'case'.": true,
"'e' is already defined.": true,

// w.raw
"Expected an identifier and instead saw \'{a}\' (a reserved word).": true
};

var e = JSHINT.errors,
found = 0,
w;

for ( var i = 0; i < e.length; i++ ) {
w = e[i];

//console.log( w );
if ( !ok[ w.reason ] && !ok[ w.raw ] ) {
found++;
print( "\n " + found + ". Problem at line " + w.line + " character " + w.character + ": " + w.reason );
print( "\n" + w.evidence );
}
}

if ( found > 0 ) {
print( "\n\n" + found + " Error(s) found.\n" );
process.exit(1);

} else {
print( "JSHint check passed.\n" );
}

0 comments on commit 61f059a

Please sign in to comment.