Eslint and Prettier, are the most used npm packages in all Modern JavaScript Applications.
However, I noticed they're not being utilized to their fullest potential. That's purely a personal preference, but as the project grows, so does the requirements to tweak configurations to improve the team's productivity and the overall performance of the app. You can check out my article on Eslint made easy breaking down Eslint for you.
For now, let's focus on quickly setting up Next.js.
For Next.js, I'm going to divide this article into two sections, based on complexities and the number of plugins we have to integrate into the project:
- The Basic Setup ๐ฑ
- The Pro Setup ๐ฏ
The Basic Setup ๐ฑ
First install the ESLint and Prettier using following commands:
Following is the Prettier setting I use in my projects and this remains same for the Pro Setup as well. I encourage you to edit this file as per your preferences. Checkout this document for further details on more options available.
Let's add a few more of these popular plugins, and get you started with having Basic Linting in your project ๐ ย
Run following command:
Add the following config. to your .eslintrc.js
, and you're good to go :
The Pro Setup ๐ฏ
๐Adding More Plugins
The main difference setting Pro apart from The Basic setup, is that the Pro flaunts a few more plugins, more awesome and ย customizable ones ๐ฉโ๐จ. ย
This is the setup I personally use, in all my Next.js projects.
Now, add the following to your .eslintrc.js
file, and you are good to go. I have explained most use cases for the following plugin, in this post.
๐Setting Up Husky
Husky gives you the ability to add precommit hooks. It works as your third eye, protecting your project from that sneaky smelly code, from being pushed into, or committing to - forcing people to follow the guidelines added by you.
after that, add this to your ย package.json
ย file:
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx}": [
"eslint '*/**/*.{js,jsx}' --fix"
]
},
That's it : and you are good to go. ๐
TlDr; ๐๐ฝโโ๏ธ
You can simply copy them from here ๐
Conclusion
Hopefully, you have learned something new here. I will be posting few more articles in this Next Station series of Next.js, so subcribe to get notified. Also we have weekly discussion on dev.to every Wednesday and Saturday.
Thanks again, if you have any queris reach out to me @sarthology