DEV Community

Cover image for Gridsome + Eslint: the complete Guide
David Couronné
David Couronné

Posted on

10 2

Gridsome + Eslint: the complete Guide

While VueJS has the great Vue Cli tool, Gridsome has "not yet" the equivalent.

To install and configure Eslint, we must install our dependencies by hand.

Install dev dependencies

This article assumes that you already have a Gridsome project installed. If not, you can consult the list of starters on this page: Gridsome Starters.

As Gridsome is based on Vuejs, we will use the same recommended tools:

yarn add eslint prettier @vue/cli-service @vue/cli-plugin-eslint @vue/eslint-config-prettier eslint-plugin-vue eslint-plugin-prettier babel-eslint -D

You have time to have a coffee during the installation !

Configurations files

In your root directory, create two files: .prettierrc.js and .eslintrc.js

// .prettierrc.js
module.exports = {
  singleQuote: true,
  semi: false
}

And:

// .eslintrc.js
module.exports = {
  root: true,
  env: {
    node: true
  },
  extends: [
    'plugin:vue/essential',
    'plugin:prettier/recommended',
    '@vue/prettier'
  ],
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
  },
  parserOptions: {
    parser: 'babel-eslint'
  },
  overrides: [
    {
      files: [
        '**/__tests__/*.{j,t}s?(x)',
        '**/tests/unit/**/*.spec.{j,t}s?(x)'
      ],
      env: {
        jest: true
      }
    }
  ]
}

Now, you have to add a script in your package.json file:

// package.json
"scripts": {
    "build": "gridsome build",
    "develop": "gridsome develop",
    "explore": "gridsome explore",
    "lint": "vue-cli-service lint"
  },

And just run:

yarn lint

Happy coding !

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay