ClosureLinterが落ちてしまうとき
普段、JavaScriptのコードをlintするときはClosureLinterを使っているのですが、何故か実行できずに失敗して落ちてしまう原因がわかったのでメモしておきます。
コマンド
$ gjslint --strict --nojsdoc index.js Traceback (most recent call last): File "/usr/local/bin/gjslint", line 8, in <module> load_entry_point('closure-linter==2.3.11', 'console_scripts', 'gjslint')() File "/Library/Python/2.7/site-packages/closure_linter/gjslint.py", line 254, in main _PrintErrorRecords(records_iter_copy) File "/Library/Python/2.7/site-packages/closure_linter/gjslint.py", line 204, in _PrintErrorRecords for record in error_records: File "/Library/Python/2.7/site-packages/closure_linter/gjslint.py", line 126, in _CheckPaths results = _CheckPath(path) File "/Library/Python/2.7/site-packages/closure_linter/gjslint.py", line 142, in _CheckPath runner.Run(path, error_handler) File "/Library/Python/2.7/site-packages/closure_linter/runner.py", line 141, in Run stop_token=error_token) File "/Library/Python/2.7/site-packages/closure_linter/runner.py", line 193, in _RunChecker stop_token=stop_token) File "/Library/Python/2.7/ File "/Library/Python/2.7/ File "/Library/Python/2.7/ File "/LibrarxecutePass(start_token, self._LintPas File "/Library/Python/2.7/ File "/Library/Pythonka File "/Library/Python/2.7/ File "/Library/Python/2.7/ File "/Library/Python File "/Library/Python/2.7/ File "/Library/Python/2.7/ File "/Library/Python/2.7/ 154, in _LintPass self._lint_rules.Chec self._lint_rules.Chec self._lint_rules.Chec self._lint_rules.Chec self._lint_rules.Checptlintrules.py", line 513, in CheckToken if (previous_token.type == Type.KEYWORD and AttributeError: 'NoneType' object has no attribute 'type'
……エラーが出ます。
どうやら
(function() { // ... }());
に修正すると動作するみたいです。セミコロンを先頭に置くなということですかね。
なにか回避するオプションとかないんでしょうか。まあminifyなどの特に気をつけていれば必要もないのですが。