「JavaScriptの構文チェッカーJSLintをEmacsから使う」で紹介したJSLintは、evalがあると「evalはevil(邪悪)だ」と必ず文句を言います。そう言われてもevalを使いたいときはあります。例えば、安直なJSONデコーダを作りたい場合:
/* evil.js */
function decodeJson(jsonText) {
return eval('(' + jsonText + ')');
}
JSLintはこう言います。
evil.js:3: character 10: eval is evil.
return eval('(' + jsonText + ')');
あー、うるさい。こんなとき、次の呪文を書くとJSLintも黙るようです。
/* evil.js */
/*jslint evil: true */function decodeJson(jsonText) {
return eval('(' + jsonText + ')');
}
JSLintのソース内を探したら、次のようなオプション一覧がありました。evilと同様な方法でオプションを調整すると、余計なお節介をやめさせることができるでしょう。
// These are all of the JSLint options.allOptions = {
adsafe : true, // if use of some browser features should be restricted
bitwise : true, // if bitwise operators should not be allowed
browser : true, // if the standard browser globals should be predefined
cap : true, // if upper case HTML should be allowed
debug : true, // if debugger statements should be allowed
eqeqeq : true, // if === should be required
evil : true, // if eval should be allowed
forin : true, // if for in statements must filter
fragment : true, // if HTML fragments should be allowed
laxbreak : true, // if line breaks should not be checked
nomen : true, // if names should be checked
on : true, // if HTML event handlers should be allowed
passfail : true, // if the scan should stop on first error
plusplus : true, // if increment/decrement should not be allowed
rhino : true, // if the Rhino environment globals should be predefined
undef : true, // if variables should be declared before used
white : true, // if strict whitespace rules apply
widget : true // if the Yahoo Widgets globals should be predefined
},