Permalink
Browse files

Use jshint

  • Loading branch information...
1 parent 70cf423 commit 62d9f1699bdd544b2f72a406fcea388a8991bb9a @wallin wallin committed May 28, 2011
Showing with 3,956 additions and 22 deletions.
  1. +21 −21 .emacs
  2. +1 −1 .emacs.d/addons/yasnippet-0.6.1c/snippets/text-mode/js-mode/fn
  3. +1 −0 tools/jshint/README
  4. +40 −0 tools/jshint/jsc.js
  5. +21 −0 tools/jshint/jshint
  6. +3,872 −0 tools/jshint/jshint.js
View
@@ -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)))
@@ -2,6 +2,6 @@
#contributor : Sebastian Wallin
#name : function
# --
-function ($1) {
+function($1) {
$0
}
View
@@ -0,0 +1 @@
+Copy all files in this directory to /usr/local/bin
View
@@ -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);
View
@@ -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}))
Oops, something went wrong.

0 comments on commit 62d9f16

Please sign in to comment.