å æ¥ãEmacsã®grepã¢ã¼ãã®èª¬æããã¾ãããããã®å¿ç¨ã¨ãã¦ãJavaScriptã®æ§æãã§ãã«ã¼ã§ããJSLintãEmacsãã使ã£ã¦ã¿ã¾ãã
Windowsä¸ã®Meadow3ã§ã®è©±ã§ãããWindowsç¹æã®é¨åã¯ãä»ã®OSã§ã¯åé¡ã«ãªããªãã´ã¿ã´ã¿ã®ã¨ããï¼ä¾ï¼å±éºãª^Zï¼ã ãã§ãã
å 容ï¼
- Emacsã®javascriptã¢ã¼ã
- JSLint
- Rhino
- ã¨ããããåããã¦ã¿ã
- JSLintã½ã¼ã¹ã®ä¿®æ£
- EmacsããJSLintã使ã
- MakefileããJSLintã使ã
âEmacsã®javascriptã¢ã¼ã
[追è¨]
javascriptã¢ã¼ãã¯æ¨å¥¨ã§ãã¾ããããEmacsã§JavaScriptã½ã¼ã¹ãå¿«é©ã«èªãããã«ï¼js2-modeã¨ã¨ã°ãºã¼ãã©ã³ãCtagsã ãã覧ãã ããã
[/追è¨]
- http://www.brgeight.se/ ï¼2008-04æç¹ï¼
.emacsã®è¨å®ä¾ï¼
;; Author: Karl Landstrom
;; Maintainer: Karl Landstrom
;; Version: 2.0 Beta 8
;; Date: 2006-12-26
;; javascript-mode
(add-to-list 'auto-mode-alist
(cons "\\.\\(js\\|json\\)\\'" 'javascript-mode))
(autoload 'javascript-mode "javascript" nil t)
(setq js-indent-level 2) ; å¤ã¯ã好ã¿ã«ãã
âJSLint
JSLintã«ã¯ãKonfabulatorçãWSHçãRhinoçãããã¾ããããã§ã¯ãRhinoçã«ã¤ãã¦èª¬æãã¾ãã
Rhinoçjslint.jsãhttp://www.jslint.com/rhino/index.htmlãããã¦ã³ãã¼ãã§ãã¾ãããããã¯æ¹è¡ã空ç½ãåãé¤ãããã®ã§ã人éãè¦ãã«ã¯è¾ããã¾ããå¾ã§å°ãå¤æ´ããé½åãããã®ã§ãJSLintãã¼ã¸ä¸çªä¸ã®Implementationã®ã¨ããããæ®éã®ã½ã¼ã¹ã³ã¼ãããã¦ã³ãã¼ããã¾ããfulljslint.jsã¨rhino.jsã®2ã¤ã®ãã¡ã¤ã«ãå¿ è¦ã§ãã
ï¼ã³ã¡ã³ãã«jslint.jsã¨æ¸ãã¦ããã¾ããããã¡ã¤ã«åã¯fulljslint.jsã§ããï¼
// jslint.js
// 2008-04-09
/*
Copyright (c) 2002 Douglas Crockford (www.JSLint.com)
// rhino.js
// 2007-02-19
/*
Copyright (c) 2002 Douglas Crockford (www.JSLint.com) Rhino Edition
âRhino
ç¾æç¹ï¼2008-04ï¼ã§ã®ææ°ç㯠Rhino 1.7R1 2008-03-06 rhino1_7R1.zip ã§ããå®è¡ã«å¿ è¦ãªã®ã¯js.jarã ãã§ããããjs.jarãã©ã£ãé©å½ãªå ´æã«ç½®ãã¾ãã
次ã¯ãåã使ã£ã¦ããèµ·åç¨ããããã¡ã¤ã«ã§ã*1ã
@echo off
REM rhino-c.bat -- ã³ãã³ãã©ã¤ã³çRhinoif "%RHINO_HOME%" == "" set RHINO_HOME=C:\installed\rhinolib
if "%JS_JAR%" == "" set JS_JAR=%RHINO_HOME%\js.jarjava -cp %JS_JAR% org.mozilla.javascript.tools.shell.Main %1 %2 %3 %4 %5 %6 %7 %8 %9
âã¨ããããåããã¦ã¿ã
次ã®ããã«ãã¦èªåç¨ã®jslint.jsãä½ãã¾ãã
ã¾ãã¯ã
cat fulljslint.js rhino.js > jslint.js
ããã§ã/bãä»ããªãã¨ãæè¿ã®è¥ã人ã¯ãã¶ãç¥ããªã^Zãæ«å°¾ã«ä»ããããªã¾ãã
copy /b fulljslint.js + rhino.js jslint.js
ãã§ãã¯ãããJavaScriptãã¡ã¤ã«ãæºåãã¦ãJSLintã§èª¿ã¹ã¦ã¿ã¾ããããã§ã¯ã以åã«æ²è¼ããRingBuffer.jsã«ããã³ããã³ããå¾ããå ¥ããã½ã¼ã¹ã使ãã¾ãã
>rhino-c jslint.js RingBuffer.js
Lint at line 7 character 32: Missing semicolon.
throw "Too small buffer size"Lint at line 10 character 21: Use the array literal notation [].
this.buffer = new Array(size);Lint at line 16 character 2: Missing semicolon.
}Lint at line 19 character 24: Line breaking error ')'.
return (this.next + 1)
ãã®åºåå½¢å¼ã§ã¯ããgrepã³ãã³ãã¨Emacs grepã¢ã¼ãã£ã¦ããã£ã±ã便å©ã ããªãã§ç´¹ä»ããEmacsã®ä¾¿å©ãªæ©è½ã使ããªãã®ã§ãjslint.jsã«æãå ãã¾ãã
>copy jslint.js jslint.js.orig(ãã®å¾ãjslint.jsãç·¨é)
JSLintã§ãã1ã¤å°ã£ããã¨ã¯ãJavaScriptã½ã¼ã¹ã³ã¼ãã«æ¥æ¬èªã®æåï¼UTF-8ã§ãï¼ã使ãã¨ããããã³ã¡ã³ãå ã§ãã£ã¦ã"Unsafe character."ã¨æå¥ãè¨ããã¨ã§ãã ãã®ç¹ãä¿®æ£ãã¾ãã
âJSLintã½ã¼ã¹ã®ä¿®æ£
åºåå½¢å¼ã«é¢ãã¦ã¯ããã¨ãã¨rhino.jsï¼rhino.jsã¯ããã36è¡ï¼ã«å«ã¾ãã¦ããåºåé¨åãæ¸ãæããã°OKã§ãã
Unsafe characterã®å¤å®ã¯ãcxã¨ããå¤æ°ã«å«ã¾ããæ£è¦è¡¨ç¾ã«åºã¥ãã¦ãªããã¾ãã
// unsafe character
cx = /[\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/,
ãã®csãæ¸ãæããã°ããããªã¨æã£ãã®ã§ãããã©ãæ¸ãæããã°ãããåã¯åãããªãã£ãã®ã§ãï¼æã¾ããã¯ãªããã©ï¼æ¬¡ã®ãã§ãã¯é¨åãåã£ã¦ãã¾ãã¾ããã
s = lines[line].replace(/\t/g, ' ');
at = s.search(cx);
if (at >= 0) {
warningAt("Unsafe character.", line, at);
}
以å決ãããããã®ä½ãæ¹ã«å¾ã£ã¦ã次ã®ã³ãã³ããå®è¡ãã¾ãã
diff -u jslint.js.orig jslint.js > jslint.js.20080411.diff
ããããã¡ã¤ã«ã¯æ¬¡ã®ã¨ããã§ãããã®ãªãªã¸ãã«jslint.jsã¯ãfulljslint.jsã¨rhino.jsãã¢ãã³ããããã¡ã¤ã«ã§ãããã¨ã«æ³¨æãã¦ãã ããã
--- jslint.js.orig Fri Apr 11 10:44:31 2008
+++ jslint.js Fri Apr 11 11:42:39 2008
@@ -644,17 +644,19 @@
// Private lex methods
function nextLine() {
- var at;
+// var at; //omitted by M.Hiyama
line += 1;
if (line >= lines.length) {
return false;
}
character = 0;
s = lines[line].replace(/\t/g, ' ');
+/* //omitted by M.Hiyama
at = s.search(cx);
if (at >= 0) {
warningAt("Unsafe character.", line, at);
}
+*/
return true;
}
@@ -3908,7 +3910,8 @@
for (var i = 0; i < JSLINT.errors.length; i += 1) {
var e = JSLINT.errors[i];
if (e) {
- print('Lint at line ' + (e.line + 1) + ' character ' +
+/* modified by M.Hiyama */
+ print(a[0] + ':' + (e.line + 1) + ': character ' +
(e.character + 1) + ': ' + e.reason);
print((e.evidence || '').
replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
@@ -3916,7 +3919,9 @@
}
}
} else {
+/* //omitted by M.Hiyama
print("jslint: No problems found in " + a[0]);
+*/
quit();
}
})(arguments);
âEmacsããJSLintã使ã
ãããæ¸ã¿ã®jslint.jsãé©å½ãªå ´æã«ã³ãã¼ãã¦ãä¾ãã°æ¬¡ã®ãããªããããã¡ã¤ã«ãä½ã£ã¦ããã¾ãã
@echo off
REM jslint-r.bat -- JSLint Rhinoçif "%JSLINT_JS%" == "" set JSLINT_JS=%HOME%\lib\jslint.js
call rhino-c "%JSLINT_JS%" %1
Emacsãã M-x compile ã¨ãã¦ãCompile command ã«jslint-r RingBuffer.js
ãæå®ããã¨ã次ã®ããã«ãªãã¾ãã
ï¼å寸大ï¼
Meadowã®å ´åãã·ã§ã«ã¨ãã¦CygwinãMSYSã®ã·ã§ã«ãæå®ãã¦ããã¨ãããããã¡ã¤ã«ããã¾ãå®è¡ã§ããªãï¼command not foundï¼ã¨ããããã®ã§æ³¨æãã¦ãã ããã次ã®å¼ãè©ä¾¡ããã°ãWindowsããããã¡ã¤ã«ãå®è¡ã§ããç¶æ³ã«ãªãã¾ãã
(setq explicit-shell-file-name "cmdproxy.exe")
(setq shell-file-name "cmdproxy.exe")
(setq shell-command-switch "/c")
âMakefileããJSLintã使ã
åã¯ãã·ã§ã«ããç´æ¥ã§ã¯ãªãã¦MakefileããJSLintãèµ·åãã¦ãã¾ãã
OK_FILES:=$(patsubst $(SRC_DIR)/%.js, $(BIN_DIR)/%.ok,$(SOURCES))
# ...lint: $(OK_FILES)
$(OK_FILES): $(BIN_DIR)/%.ok : $(SRC_DIR)/%.js
@echo "$< --> $@"
$(JSLINT_CMD) $< | tee $(SRC_DIR)/$(JSLINT_PREFIX)$<.lint
@if [ ! -s $(SRC_DIR)/$(JSLINT_PREFIX)$<.lint ]; then \
rm $(SRC_DIR)/$(JSLINT_PREFIX)$<.lint ; \
touch $@ ; \
fi
ã¦ã¼ã ãMakefileã«åã£ã¦ããé æ¸ãããã¤ã ãããç¡é§ã«è¤éã ã
ãããããã£ã