LoginSignup
12
7

More than 5 years have passed since last update.

eslintの設定

Posted at

流行りのJavaScript検証の設定メモ

参考

@mysticatea さんの記事を参考させていただきました。

準備

今の自分の環境

  • node.js v8.9.4
  • npm 5.6.0

ESlint設定

インストール

今回はグローバルではなくローカル環境

npm init //package.jsonを作成
npm install eslint //作成したpackage.jsonにeslintがあることを確認 

ルール設定

.eslintrc.jsonを作成して各ルールをかく
ルールを細かく書くと長くなるので大雑把に

ECMAScript 2015 (ES6)はtrue


  "env": {
    "browser": true,
    "es6": true
  }

jQueryを使用するので設定追加
https://www.npmjs.com/package/eslint-plugin-jquery

npm install eslint-plugin-jquery --save-dev

.eslintrc.json


{
  "plugins": [
    "jquery"
  ],
  "rules": {
  }
}

このままだとjQueryで怒られた


$(function () {
});
// "$" is not defined no-undefと怒られた

.eslintrc.jsonにjQueryの記述を追加

{
  "env": {
    "jquery": true
  }
}

これで解消

ルールは共有設定を使用@mysticatea さんのとおりにeslint-config-eslint
他にもgoogleのeslint-config-googleがある。

12
7
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
7