DEV Community

Cover image for Guide to ESLint & Prettier with Nuxt 3

Guide to ESLint & Prettier with Nuxt 3

Nikita on January 29, 2024

Introduction In this article, you will learn: How to set up a Nuxt project with ESLint and Prettier How to configure ESLint and Pretti...
Collapse
 
llops profile image
dani llops

Super useful, thanks!!

Collapse
 
pratik149 profile image
Pratik Rane

Thank you for explaining each step with the "why" behind it. Very rare to come across such detailed post!

It would have been nicer if you could have mentioned at the end how the final eslintrc.json, prettierrc.json and package.json files looked like, or may be an example git repo, if it is not too much ask for. 😄

Collapse
 
nikitadmitr profile image
Nikita • Edited

Appreciate it!

I've already deleted that tutorial project, but it might look like this

eslintrc.json

{
   "root": true,
   "extends": ["@nuxt", "plugin:prettier/recommended", "prettier"],
   "env": {
      "browser": true,
      "node": true
   }
}
Enter fullscreen mode Exit fullscreen mode

prettierc.json

{
   "endOfLine": "auto",
   "tabWidth": 3,
   "quoteProps": "consistent",
   "plugins": [
      "prettier-plugin-tailwindcss"
   ],
}
Enter fullscreen mode Exit fullscreen mode

package.json

{
   "name": "nuxt-app",
   "private": true,
   "type": "module",
   "scripts": {
      "build": "nuxt build",
      "dev": "nuxt dev",
      "generate": "nuxt generate",
      "preview": "nuxt preview",
      "postinstall": "nuxt prepare",
      "lint": "eslint .",
      "lint:fix": "eslint . --fix",
      "format": "prettier . --write"
   },
   "devDependencies": {
      "@nuxt/eslint-config": "^0.2.0",
      "@nuxtjs/eslint-module": "^4.1.0",
      "@nuxtjs/tailwindcss": "^6.11.2",
      "eslint": "^8.56.0",
      "eslint-config-prettier": "^9.1.0",
      "eslint-plugin-nuxt": "^4.0.0",
      "eslint-plugin-prettier": "^5.1.3",
      "nuxt": "^3.9.3",
      "prettier": "^3.2.4",
      "prettier-plugin-tailwindcss": "^0.5.11",
      "vue": "^3.4.14",
      "vue-router": "^4.2.5"
   }
}
Enter fullscreen mode Exit fullscreen mode

nuxt.config.ts

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
   devtools: { enabled: true },
   modules: [
      "@nuxtjs/eslint-module"
   ]
});
Enter fullscreen mode Exit fullscreen mode
Collapse
 
nurlan_tl profile image
Nurlan TL

Why I get:
admin@iMac myProject % npm run lint

lint
eslint .

Oops! Something went wrong! :(

ESLint: 8.57.0
No files matching the pattern "." were found.

It is fresh Nuxt installation, and all done as you say.

Collapse
 
nurlan_tl profile image
Nurlan TL

Fixed. Need to add .eslintrc.cjs:
module.exports = {
root: true,
extends: ["@nuxt/eslint-config"],
};

Collapse
 
nikitadmitr profile image
Nikita • Edited

Yeap, thank you. I've edited the comment