19
7

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 1 year has passed since last update.

Nuxt 3 with ESLint

Posted at

概要

Nuxt3でESLintを設定する方法

手順

1. ESLintをインストール

$ yarn add -D eslint eslint-plugin-vue
$ yarn add -D typescript @typescript-eslint/eslint-plugin @typescript-eslint/parser @nuxtjs/eslint-config-typescript

2. ESLintを初期化

$ yarn run eslint --init

# 以下を選択
> To check syntax and find problems
> JavaScript modules (import/export)
> Vue.js
> Does your project use TypeScript? Yes
> Where does your code run? Node (※スペースキーで選択)
> What format do you want your config file to be in? JavaScript
> Would you like to install them now with npm? No

3. 設定ファイルを修正

.eslintrc.js
module.exports = {
    "env": {
        "es2021": true,
        "node": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:vue/essential",
        "plugin:@typescript-eslint/recommended",
        "@nuxtjs/eslint-config-typescript" // ここを追加
    ],
    "parserOptions": {
        "ecmaVersion": 13,
        "parser": "@typescript-eslint/parser",
        "sourceType": "module"
    },
    "plugins": [
        "vue",
        "@typescript-eslint"
    ],
    "rules": {
    }
};

4. スクリプトを追加

package.json
"scripts": {
  "dev": "nuxi dev",
  "build": "nuxi build",
  "start": "node .output/server/index.mjs",
  "lint": "eslint --ext .ts,.js,.vue ."  // 追加
},

5. 実行

$ yarn lint

完了!!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?