Skip to content

Instantly share code, notes, and snippets.

@saifulapm
Last active March 28, 2023 13:34
Show Gist options
  • Select an option

  • Save saifulapm/27137bb401899751f39b8ae4fa1e93ba to your computer and use it in GitHub Desktop.

Select an option

Save saifulapm/27137bb401899751f39b8ae4fa1e93ba to your computer and use it in GitHub Desktop.
Setting up ESLint and Prettier for NextJs

ESLint requires a few additional configurations to be set up optimally for use with Next JS.

To start off with, install eslint, eslint-plugin-react,

npm i --save-dev eslint eslint-plugin-react

Next, create a .eslintrc file using the following:

eslint --init

Use the arrow keys to select: Use a popular style guide -> Standard -> JSON. Install any additional dependencies required.

An eslintrc.json file will be created.

Add the following to your .eslintrc.json file:

{
  "extends": [
    "eslint:recommended",
    "plugin:react/recommended"
  ],
  "rules": {
    "react/react-in-jsx-scope": "off",
    "react/prop-types": 0
  },
  "globals": {
    "React": "writable"
  }
}

Note the “react/react-in-jsx-scope”: “off” under rules, and “React” under “globals”. Without these, you will get errors since NextJs does not require you to import React into each component.

Hope this helps!

Note: If you’re using Visual Studio Code and ESLint is still not working, try updating your Visual Studio Code.

Create .prettierrc in the root of your project and add the following:

{
  "trailingComma": "es5",
  "tabWidth": 2,
  "semi": false,
  "singleQuote": true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment