間違いだらけの備忘録

このページの内容は無保証でありこのページの内容によって直接、または間接に損害を受けられたとしても私は責任を取りません。

WindowsのコマンドプロンプトからJSHint

http://mirahalab.blogspot.jp/2013/05/windowsjshint.html

Rhinoををインストールして、JShintのRhino bundleをダウンロード

https://developer.mozilla.org/en-US/docs/Rhino/Download_Rhino?redirectlocale=en-US&redirectslug=RhinoDownload
http://www.jshint.com/install/
cygwin環境で構文エラー検出のみ使用したかったため、下記を作成。

#!/bin/bash
"/cygdrive/c/Program Files/Java/jre7/bin/java.exe" -Dfile.encoding=UTF-8 -jar "C:\cygwin\home\user\rhino1_7R4\js.jar" "C:\cygwin\home\user\jshint-rhino-2.1.10.js" $@ | grep "^E" && exit 1
exit 0

jshint-rhino-2.1.10.jsを修正

$ diff -uNr jshint-rhino-2.1.10.orig.js jshint-rhino-2.1.10.js
--- jshint-rhino-2.1.10.orig.js 2013-08-11 00:00:00.163123800 +0900
+++ jshint-rhino-2.1.10.js      2013-08-11 00:00:00.180308900 +0900
@@ -7535,7 +7535,7 @@
                state.ignored = newIgnoredObj;
 
                state.option.indent = state.option.indent || 4;
-               state.option.maxerr = state.option.maxerr || 50;
+               state.option.maxerr = state.option.maxerr || Number.POSITIVE_INFINITY;
 
                indent = 1;
                global = Object.create(predefined);
@@ -11439,9 +11439,7 @@
 
                if (!JSHINT(input, opts, globals)) {
                        for (var i = 0, err; err = JSHINT.errors[i]; i += 1) {
-                               print(err.reason + " (" + name + ":" + err.line + ":" + err.character + ")");
-                               print("> " + (err.evidence || "").replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
-                               print("");
+                               print(err.code + ":" + err.reason + " (" + name + ":" + err.line + ":" + err.character + ")" + "> " + (err.evidence || "").replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
                        }
                        retval = 2;
                }
このページにはhatena以外のサービスからのコンテンツが埋め込まれています。 hatenaによりGoogle AdSense 広告が埋め込まれています。