Closure Linter の使用方法
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
注: Closure Linter は非推奨であり、Google 内でもほとんど使用されなくなっています。詳しくは、こちらのページをご覧ください。
このドキュメントでは、Closure Linter のインストール方法と使用方法について説明します。
Closure Linter をインストールする
Python の pip
ユーティリティを使用して、Closure Linter をダウンロードしてインストールします。
Linux
Linux に Closure Linter をインストールするには、次のコマンドを実行します。
$ sudo apt-get install python-pip
$ sudo pip install https://github.com/google/closure-linter/zipball/master
Mac OS X
Mac OS X に Closure Linter をインストールするには、次のコマンドを実行します。
$ sudo easy_install pip
$ sudo pip install https://github.com/google/closure-linter/zipball/master
Windows
Windows に Closure Linter をインストールするには:
- Windows 用 Python をダウンロードしてインストールします。
- 次のコマンドを実行します。
> pip install https://github.com/google/closure-linter/zipball/master
注: Closure Linter の Windows サポートは試験運用です。
スタイルの問題を検出する
単一のファイルで Closure Linter を実行するには、次のようにします。
$ gjslint path/to/my/file.js
次のような結果が表示されます。
Line 46, E:0110: Line too long (87 characters).
Line 54, E:0214: Missing description in @return tag
Line 66, E:0012: Illegal semicolon after function declaration
Line 150, E:0120: Binary operator should go on previous line "+"
Line 175, E:0011: Missing semicolon after function assigned to a variable
Line 210, E:0121: Illegal comma at end of array literal
Line 220, E:0002: Missing space before ":"
次のように、ディレクトリ全体を再帰的にチェックすることもできます。
$ gjslint -r path/to/my/directory
デフォルトでは、Closure Linter は正しい JsDoc アノテーションの存在を確認します。プロジェクトで JsDoc アノテーションの欠落をチェックしない場合は、次のようにチェックを無効にします。
$ gjslint --nojsdoc -r path/to/my/directory
このフラグは JsDoc アノテーションの欠落に関するチェックを無効にしますが、既存の JsDoc アノテーションが正しく使用されているかどうかはリンターによって検証されます。
--strict フラグ
Closure Linter で、スペーシング、JsDoc 型、author タグなどのスタイル ルールをより厳密に適用する場合は、--strict
コマンドライン フラグを使用します。Closure Library にコードを投稿する場合は、--strict
を使用する必要があります。
スタイルの問題を修正する
上記のコマンドのいずれかで、gjslint
を fixjsstyle
に置き換えると、gjslint
がチェックするエラーの多くが自動的に修正されます。
次に例を示します。
$ fixjsstyle path/to/file1.js path/to/file2.js
fixjsstyle
を使用する前に、スクリプトが不要な変更を行う場合に備えて、ファイルをバックアップするか、ソース管理システムに保存する必要があります。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-26 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-26 UTC。"],[[["\u003cp\u003eClosure Linter, although deprecated and rarely used within Google, is a tool for identifying and fixing JavaScript style issues.\u003c/p\u003e\n"],["\u003cp\u003eIt can be installed using pip on Linux, Mac OS X, and Windows, with Windows support being experimental.\u003c/p\u003e\n"],["\u003cp\u003eClosure Linter can analyze single files or entire directories for style problems, providing detailed error messages.\u003c/p\u003e\n"],["\u003cp\u003eThe tool allows for automatic fixing of many style errors using the \u003ccode\u003efixjsstyle\u003c/code\u003e command, but it's recommended to back up files beforehand.\u003c/p\u003e\n"],["\u003cp\u003eFor stricter style checks and contributions to Closure Library, use the \u003ccode\u003e--strict\u003c/code\u003e flag.\u003c/p\u003e\n"]]],[],null,["# How to Use Closure Linter\n\nNote: Closure Linter is deprecated, and is rarely used anymore within Google.\nSee [this page](https://developers.google.com/closure/utilities/) for more information\n\n\nThis document describes how to install and use Closure Linter.\n\nInstall Closure Linter\n----------------------\n\nUse the Python `pip` utility to download and\ninstall Closure Linter.\n\n### Linux\n\nTo install Closure Linter on Linux, execute the following commands: \n\n```\n$ sudo apt-get install python-pip\n$ sudo pip install https://github.com/google/closure-linter/zipball/master\n```\n\n### Mac OS X\n\nTo install Closure Linter on Mac OS X, execute the following command: \n\n```\n$ sudo easy_install pip\n$ sudo pip install https://github.com/google/closure-linter/zipball/master\n```\n\n### Windows\n\nTo install Closure Linter on Windows:\n\n1. Download and install [Python for\n Windows.](http://www.python.org/download/windows/)\n2. Execute the following command:\n\n```\n\u003e pip install https://github.com/google/closure-linter/zipball/master\n```\n\n**Note:** Windows support for Closure Linter is\nexperimental.\n\nFind Style Problems\n-------------------\n\nTo run the Closure Linter on a single file, try: \n\n```\n$ gjslint path/to/my/file.js\n```\n\nYou should see results like this: \n\n```\nLine 46, E:0110: Line too long (87 characters).\nLine 54, E:0214: Missing description in @return tag\nLine 66, E:0012: Illegal semicolon after function declaration\nLine 150, E:0120: Binary operator should go on previous line \"+\"\nLine 175, E:0011: Missing semicolon after function assigned to a variable\nLine 210, E:0121: Illegal comma at end of array literal\nLine 220, E:0002: Missing space before \":\"\n```\n\nYou can also recursively check an entire directory, like this: \n\n```\n$ gjslint -r path/to/my/directory\n```\n\nBy default, the Closure Linter checks for the presence of correct\nJsDoc annotations. If you don't want to check for missing JsDoc\nannotations in your project, disable the check like this: \n\n```\n$ gjslint --nojsdoc -r path/to/my/directory\n```\n\nAlthough this flag disables checks for missing JsDoc annotations,\nthe linter still verifies that existing JsDoc annotations are used\ncorrectly.\n\n### The --strict Flag\n\nIf you want Closure Linter to be more strict about style rules like\nspacing, JsDoc types, and author tags, use the `--strict`\ncommand line flag. You must use `--strict` if you are contributing\ncode to the [Closure\nLibrary](/closure/library).\n\nFix Style Problems\n------------------\n\nIn any of the above commands, you can substitute `fixjsstyle` for\n`gjslint` to automatically fix many of the errors\nthat `gjslint` checks for.\n\nFor example: \n\n```\n$ fixjsstyle path/to/file1.js path/to/file2.js\n```\n\nYou should back up your files or store them in a source control\nsystem before using `fixjsstyle`, in case the script makes\nchanges that you don't want."]]