How To Setup Prettier

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ส.ค. 2024
  • Prettier is one of my favorites tools for writing clean and easy to read code since it does all the formatting for you. In this video I will show you how to setup Prettier, how to use it in your IDE, how to configure it with ESLint, and a few other small Prettier tips.
    🌎 Find Me Here:
    My Blog: blog.webdevsimplified.com
    My Courses: courses.webdevsimplified.com
    Patreon: / webdevsimplified
    Twitter: / devsimplified
    Discord: / discord
    GitHub: github.com/WebDevSimplified
    CodePen: codepen.io/WebDevSimplified
    ⏱️ Timestamps:
    00:00 - Introduction
    00:38 - Installation
    01:35 - Command Line Usage
    02:51 - Integrating Into VSCode
    06:18 - Ignoring Files
    08:00 - Configuration Options
    09:55 - Using With Eslint
    #Prettier #WDS #JavaScript

ความคิดเห็น • 112

  • @Outplayedqt
    @Outplayedqt ปีที่แล้ว +14

    Gosh, I’ve been curious about the ACTUAL correct way of setting Prettier up. Thanks again for such an eloquent yet concise tutorial!

  • @justingolden21
    @justingolden21 ปีที่แล้ว +5

    Great comprehensive yet short and sweet intro to Prettier. I knew 2/3rds of this stuff, but it's good to have all this in one place. A great video to start or to link to someone starting.

  • @maacpiash
    @maacpiash ปีที่แล้ว +1

    Excellent video. The last part was really helpful. Whenever I start a new project, one of the hardest things to get right is to configure ESLint and Prettier to work well with each other. Great job explaining that bit.

  • @redemptionokoro8274
    @redemptionokoro8274 ปีที่แล้ว +3

    This is sorcery. I was kind of struggling with prettier and eslint for the past two days now. Nice one kyle

  • @christophersavasta5222
    @christophersavasta5222 ปีที่แล้ว +1

    You read my mind! I was just having trouble setting this up last week. And now I know why. Thanks.

  • @aliimran7051
    @aliimran7051 ปีที่แล้ว

    Excellent video that covers all the essential information a developer should be aware of.

  • @IhorVyshniakov
    @IhorVyshniakov 5 หลายเดือนก่อน

    Very appreciating your last part 09:55 about "Using With Eslint"!!!
    Thank you a lot

  • @GeneralistDev
    @GeneralistDev ปีที่แล้ว

    Was trying this for so long... finally you are here❤️

  • @cristianmonroy3897
    @cristianmonroy3897 ปีที่แล้ว

    I've already finished a node.js back-end course and my teacher magically made the .prettierrc file work when he saved the changes of a file, but i didn't get why. With this tutorial I understood why it is. Thanks a lot, you rock.

  • @cryptonews5253
    @cryptonews5253 ปีที่แล้ว

    Loved your videos Web dev and all your courses specially JS Simplified

  • @arogueotaku
    @arogueotaku ปีที่แล้ว +2

    Awesome video Kyle. Would be awesome to see a similar video made for ESLint also.

  • @cold_
    @cold_ ปีที่แล้ว +2

    This tutorial on how to set up Prettier was incredibly helpful! The presenter did a great job of explaining the benefits of using Prettier and demonstrated each step clearly and concisely. The visual presentation of the video made it easy to follow along and understand each concept, and the tips and insights provided throughout the tutorial were very helpful. Thanks to this video, I was able to set up Prettier in my JavaScript project quickly and easily. I highly recommend this tutorial to anyone looking to improve their code formatting and simplify their workflow.

    • @hi-ew2ox
      @hi-ew2ox ปีที่แล้ว

      gpt ass comment

  • @arcz15
    @arcz15 ปีที่แล้ว +1

    I always wanted to start using it but never know right way to actually it set up. Thanks!

  • @markopolo2224
    @markopolo2224 ปีที่แล้ว

    this couldnt have been come out at a better time
    for some reason my prettier stopped working and this will be so helpfull
    thank you so much

  • @theisoj
    @theisoj ปีที่แล้ว

    Very nice tutorial! Thanks Kyle!

  • @kabijoshi5949
    @kabijoshi5949 11 หลายเดือนก่อน

    You are fking very smart. A real time saver for dummies like myself. Thumbs up man.
    Keep it up and thanks.

  • @kayodekehinde3756
    @kayodekehinde3756 5 หลายเดือนก่อน

    Thank you Kyle nice teaching...

  • @coderawesome
    @coderawesome 8 หลายเดือนก่อน

    On point! Thanks Kyle.

  • @ahmedalaaezzat
    @ahmedalaaezzat 8 หลายเดือนก่อน

    Thank you that was super useful ❤

  • @user-ky8dr1hu5e
    @user-ky8dr1hu5e ปีที่แล้ว

    Very useful! Thnx a lot!

  • @gabrielanzaldoalvarado.2380
    @gabrielanzaldoalvarado.2380 หลายเดือนก่อน

    clear and concise 🙌

  • @carlotadias9335
    @carlotadias9335 8 หลายเดือนก่อน

    nice video ! thank you

  • @Krzysiekoy
    @Krzysiekoy ปีที่แล้ว +4

    11:25 Interesting. I tend to go 1 step further and instead of running npx eslint-config-prettier and manually turning off conflicting rules, I just make eslint use prettier as a formatter. So in my eslint config I just do "extends": ["some-config-you-extend", "plugin:prettier/recommended"]. It's not necessary but this way eslint is using prettier as its plugin and there is zero chance for any conflicts.

  • @UmarHamza
    @UmarHamza ปีที่แล้ว

    Great video

  • @Ald0Abdiel
    @Ald0Abdiel ปีที่แล้ว

    Awesome video :)

  • @samislam2746
    @samislam2746 7 หลายเดือนก่อน

    The good thing in this channel is you don't waste our time

  • @FidlyBass
    @FidlyBass ปีที่แล้ว

    good stuff ✌

  • @andrewwalkerscotland
    @andrewwalkerscotland ปีที่แล้ว

    Great tutorial as usual. Triggered my OCD in the title though using the word 'setup' as a verb, grrr!

  • @PhoneBizone
    @PhoneBizone 2 หลายเดือนก่อน

    thanks buddy

  • @user-zx9xw4hw1j
    @user-zx9xw4hw1j ปีที่แล้ว

    Great video! can you do one with eslint? and maybe the configure it with prettier?

  • @alagunoff
    @alagunoff ปีที่แล้ว

    Thanks

  • @e-benz
    @e-benz ปีที่แล้ว

    love WebStorm

  • @harmez7
    @harmez7 ปีที่แล้ว

    you're good boy Kyle

  • @BezzantSam
    @BezzantSam ปีที่แล้ว +2

    You should change the intro music to a death metal riff

  • @BGdev305
    @BGdev305 ปีที่แล้ว

    Would really like for you to do an updated how YOU have setup VS Code and live browser updating. I know you did this some years ago, but things have changed.

  • @imadbenmadi
    @imadbenmadi 10 หลายเดือนก่อน

    bro yr amaizing

  • @geniuskingsley6747
    @geniuskingsley6747 ปีที่แล้ว

    Nice ❤

  • @xaiwnl
    @xaiwnl ปีที่แล้ว

    That thumbnail like how you'd even manage to get the before bit 💀💀💀

  • @themarksmith
    @themarksmith ปีที่แล้ว +3

    When trying prettier for Tailwindcss in VS Code it always complains about my using closing semanitc HTML tags - Not sure why so I always end up disabling Prettier - anyone have any ideas?

  • @alwayzsmarter
    @alwayzsmarter ปีที่แล้ว +2

    i dont have text editor option to select prettier

  • @tamasmolnar4157
    @tamasmolnar4157 3 หลายเดือนก่อน

    Hi Kyle, ESLint 9.0.0 is out (breaking changes). If you have time/will, please make a video on ESLint and Prettier in a node.js typescript project (e.g. Nest.js).
    It would be really appreciated. Thanks in advance.

  • @999hibuki
    @999hibuki ปีที่แล้ว

    thaksn

  • @PieterWigboldus
    @PieterWigboldus 5 หลายเดือนก่อน

    Using the actual version is a personal choice. But if prettier isnt using semver and break things in minor versions, than this would be an advice, or use something better that use semver.
    If you want to use the exact version or use the ^ should just be a personal preference.

  • @alanproduction910
    @alanproduction910 ปีที่แล้ว

    please make a tutorial video about how to connect PHP to REACT and how we use them together ...

  • @abdulazeez.98
    @abdulazeez.98 ปีที่แล้ว

    There is also an awesome trick you can use. Write a comment with “prettier-ignore” and it will ignore the next code block (i.e. function, loop..). It’s useful when you have a long line and you don’t want it to wrap.

  • @SaarC-rm2go
    @SaarC-rm2go ปีที่แล้ว +1

    What's the difference between just clicking Alt+Shift+F?

  • @hojdog
    @hojdog ปีที่แล้ว +1

    I've been using eslint and prettier for years and I still spend a day or two trying to configure them every time I start a new project, and it never works out as I like anyway and I just settle for whatever doesn't break in the end 😅

    • @MrJoey5
      @MrJoey5 ปีที่แล้ว

      This sounds awful tbh

  • @sfox-j
    @sfox-j ปีที่แล้ว +1

    Kyle, you could use -D instead of --save-dev. It uses less effort.

  • @gosnooky
    @gosnooky ปีที่แล้ว

    I just use eslint for both. I don't see why we need a separate dependency and editor plugin to perform the 5 or so tasks that eslint can handle just fine.

  • @boopathisakthivel6901
    @boopathisakthivel6901 ปีที่แล้ว

    Will prettier works with all framework files ? For eg, *.feature files. I have prettier that works with react/typescript/css files except this automation files.

  • @sogggy
    @sogggy ปีที่แล้ว +2

    Can you do a random video playing the guitar behind you?

  • @darrylbrian
    @darrylbrian ปีที่แล้ว

    Is it possible to set up Prettier to use the Airbnb Javascript style guide?

  • @nageshpatel889
    @nageshpatel889 ปีที่แล้ว

    How can we do production ready webpack configuration in react app..?

  • @aram5642
    @aram5642 ปีที่แล้ว +2

    This is actually the development area that gets me p.ssed off. There is too many of those formatting tools around, and none of them is either complete or cross-platform/cross-IDE. Prettier, editorconfig, eslint fixers, and then ide plugins or internal settings. I wish I could only use liny fixers with the vast gamut of options webstorm offers.

  • @fantasyplanet480
    @fantasyplanet480 ปีที่แล้ว

    Hello can you make a live streaming app like twitch tv using mern stack and key stream for every streamer to connect with obs ? Thanks

  • @solr4cc
    @solr4cc 9 หลายเดือนก่อน

    WHy after runnig prettier your object have all prop on different lines where mine is oneliner?

  • @michaelirwin7258
    @michaelirwin7258 ปีที่แล้ว

    I like and use prettier just because. I picked it up a few years back and never turned it off...

  • @yoshiyoshi6
    @yoshiyoshi6 9 หลายเดือนก่อน

    note: you need only `npm i prettier` to install prettier since --save-dev is the default behaviour of npm

  • @Matrium0
    @Matrium0 ปีที่แล้ว +1

    Prettier is nice for JS/TS code, but a catastrophe for any kind of markup (e.g. HTML), at least if you have lots of attributes (let's say because of accessibility)
    It prints every single attribute of an html element (for example) on a new line. This makes the arguments readable, but drops the readability of the overall structure of the document (which when reading HTML you are most likely MORE interested in) into oblivion.
    Prettier just forces you into one code-style, without even thinking for a second that there may be different requirements for styling of code (e.g. JS/TS) and markup (e.g. HTML).
    If you have to (heterogenous team with members all around the world using different IDEs) you can use it. But if you are in homogenous environment with direct contact to your colleagues you will 100% find a better solution for you

  • @rhyshughes9942
    @rhyshughes9942 4 หลายเดือนก่อน

    If my project has prettier in devDependencies but my team has prettier local to their mac's, will it override their local settings? If not,, how do they turn it off?

  • @andreymatveyev3204
    @andreymatveyev3204 ปีที่แล้ว

    how to get array values to show up on the new line

  • @adityasethi9794
    @adityasethi9794 ปีที่แล้ว

    The issue with front end is that there are a billion packages to install lol. Good vid tho.
    Why do we need the extension if we install the dev prettier pkg?

  • @JoelPeltonen
    @JoelPeltonen ปีที่แล้ว

    I still can't believe prettier by default gives HTML void elements a closing slash. It also just can't handle long strings in a sane enough way.

  • @chezchezchezchez
    @chezchezchezchez ปีที่แล้ว

    Is there an add-on for VS 2022 proper?

  • @rickyrico80
    @rickyrico80 ปีที่แล้ว

    Log(a * b < 7 ? 'Ugly' : 'pretty')
    Ternaries all the way baby

  • @aamhermansyah7859
    @aamhermansyah7859 ปีที่แล้ว

    Please make ritch text editor or wysiwyg tutorial using Javascript 🙏

  • @nick066hu
    @nick066hu ปีที่แล้ว +2

    My issue is not the topic here. but this is what comes to my mind seeing Prettier and Co.'s default results of code 'prettifying', sorry for the off-topic rant: (btw. a clue to a more appropriate, more effective forum for my topic is welcome)
    Why does everyone, including the most popular tools, insist on a formatting habit coming from the 1980's, the days of 25 to 80 characters per line screens, when all source code was printed out on matrix printers to fanfold paper, as the only way of being well-documented and kept safe. When 'structured, clean programming' meant one variable/statement/nesting depth per line. It has even evolved to a stage when each function declaration had to start on a new page when printed.
    It is now 2023. Of my three monitors, the middle one alone is 4096 pixels, almost a meter wide (it's a 48" 4k OLED 👍), perhaps even more significant is that my two eyes are arranged horizontally 👀 (maybe this is the reason why I hate vertical videos too). In a word: I have plenty of horizontal screen space. Vertical space is however a precious treasure for me and all programmers I know. Then why is this code writing style that wastes the most valuable, vertical space is so widespread?
    Believe me, understanding two or three basic object properties profanely written into one line, or even an if-then-else structure where not a whole line for each curly brace is wasted (I regularly see two additional empty lines added around to further ease the indigestible mystery of the curly braces of a simple if-then-else), is not beyond the intellectual capacity of even a novice programmer. But having to scroll back and forth several meters to understand a simple program is a challenge for us all. Even if you don't recognize it as a problem: understanding several related logical units in the same field of vision is way more easy than assemble one in mind from several screens. Just give it a try!
    Please limit the spread of vertically diluted source code, it is as pointless as how the vertical videos are stupid. The only difference is that those videos are perpetrated by incompetents, but this vertical coding style is unfortunately spread by professionals.
    Professionals who think that a simple 'if (s==='nope') return null else return s' instruction, although it is written in plain English, is only interpretable for all other programmers and their future selves when spread to 8 lines of code (or 12-15 lines if the even more pretty 'clarifying' empty lines are added), covering a significant part of any computer screen. What do they think is then needed to understand a complex parallel thread-safe multilevel abstraction? Seven empty lines between statements?
    PS: I would appreciate seeing a config/setting for doing the opposite of the 'prettifying' vertical code dilution: a vertical code condenser, an 'uglyfier' Like removing empty lines when more then one, one-line conditional/loop statements when only one statement is in the block, one-line object initializers (when properties are unnested and fit within a line), etc. This is not to confuse with code minifying, my 'uglyfier', let's name it vertical condenser, would make the code more concise, more readable.

  • @chanmyaemaung
    @chanmyaemaung ปีที่แล้ว

    👍

  • @pallu83
    @pallu83 ปีที่แล้ว

    Can’t find anything to run prettier on save with IntelliJ 😢

  • @AndrewLapteff
    @AndrewLapteff ปีที่แล้ว

    yeaehhhh!!!!!

  • @windar2390
    @windar2390 ปีที่แล้ว

    i actually like the standard formatter more

  • @alwayzsmarter
    @alwayzsmarter ปีที่แล้ว

    Do u still need to install package if using vs code extension

    • @alwayzsmarter
      @alwayzsmarter ปีที่แล้ว

      Annnndd as i kept watching u answered this lol nvd

  • @jabadnik
    @jabadnik ปีที่แล้ว

    Bs"D
    Hi Kyle! I'm building a Spotify's clone with Spotify for developers and your TH-cam's video. There's a login button, when I touch it, it goes to the page that I am building now, and few seconds turns back to the page in the button's login.

  • @MerrickKing
    @MerrickKing ปีที่แล้ว

    My issue with prettier is that it's so opinionated and hard to configure. How about an ESLint tutorial? Including for TS

  • @aznmayo
    @aznmayo ปีที่แล้ว

    it says the npm command is not found

  • @Sevkavic1
    @Sevkavic1 ปีที่แล้ว +4

    Standardjs has the better formatting rules and zero configuration. And the main thing that it is a standard which is mean that you can not change the standard of the rules it uses to format your code. In this way every developer you work with on some project has the same set of rules that formatter applies to make a cleanup in the project code. Thus you use the same solid standard of the code style which is setuped by default always.

    • @coolemur976
      @coolemur976 ปีที่แล้ว +7

      "Standardjs has the better formatting rules" - that is subjective, but nice try stating it as a fact.
      For example, standardjs removes dangling commas. And some devs might prefer dangling commas because when you rearrange items in arrays or objects using shortcuts, you don't have to worry about missing comma.
      And this is just one of the examples...
      So in this case, when team prefers this rule, Standartjs is instantly not an option.
      Eslint + prettier gives more freedom (even tho prettier is opinionated and might have some edge case problems itself with very specific projects).

  • @zinner525
    @zinner525 ปีที่แล้ว

    And what do i do if prettier is doing garbage formatting like my second input line here :

    {errors && {errors}}
    .
    For some stupid reason it thinks that the second input line here is easier to read and formats it different than the rest. Been driving me crazy.

  • @flamme8587
    @flamme8587 ปีที่แล้ว

    Oh, Jetbrains' tools have it as default.
    You can perform the code reformat associated to a bind like the saving file or a key binding, configuring how it works for each type of file etc..
    Prettier js can be good when using concurrency before building to production tho

  • @NITINKUMARSHAW-cc9nv
    @NITINKUMARSHAW-cc9nv 5 หลายเดือนก่อน

    Bro Will this work in trading BRO?

  • @irun_mon
    @irun_mon ปีที่แล้ว

    I don't like the way prettier formats my boostrap lines, i just use build in formater

  • @risitas5874
    @risitas5874 ปีที่แล้ว

    Doesn't the package-lock.json remove the need to save the exact version of the library?

  • @jiegao3591
    @jiegao3591 ปีที่แล้ว

    _presses alt+shift+f in vscode_
    _random stuff breaks_

  • @glaciron
    @glaciron ปีที่แล้ว

    Guys, can someone tell me, prettier in css does not work

  • @mykalimba
    @mykalimba ปีที่แล้ว +2

    I tried the prettier extension in VS Code, but had to uninstall it. It was *too* opinionated for me, and there was no way to ease up on certain things in the settings. Prettier said "Take me as I am, or leave me!", and I said "Bye, Felicia!".

  • @voidmind
    @voidmind ปีที่แล้ว +1

    ESLint is a way better formatter, because it's flexible enough that you can customize it's formatting rules really easily. Please do yourself a favour when you start a new job: Make sure you don't install Prettier until you know if there are no other code formatting tools that your team has standardized on. Prettier can reformat a whole code base and mess up the git blame on each line of code changed due to automatic re-formatting. You will just aggravate all the other devs on the team.

  • @davidmeissner5010
    @davidmeissner5010 ปีที่แล้ว

    Is that an American Jackson in the background?

  • @_Ye______ah_
    @_Ye______ah_ 7 หลายเดือนก่อน

    how to unistall

  • @pomprocks
    @pomprocks ปีที่แล้ว +16

    Ideally each person could have their own prettier settings and see the code formatting the way they want to see it. Why don't we have that option yet?

    • @nivethan_me
      @nivethan_me ปีที่แล้ว +11

      umm then what will happen with version control? after i edit a file the whole file will be highlighted by git as changed i guess

    • @nikolaik.6344
      @nikolaik.6344 ปีที่แล้ว

      @@nivethan_me the file should be committed without the spaces and line breaks, i guess??

    • @thalibmuhammad9519
      @thalibmuhammad9519 ปีที่แล้ว +4

      no, ideally .prettierrc are pushed to repo and prettier configuration are consensus of the repo maintainer,
      so every PR will not display unecessary formatting changes

    • @ogreeni
      @ogreeni ปีที่แล้ว +7

      Absolutely not. Formatting should be consistent across the repo.

    • @martinlutherkingjr.5582
      @martinlutherkingjr.5582 ปีที่แล้ว +1

      What a dumb idea

  • @MJ-qe5lg
    @MJ-qe5lg ปีที่แล้ว

    Explain why you do not like semicolons and what that means in the feature

  • @RedStone576
    @RedStone576 ปีที่แล้ว +1

    just use standard

  • @AkhilPrasadYT
    @AkhilPrasadYT ปีที่แล้ว

    Why don't you simply right click & press the format document option rather than making this so complicated or use the formatfiles extension.

    • @DaveMadeIt
      @DaveMadeIt ปีที่แล้ว

      Yes, I use that feature all the time. Why would I install prettier??

  • @ultrasoundaudio7844
    @ultrasoundaudio7844 ปีที่แล้ว +1

    First 😁

  • @montebont
    @montebont ปีที่แล้ว

    Not a fan of opinionated formatters. Their "opinions" just don't work for me. Maybe because I have a graphics design background I try and write my code as readable as I can in the first place. If only to do myself a favor when I have to change it at a later moment. My tip: do not indent to much: 2 spaces work very well.

  • @QwDragon
    @QwDragon ปีที่แล้ว +1

    To setup it you should only delete it and never use again. Hate it!

  • @michaelraymondlegg210
    @michaelraymondlegg210 10 หลายเดือนก่อน

    my problem with prettier is using the tags getting closed like this, ive tried editing the prettier.json but it didnt work

  • @user-tl3cc5wz4u
    @user-tl3cc5wz4u ปีที่แล้ว

    anyone know how to setup multiline assignment alignment with vscode like
    this.screenVariables = layerAttributes.screenVariables
    this.events = layerAttributes.events
    this.editorAttributes = layerAttributes.editorAttributes || {}
    this.connectedFaceplateScriptId = layerAttributes.connectedFaceplateScriptId

  • @TheRealDagothUr
    @TheRealDagothUr 5 หลายเดือนก่อน

    I disliked this video bc I'm extremally demanding and extremally impatient, I've asked google for "how to config prettier" and it gave me a video about installing it. Web Dev Simplified it may not be your fault, but it is your loss anyway.