Тёмный

How To Setup Next.JS with TypeScript, Prettier, ESLint and Husky 

Jarrod Watts
Подписаться 8 тыс.
Просмотров 40 тыс.
50% 1

Learn how to set up ESLint, Prettier, and Husky to consistently write and style your code. We'll be using a TypeScript and Next.JS project to demonstrate how you can set up Visual Studio to lint and format your code whenever you hit save, as well as setting up pre-commit hooks to check your code for style consistency using Husky.
Grab the code used in this video here:
github.com/jarrodwatts/code-l...
The resources I used in this video:
Prettier: prettier.io/
ESLint: eslint.org/
Husky: www.npmjs.com/package/husky
For the text version of this video, and step by step code snippets:
blog.jarrodwatts.com/nextjs-es...
Other helpful links:
- Text version of this video: blog.jarrodwatts.com/nextjs-e...
Find me:
- Website: jarrodwatts.com
- Twitter: / jarrodwattsdev
- GitHub: github.com/jarrodwatts
- Buy me a coffee: (www.buymeacoffee.com/jarrodwatts)
Timestamps:
0:00 - Introduction
0:47 - What we're building
1:12 - Creating the Next.JS App
1:39 - TypeScript
2:22 - ESLint
3:57 - Prettier
5:22 - Visual Studio Code
7:04 - Husky
9:09 - Important Note
9:52 - Conclusion
In this guide I'm going to run through how you can:
- Setup your Next.JS projects using Typescript, ESLint, Prettier, and Husky.
- Lint and format your code to align to the style rules you defined in config.
- Auto-format and auto-style your code whenever you click save.
- Check if your code meets all of your style rules before you git commit.
- Use and extend Google's Typescript style guidelines.

Наука

Опубликовано:

 

4 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 66   
@JarrodWatts
@JarrodWatts 3 года назад
Hey everyone! The other day Vercel announced Next.JS 11, which includes built-in support for ESLint. You can still follow this tutorial as it will work 100% - but if you are using Next.JS 11 you can now run "next lint" as a script in your package.json file as well. This next lint command will use your .eslintrc file, and will also include rules specific to Next.JS, (e.g. using tag instead of tag). All you'll need to do is just update to version 11, and add "next-lint": "next lint" as a script in your package.json file. Then run npm run next-lint. Read more here: blog.jarrodwatts.com/whats-new-in-nextjs-11
@danielbennett1192
@danielbennett1192 2 года назад
Great content, love this style of tutorial. Fast, well explained and no filler.
@samuel.nunezm1
@samuel.nunezm1 2 года назад
Simple, straight to the point and it worked perfectly for me. Thanks man!!
@danielnadar75
@danielnadar75 2 года назад
Thanks brother! This is now our config going forward! Keep up the awesome work.
@adimaralimuddin96
@adimaralimuddin96 Год назад
seems like a new great high quality channel. worth subscribing! thanks for the content by the way. real great help.!
@sanketss84
@sanketss84 2 года назад
Thank you this has been super helpful also your narration and flow is spot on.
@VimalMistry10
@VimalMistry10 2 года назад
Finally found right video for eslint 😍
@xenon4602
@xenon4602 3 года назад
Your video quality has a lot of potential. Keep up the good work
@JarrodWatts
@JarrodWatts 3 года назад
Thank you! Putting some decent time into editing them all together so I appreciate it!
@arabsight
@arabsight 2 года назад
thanks for the content, just a quick tip: you can run create-next-app with "--ts" flag to get a typescript project ready.
@frankbarros4362
@frankbarros4362 2 года назад
Such an excellent video - subscribed!
@vitorpereira7606
@vitorpereira7606 3 года назад
Awesome video man! I will surely use you video when I start my Next projects.
@JarrodWatts
@JarrodWatts 3 года назад
Thank you Vitor! It's an awesome tool to work with
@Fullflexno
@Fullflexno 2 года назад
Nice video. Cheers from Norway!👍👍
@petarkolev6928
@petarkolev6928 2 года назад
Thank you for the amazing video!
@jonathanrees47
@jonathanrees47 2 года назад
You are a wizard! Thank you for helping me satisfy my OCD and code more efficiently.
@m.rivaldiirawan2374
@m.rivaldiirawan2374 4 дня назад
ohh damn, Am I also OCD? 🥲
@hassaniyouness8024
@hassaniyouness8024 3 года назад
the first 30s second of the video made me like and subscribe the way y introduced the need for these tools is nice, keep the good work bro
@JarrodWatts
@JarrodWatts 3 года назад
Thank you bro! It takes a bit of time to edit the intros together, so that is really good to hear!
@hassaniyouness8024
@hassaniyouness8024 3 года назад
@@JarrodWatts it's worth it it will make you stand out from the others 😉
@andreas_keller
@andreas_keller 3 года назад
Awesome! And great editing as well ;-)
@JarrodWatts
@JarrodWatts 3 года назад
Thanks Andreas! I've been working hard on improving my editing, so that means a lot!
@RoshanKrSoni
@RoshanKrSoni 3 года назад
you deserve millions bro :) Thanks for this
@JarrodWatts
@JarrodWatts 3 года назад
Thank you so much Roshan! Glad you liked it.
@sharizart
@sharizart 2 года назад
great tutorial!
@ashiqdey
@ashiqdey 2 года назад
Awesome man
@leopolddelassence5224
@leopolddelassence5224 Год назад
thank you very much sir
@EagerEggplant
@EagerEggplant 2 года назад
I am ROFLing at those husky feedbacks xD
@MaganDesigns
@MaganDesigns 3 года назад
This is really awesome, Thank you. subbed.
@JarrodWatts
@JarrodWatts 3 года назад
Thank you so much Jirkoz!
@vucaotan9903
@vucaotan9903 2 года назад
Hope u make more vid like this
@alexandrn.5943
@alexandrn.5943 2 года назад
cool, thank you bro :)
@paulbrown6792
@paulbrown6792 3 года назад
Very Helpful :)
@JarrodWatts
@JarrodWatts 3 года назад
Thanks Paul! Really good to hear you found it helpful
@santhosh3374
@santhosh3374 3 года назад
I'm the 2000th viewer 🎉 Informative vid too!
@JarrodWatts
@JarrodWatts 3 года назад
Wooooo 🥳 thanks for being the 2000th viewer on my first ever 2000 view video! 😂 Really appreciate you watching and for the kind feedback!
@zubairimtiaz4986
@zubairimtiaz4986 Год назад
this setup saves a lot of headache.
@CuongNguyen-xw8qu
@CuongNguyen-xw8qu 3 года назад
thank you so much!
@JarrodWatts
@JarrodWatts 3 года назад
No worries! Really glad you found it helpful :)
@jasoncprince
@jasoncprince 3 года назад
Just a couple things I noticed. - The require-jsdoc rule was deprecated in ESLint v5.10.0 and can be disabled. - The react/react-in-jsx-scope rule will throw an error if a component files not import React. With React 17, which Next.js now ships with, it is no longer necessary to import React and thus this rule can be disabled.
@JarrodWatts
@JarrodWatts 3 года назад
Thanks a lot for sharing your wisdom Jason! I've pinned your comment so everyone else can see too
@bwanamaina
@bwanamaina 2 года назад
very nice 👌
@jacob8225
@jacob8225 Год назад
I follow your step, but when I enter npm run test-all, it shows Error while loading rule '@typescript-eslint/dot-notation': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.
@bosphoramus
@bosphoramus 3 года назад
thank you
@JarrodWatts
@JarrodWatts 3 года назад
No worries Tony, glad you found it helpful
@liam8469
@liam8469 3 года назад
Hi Thanx. The video is awesome, but I got some issue when config husky: Whenever I change something in pre-commit file (.husky/pre-commit), I will receive when I run git commit : fatal: cannot run .husky/pre-commit: No such file or directory But it works fine if I keep the original pre-commit file. Anyone with the same issue?
@mrjohn1172
@mrjohn1172 3 года назад
Thank you for the great content. But I'm confused because on my vscode, I already have linting errors without ESLint and only typescript. From where the linting come from in this case? Is TypeScript have a default linter included by default?
@JarrodWatts
@JarrodWatts 3 года назад
Hey mate, thanks for the kind feedback :) I don't know for sure since I can't see your code but maybe you have a VS Code extension installed, like the ESLint Extension for example. Another thing you might be seeing is the problems that the TypeScript compiler points out.
@mrjohn1172
@mrjohn1172 3 года назад
​@@JarrodWatts Damn that was a quick answer! Thank you for your response I really appreciate :) I don't have the ESLint Extension, but I have the default Nextjs tsconfig file which come with alot of default settings. And when I hover on a lint error, I see "TS" right next to the error message, so i'm guessing TypeScript really has a linter included but based on the tsconfig file? For example, when I import something that I don't use, it will warn me - exactly like ESLint does, so that's why I was a little bit confused. I'm a beginner also, so maybe I'm just stupid XD
@JohnGreen-qc5xb
@JohnGreen-qc5xb 3 года назад
whats the difference in just using the vs code extensions, compared to downlaoding them using npm i and setting up config files?
@JarrodWatts
@JarrodWatts 3 года назад
Hey John, Great question - I don't think I've ever actually tried it, honestly. I think there are a few reasons why you'd want the packages and the configuration rather than just the extensions: 1. The configuration will stay consistent across devices (all the devs on the team can have use the same configuration) with the use of config files in the codebase. 2. You can configure each of the packages rules to your choosing, including individual rules and settings for each extension in the config files. 3. You can run the tools on the command line, e.g. (format all of your code at once by running prettier --write .) or (check all of your files match your ESLint config by running eslint .) I think that the extensions are more of a VS Code specific thing as well. They are just there to underline errors in red or warnings in yellow in the IDE, and to sometimes give you the option to fix it automatically. Using the VS Code extensions also offer additional features with the autosave fixes and things like that with the .vscode folder configuration as I displayed - which is awesome. But really, I'd say the difference is that the core tools are the packages themselves, whereas the extensions are just helpers to help visualise problems in the IDE. Hope I answered your question, maybe someone else can add on if they notice anything missing. :-)
@supa1009
@supa1009 2 года назад
Good setup, I would only add lint-staged to husky, so that only staged files are linted.
@defilogic6726
@defilogic6726 2 года назад
These instructions are outdated with Next.JS 12 out. My .eslintrc.js isn't formatted correctly and I can't call prettier from the powershell. I don't know why. any ideas?
@aram5642
@aram5642 2 года назад
I don't understand why it is needed to install prettier to do the job eslint fixers could, and then shortly after installing Prettier - install yet another config package to avoid conflicts between Prettier and eslint.
@lulungsatrioprayuda9931
@lulungsatrioprayuda9931 Год назад
i have some of trouble sir when i try to install "prettier --write ." its throw argument like this "'prettier' is not recognized as an internal or external command, operable program or batch file." i have already path of npm at user but still doesnt work would you like to help me? thank you
@lulungsatrioprayuda9931
@lulungsatrioprayuda9931 Год назад
sad i found it the solution is must run it with"npx prettier --write ." and it will run as well hehe
@jacob8225
@jacob8225 Год назад
and one more bug, when I npx husky-init npm install, it shows git can't find out. To solve it, I move all files of project to root of directory
@drawwithraman3268
@drawwithraman3268 10 месяцев назад
@jacob8225 did you get any solution?
@Gohel95
@Gohel95 2 года назад
Thank You So Much, You saved my A**, BTW you have great voice. God Bless You.
@michaelscofield2469
@michaelscofield2469 Год назад
please make a new one
@alexk9836
@alexk9836 3 года назад
Why didn't you show how to use lint-staged? :(
@JarrodWatts
@JarrodWatts 3 года назад
Hey Alex, sorry about that - thanks for the feedback though! I personally haven't set up lint-staged in my projects, but I'd imagine that it's pretty similar to the tools I went through in the video. Let me know if I can help in any way!
@conceptcoder
@conceptcoder 2 года назад
Man... your a look like "Fireship"...
Далее
How To Setup Prettier, ESLint and Husky For Beginners
12:04
Next.js App Router: Routing, Data Fetching, Caching
14:32