12
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JSHintでJavaScriptの予約語をチェックする

Posted at

チェックに使った.jshintrcはこちら
.jshintrc日本語版 - Qiita

以下のリストはO'Reilly Japan - JavaScript 第6版#2.4.1 予約語より抜粋。

"Not error"とコメントされていないのは全て(正しく)エラーになっている。

example.js
	// 予約語
	var break = 1;
	var delete = 1;
	var function = 1;
	var return = 1;
	var typeof = 1;
	var case = 1;
	var do = 1;
	var if = 1;
	var switch = 1;
	var var =1;
	var catch = 1;
	var else = 1;
	var in = 1;
	var this = 1;
	var void = 1;
	var continue = 1;
	var false = 1;
	var instanceof = 1;
	var throw = 1;
	var throw = 1;
	var while = 1;
	var debugger = 1; // Debug: trueなのにError
	var finally = 1;
	var new = 1;
	var true = 1;
	var with = 1;
	var default = 1;
	var for = 1;
	var null = 1;
	var try = 1;

 	// 将来に向けての予約語
	var class = 1;
	var const = 1;
	var enum = 1;
	var export = 1;
	var extends = 1;
	var import = 1;
	var super = 1;

	// strictモードでは予約語
	var implements = 1;
	var let = 1;
	var private = 1;
	var public = 1;
	var yield = 1;
	var interface = 1;
	var package = 1;
	var protected = 1;
	var static = 1;
	var arguments = 1;
	var eval = 1;

	// JAVAの予約語
	var abstract = 1;
	var double = 1;
	var goto = 1;
	var native = 1;
	var static = 1;
	var boolean = 1;
	var enum = 1;
	var implements = 1;
	var package = 1;
	var super = 1;
	var byte = 1;
	var export = 1;
	var import = 1;
	var private = 1;
	var synchronized = 1;
	var char = 1;
	var extends = 1;
	var int = 1;
	var protected = 1;
	var throws = 1;
	var class = 1;
	var final = 1;
	var interface = 1;
	var public = 1;
	var transient = 1;
	var const = 1;
	var float = 1;
	var long = 1;
	var short = 1;
	var volatile = 1;

	// グローバル変数/関数
	var arguments = 1;
	var encodeURI = 1; // Not error
	var Infinity = 1;
	var Number = 1; // Not error
	var RegExp = 1; // Not error
	var Array = 1; // Not erro
	var encodeURIComponent = 1; // Not error
	var isFinite = 1; // Not error
	var Object = 1; // Not error
	var String = 1; // Not error
	var Boolean = 1; // Not error
	var Error = 1; // Not error
	var isNan = 1; // Not error
	var parseFloat = 1; // Not error
	var SyntaxError = 1; // Not error
	var Date = 1; // Not Error
	var eval = 1;
	var JSON = 1; // Not Error
	var parseInt = 1; // Not Error
	var TypeError = 1; // Not Error
	var decodeURI = 1; // Not Error
	var EvalError = 1; // Not Error
	var Math = 1; // Not Error
	var RangeError = 1; // Not Error
	var undefined = 1;
	var decodeURIComponent = 1; // Not Error
	var Function = 1; // Not Error
	var NaN = 1; // Not Error
	var ReferenceError = 1; // Not Error
	var URIError = 1; // Not Error

結果

グローバル変数/関数がほとんどチェックされない

以下のようなのが通ってしまうのはどうしたものか。。

example.js
var encodeURI = 1;
encodeURI("a");
// NotError

debuggerのエラー抑制がされない

.jshintrcのdebugオプションをtrueにしてもエラーに。

12
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?