Skip to content

Commit

Permalink
Use jshint
Browse files Browse the repository at this point in the history
  • Loading branch information
wallin committed May 28, 2011
1 parent 70cf423 commit 62d9f16
Show file tree
Hide file tree
Showing 6 changed files with 3,956 additions and 22 deletions.
42 changes: 21 additions & 21 deletions .emacs
Original file line number Diff line number Diff line change
Expand Up @@ -431,27 +431,27 @@

;;(load "flymake-php.el")

;; (defun flymake-jslint-init ()
;; (let* ((temp-file (flymake-init-create-temp-buffer-copy
;; 'flymake-create-temp-inplace))
;; (local-file (file-relative-name
;; temp-file
;; (file-name-directory buffer-file-name))))
;; (list "rhino" (list (expand-file-name (add-path "tools/jslint/jslint.js")) local-file))))

;; (setq flymake-allowed-file-name-masks
;; (cons '(".+\\.js$"
;; flymake-jslint-init
;; flymake-simple-cleanup
;; flymake-get-real-file-name)
;; flymake-allowed-file-name-masks))

;; (setq flymake-err-line-patterns
;; (cons '("^Lint at line \\([[:digit:]]+\\) character \\([[:digit:]]+\\): \\(.+\\)$"
;; nil 1 2 3)
;; flymake-err-line-patterns))

(require 'gjslint)
(defun flymake-jslint-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "jshint" (list local-file))))

(setq flymake-allowed-file-name-masks
(cons '(".+\\.js$"
flymake-jslint-init
flymake-simple-cleanup
flymake-get-real-file-name)
flymake-allowed-file-name-masks))

(setq flymake-err-line-patterns
(cons '("^\\(.+\\). \(line: \\([[:digit:]]+\\), character: \\([[:digit:]]+\\)\)$"
nil 2 3 1)
flymake-err-line-patterns))

;;(require 'gjslint)

(add-hook 'javascript-mode-hook
(lambda () (flymake-mode 1)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
#contributor : Sebastian Wallin
#name : function
# --
function ($1) {
function($1) {
$0
}
1 change: 1 addition & 0 deletions tools/jshint/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Copy all files in this directory to /usr/local/bin
40 changes: 40 additions & 0 deletions tools/jshint/jsc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*jshint boss: true */

// usage:
// jsc env/jsc.js -- ${file} "$(cat ${file})" "{option1:true,option2:false}"

load("/usr/local/bin/jshint.js");

(function(args){
var name = args[0],
input = args[1],
opts = (function(arg){
switch (arg) {
case undefined:
case '':
return {};
default:
return eval('(' + arg + ')');
}
})(args[2]);

if (!name) {
print('jshint: No file name was provided.');
quit();
}

if (!input) {
print('jshint: ' + name + ' contents were not provided to jshint.');
quit();
}

if (!JSHINT(input, opts)) {
for (var i = 0, err; err = JSHINT.errors[i]; i++) {
print(err.reason + ' (line: ' + err.line + ', character: ' + err.character + ')');
print('> ' + (err.evidence || '').replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
print('');
}
}

quit();
})(arguments);
21 changes: 21 additions & 0 deletions tools/jshint/jshint
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
# usage (run from jshint's directory) :
# env/jsc.sh /path/to/script.js
# or with jshint options:
# env/jsc.sh /path/to/script.js "{option1:true,option2:false,option3:25}"

alias jsc="/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc"
FILE="${1}"
OPTS="${2}"

LINT_RESULT="$(jsc /usr/local/bin/jsc.js -- ${FILE} "$(cat ${FILE})" "${OPTS}")"
ERRORS=$(echo ${LINT_RESULT} | egrep [^\s] -c)

if [[ ${ERRORS} -ne 0 ]]; then
echo "[jshint] Error(s) in ${FILE}:"
printf "%s\n" "${LINT_RESULT}"
else
echo "[jshint] ${FILE} passed!"
fi

exit $((0 + ${ERRORS}))
Loading

0 comments on commit 62d9f16

Please sign in to comment.