Git Commit Hooks with Husky - Format with Prettier on Pre-Commit Tutorial

Поделиться
HTML-код
  • Опубликовано: 18 ноя 2024

Комментарии • 61

  • @colbyfayock
    @colbyfayock  3 месяца назад

    Learn how to build a full stack Next.js app in my upcoming course: colbyfayock.com/course

  • @jatinchavan5360
    @jatinchavan5360 2 года назад +1

    Awesome. I learned what I needed in just 5mins. Amazing!

  • @Vaforadeicoioni
    @Vaforadeicoioni 2 года назад

    what a great format. clear
    BONUS POINTS for warning users that package versions may increase so this config may enstale.

  • @antoniodevcodes
    @antoniodevcodes Год назад

    Had never heard of Husky before. Interesting one. Thanks!

  • @raghavsehgal25
    @raghavsehgal25 3 года назад +1

    The best explanation out there!! Thanks Colby

  • @JamesQQuick
    @JamesQQuick 3 года назад +1

    Wow! This is really neat. I need to learn more about tools like this!

    • @colbyfayock
      @colbyfayock  3 года назад

      Thanks, yeah, this helps the workflow so much, especially when dealing with teams, keeping a consistent codebase

  • @petarkolev6928
    @petarkolev6928 3 года назад +3

    Amazing video, Colby!
    I found out about your channel few days ago and I like your videos very much! Been pretty helpful to me so far :)

  • @luisponce3580
    @luisponce3580 2 года назад +2

    Just like he predicted in the video, for husky version 5 and above, you have to configure the git hooks way different now using husky

  • @MK72887
    @MK72887 2 года назад

    Great tutorial. Subscribed. Love your precise and on point vids. Kudos!

  • @JayTailor45
    @JayTailor45 Год назад

    The video was right to the point. Thanks man.

  • @silolz0rz565
    @silolz0rz565 2 года назад

    I'm doing a project where i need to get the output (verbose) of the pre-commit and view them in a separate window. This has helped to get the basic.

    • @colbyfayock
      @colbyfayock  2 года назад

      glad to hear it was helpful! 🙌

  • @none0n
    @none0n 2 года назад

    Hello, I am your latest subscriber. Thanks for the video

    • @colbyfayock
      @colbyfayock  2 года назад

      and thank you fort he sub :)

  • @fatihcals5468
    @fatihcals5468 8 месяцев назад

    Thank you very much for video @colbyfayock. Could you record new extended video with combine eslint rules and prettier under husky

    • @colbyfayock
      @colbyfayock  8 месяцев назад

      hey not sure if ill get to that one but i'll add it to my list!

  • @zuijd4269
    @zuijd4269 9 месяцев назад

    Amazing video!! I was just wondering if it's possible to connect a '.prettierrc.json' file to the 'prettier --write .' command. I assumed this would happen automatically but in my case it didn't.

    • @colbyfayock
      @colbyfayock  9 месяцев назад

      if it's in the root of the project, it _should_ pick that up automatically: prettier.io/docs/en/configuration.html
      you can also set the config path manually: prettier.io/docs/en/cli#--find-config-path-and---config

    • @zuijd4269
      @zuijd4269 9 месяцев назад

      Thanks!!

  • @solaaar3
    @solaaar3 Год назад

    this is deprecated, would love to have a video on how to it with the current version of husky.

    • @colbyfayock
      @colbyfayock  Год назад

      thanks for the suggestion, i'll keep that in mind!

  • @wojciechnartowski9738
    @wojciechnartowski9738 2 года назад

    Hey mate,
    commiting does not format my code automatically ;(
    running separately yarn format does. What can be the problem?
    "scripts": {
    "lint": "prettier --check .",
    "format": "prettier --write ."
    },
    "husky": {
    "hooks": {
    "pre-commit": "yarn format && -A ."
    }

    • @colbyfayock
      @colbyfayock  2 года назад +1

      hey the newer version of husky uses a different syntax so that may be the issue. here's my code example for the version in the video: github.com/colbyfayock/my-husky-project/blob/main/package.json

  • @huzaifquazi
    @huzaifquazi 2 года назад

    This tutorial is great 🚀, I tried it with husky v8 but it was not working it will only work with husky@^4.3.0 .
    or it can be like I am missing something while working with husky version 8 🙌

    • @colbyfayock
      @colbyfayock  2 года назад

      thanks, yeah! this is only 4.3 unfortunately as they completely redid how it works

  • @bigk9000
    @bigk9000 3 года назад +1

    For some reason, "husky install" doesn't add the hooks listed in the package.json file.

    • @colbyfayock
      @colbyfayock  3 года назад

      hm i think that might be a newer version of husky, haven't played around with that version yet. id try checking out the docs github.com/typicode/husky

    • @bigk9000
      @bigk9000 3 года назад

      @@colbyfayock The documentation on their GitHub is very sparse. Thankfully, I managed to find their actual latest documentation that's quite more on depth after posting my initial comment.
      A lot of it is rooted in using npx and just storing the hooks in a husky directory of bash scripts that you commit into the repo.

    • @colbyfayock
      @colbyfayock  3 года назад

      @@bigk9000 ah. what do you think of that newer API? i tend to like the idea of my husky scripts being managed in package.json... 🤔

    • @bigk9000
      @bigk9000 3 года назад

      @@colbyfayock I can't accurately say -- at least not in comparison to the old one -- because I only learned about Husky a month ago.
      Honestly, I prefer to keep the configurations in it's own dotrc file and try to keep the package.json file as clean as possible.
      I forgot the reasons as to why they did this; I think they mentioned something about how using config files and package.json files were too inconsistent.
      When you run "npx husky-init" it (assuming you're going with default settings) adds "./.husky/_/husky.sh", a hook for testing to start off with at "./.husky/pre-commit", and a gitignore in husky to make sure that the husky script doesn't get added to the repo.
      It also includes "prepare": "husky install" in your package.json scripts.
      So, as it stands now, I prefer some config file so you can more easily see and change what hooks are there. I'm sure there's a reason for this change, but I'm not fully sure why.

    • @colbyfayock
      @colbyfayock  3 года назад +1

      @@bigk9000 yeah interesting, thanks for sharing. i dont do anything crazy with mine, mostly just running formatting, i just like that i can add a few lines of config next to my existing "scripts" in there, but i could see how that would be helpful especially if you're doing more complicated tasks

  • @jurajpiar5749
    @jurajpiar5749 3 года назад

    Often enough, you've got files in your working tree that you don't want to stage into your current commit. In that case, `git add -A . ` in your pre-commit is going to render the husky tool a nuisance.

    • @colbyfayock
      @colbyfayock  3 года назад

      depends on what you're trying to do. also lint-staged can help prevent the issue you're running into, where it will automatically run git add to only the files that were originally staged upon change github.com/okonet/lint-staged#migration

  • @colbyfayock
    @colbyfayock  Год назад

    Get fresh tutorials and other free content straight to your inbox! colbyfayock.com/news

  • @viktorlernt6063
    @viktorlernt6063 10 месяцев назад

    👏👏👏👏👏

  • @akashshrestha01
    @akashshrestha01 2 года назад

    great

  • @YehorKanaiev
    @YehorKanaiev 3 года назад

    Чётко), но очень быстро объясняешь, как будто кто-то подганяет).

    • @colbyfayock
      @colbyfayock  3 года назад

      not totally sure what you mean!

  • @gavin4981
    @gavin4981 2 года назад

    Super mudge

    • @colbyfayock
      @colbyfayock  2 года назад

      haven't heard this one, what's "mudge"?

  • @InshuMussu
    @InshuMussu 3 года назад

    bro, you are going very fast..