0
0

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 3 years have passed since last update.

vueのeslintとかprettierの設定をしよう!!

Posted at

vueでwebサイトを作っていくよ

備忘録としてだから、気にせず書いていこう

まずはvueをcreateするよ

vue create hoge

その後の設定は以下

? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, Router, Linter
? Use history mode for router? (Requires proper server setup for index fallback 
in production) Yes
? Pick a linter / formatter config: Prettier
? Pick additional lint features: Lint on save
? Where do you prefer placing config for Babel, ESLint, etc.? In package.json
? Save this as a preset for future projects? No

eslintとかの設定を頑張ろう

eslintの設定を変えていく

yarn eslint --init

yarn run v1.22.10
? How would you like to use ESLint? To check syntax and find problems
? What type of modules does your project use? JavaScript modules (import/export)
? Which framework does your project use? Vue.js
? Does your project use TypeScript? No
? Where does your code run? Browser
? What format do you want your config file to be in? JavaScript
The config that you've selected requires the following dependencies:

eslint-plugin-vue@latest
? Would you like to install them now with npm? Yes

よくわからなかったけど、下の記事を参考にしました
最初の初期設定でpackage.jsonに設定を書く。みたいな設定にしちゃったけど大丈夫かな笑
PrettierとESLintをVSCodeで使う(Vue)

記事通り.eslintrc.jsに追加
ちょっとエラー出ちゃったので、そこだけ変えました

module.exports = {
    env: {
        browser: true,
        es6: true,
    },
    extends: [
        "eslint:recommended",
        "plugin:vue/essential",
        "plugin:prettier/recommended",
    ],
    globals: {
        Atomics: "readonly",
        SharedArrayBuffer: "readonly",
    },
    parserOptions: {
        ecmaVersion: 2018,
        sourceType: "module",
    },
    plugins: ["vue", "prettier"],
    rules: {
        "prettier/prettier": "error",
    },
};

記事ではprettierrcにも追加しているけど、今回はしない

.vscodeのsetting.jsonに以下を追加

{
    "workbench.colorTheme": "Default Light+", //ワークベンチのテーマ デフォルトの白
    "editor.codeActionsOnSave": {
        "source.fixAll.eslint": true,
        "source.organizeImports": true,
        "source.fixAll": true
    },
    "editor.formatOnPaste": false,
    "editor.formatOnSave": false,
    "editor.formatOnType": true,
    "eslint.validate": ["javascript", "javascriptreact", "vue", "typescript"],
    "vetur.format.defaultFormatter.css": "prettier",
    "vetur.format.defaultFormatter.scss": "prettier",
    "vetur.format.defaultFormatter.html": "prettier",
    "vetur.format.defaultFormatter.js": "prettier-eslint",
    "vetur.format.defaultFormatter.ts": "vscode-typescript",
    "vetur.validation.template": false
}

設定完了!!

おお、、これらをやったらいい感じにeslintも動くし、色とかもいい感じだ!!
あとは、eslintignoreとか今度作ろうかな

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?