7
4

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.

ESlint, prettierを使ってjavascript, vueのコード品質を保つ

Last updated at Posted at 2019-09-24

scssのコード品質については stylelint,prettierを使ってscssのコード品質を保つ - Qiitaを参考。
また、.js.vueが混在しているプロジェクトを想定。(.jsについてはjQueryも使っている想定)

eslint, prettierをインストール

$ yarn add babel-eslint eslint eslint-config-airbnb eslint-config-prettier eslint-plugin-import eslint-plugin-prettier eslint-plugin-vue

参考

prettierrcの設定・.eslintrc.jsonの設定

.prettierrc

{
  "printWidth": 120,
  "tabWidth": 2,
  "useTabs": false,
  "singleQuote": true,
  "proseWrap": "preserve"
} 

参考

.eslintrc.json

.eslintrc.json
{
  "env": {
    "es6": true,
    "browser": true,
    "jquery": true // if use $
  },
  "plugins": [
    "import"
  ],
  "parserOptions": {
    "parser": "babel-eslint",
    "sourceType": "module",
    "allowImportExportEverywhere": false
  },
  "extends": [
    "airbnb-base",
    "eslint:recommended",
    "plugin:vue/recommended",
    "plugin:prettier/recommended"
  ],
  "globals": {
    "gon": true
  },
  "rules": {
    "semi": [
      "error",
      "never"
    ],
    "comma-dangle": [
      "error",
      "never"
    ],
    "no-param-reassign": [
      "error", {
        "ignorePropertyModificationsFor": [
          "state"
        ]
      } 
    ],
    "prettier/prettier": [
      "error",
      {
        "printWidth": 120,
        "singleQuote": true,
        "trailingComma": "none",
        "semi": false
      }
    ]
  }
}

参考

package.json(npm script)

app/frontend/javascriptsよりも下にjs,vueファイルを入れている場合。

{
  "scripts": {
    "lint:javascript": "eslint --fix app/frontend/javascripts/**/*.{js,vue}"
  },
}
7
4
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?