[Front-End General] ESLint: .js を lint する

JSHint から乗り換えを検討。

[markdown]
> * [ESLint – Pluggable JavaScript linter](http://eslint.org/)

## Install

プロジェクトディレクトリにインストールする。

“`prettyprinted
% npm install –save-dev eslint
% $(npm bin)/eslint –version
v2.5.3
“`

### IDE

例えば atom に導入するには、下記でインストール。

“`prettyprinted
apm install linter-eslint
“`

## Config

`.eslintrc` を作成する。

“`prettyprinted
% $(npm bin)/eslint –init
? How would you like to configure ESLint? Use a popular style guide
? Which style guide do you want to follow? Google
? What format do you want your config file to be in? JSON
Successfully created .eslintrc.json file in /Users/****/projects
“`

`Installing eslint-config-google` まで実行してくれた。
生成直後は `”extends”: “google”` のみ。
[Specifying Environments](http://eslint.org/docs/user-guide/configuring#specifying-environments) の設定を加える。

“`json:.eslintrc.json
{
“extends”: “google”,
“env”: {
“browser”: true,
“node”: true,
“es6”: true,
“mocha”: true,
“jquery”: true
}
}
“`

例えば `jquery` が入っていないと下記のようなエラーが出る。

“`prettyprinted
% $(npm bin)/eslint source/javascripts/lib/*
/Users/****/projects/source/javascripts/lib/_basic.js
7:1 error ‘$’ is not defined no-undef
“`

## Usage

“`prettyprinted
% $(npm bin)/eslint source/javascripts/lib/*
/Users/****/projects/source/javascripts/lib/_smooth-scrolling.js
12:1 warning Line 12 exceeds the maximum line length of 80 max-len
✖ 1 problem (0 errors, 1 warning)
“`

## 補遺

> * [時代はESLint。JSLintでもJSHintでもなくESLint。 – Qiita](http://qiita.com/inuscript/items/dcf48f56d8f484c0a1a8)
> * [共有設定でらくらく ESLint – Qiita](http://qiita.com/mysticatea/items/dc35ced6bd5e782f50cd)
> * [ESLint v2.0.0 の変更点まとめ – Qiita](http://qiita.com/mysticatea/items/8bcecd821cca9e849078)

react(jsx)

> * [eslint-plugin-react](https://www.npmjs.com/package/eslint-plugin-react)
> * [ESLint 最初の一歩 – Qiita](http://qiita.com/mysticatea/items/f523dab04a25f617c87d)
[/markdown]