Build a Modern JS Project - #4 Pre-commit with Husky & lint-staged

Поділитися
Вставка
  • Опубліковано 2 лис 2024

КОМЕНТАРІ • 16

  • @flacodoom
    @flacodoom 3 роки тому

    Great video, clear and concise... could you made a 2021 updated versión? ... Thanks for sharing

  • @wobsoriano
    @wobsoriano 4 роки тому

    Man this series is god mode. Thanks for this

  • @magnifico689
    @magnifico689 5 років тому +4

    This is a great tutorial series, kindly also finish the MERN + Graphql series. Thanks!

  • @alexandervega7541
    @alexandervega7541 5 років тому

    Thanks for the tutorial! Definitely learning here
    I'm trying to understanding something.. lint-staged package is necessary because it can lint and fix only the files we are about to commit (files in in the stage area), correct? Not sure if we get another benefit from installing it.
    I tried running just with husky like this:
    "husky": {
    "hooks": {
    "pre-commit": "npm run lint:fix"
    }
    },
    but with this way the formatting for the js files was done after the commit was completed so it didn't work as I expected.
    also tried:
    "pre-commit": "npm run lint:fix; git add ."
    but this way it adds everything for the commit (and I may have other files that I actually didn't want to add to the commit)

    • @CodeRealm
      @CodeRealm  5 років тому

      I have an array with "npm run lint:fix" and "git add" (without the period), and it works like charm. See the repo github.com/alex996/react-css-spinners/blob/master/package.json

  • @rahulsriram6295
    @rahulsriram6295 4 роки тому

    Aren't the pre and post hooks of git itself enough in npm-scripts? Should we use husky?

    • @CodeRealm
      @CodeRealm  4 роки тому +1

      Possibly, although I haven't used Git hooks. I suppose husky uses them under the hood.

  • @sabeerbikba8585
    @sabeerbikba8585 6 місяців тому

    well explained thanks

  • @zainsyed9811
    @zainsyed9811 5 років тому

    Thanks for the amazing playlist :). One quick question when I commit husky and lint-staged doesnt seem to be working. The terminal shows:
    husky > pre-commit (node v10.16.0)
    No staged files match any of provided globs.
    My package.json file is identical to yours (as is my folder structure)
    "scripts": {
    "lint": "eslint '**/*.js'",
    "lint:fix": "prettier-eslint '**/*.js' --write"
    },
    "husky": {
    "hooks": {
    "pre-commit": "lint-staged"
    }
    },
    "lint-staged": {
    "*.js": [
    "npm run lint:fix",
    "git add"
    ]
    }
    Thanks for your help :)

  • @rachaz9119
    @rachaz9119 4 роки тому

    Is there a way to ignore files? the "ignore" key is deprecated and i micromatch.not doesnt work :( is there an example for it

    • @CodeRealm
      @CodeRealm  4 роки тому

      Ignore files in lint-staged? It takes a glob pattern, so you could include/exclude with it. Otherwise, with ESLint, you just create a .eslintignore file

  • @piwinGer
    @piwinGer 5 років тому

    Great series. 👍

  • @compteprivefr
    @compteprivefr 4 роки тому

    This might be a really stupid question. But if you can simply use git-hooks to run all your tests before commits, what is the point of having a CI?? You simply enforce this in your team and no need for a slow and costly CI build...

    • @CodeRealm
      @CodeRealm  4 роки тому +1

      Git hooks will run on the staged files, not on the entire codebase. The point of CI is to catch typos or errors before they into production typically by running a linter and/or formatter and a test suite. Developers can still bypass or disable git hooks when pushing; they also often forget to re-run the tests. CI is kind of a gateway that shields your live servers from bad code.

  • @kinglamido
    @kinglamido 5 років тому

    Nyc as always

  • @cristianscript5649
    @cristianscript5649 2 роки тому

    It's not working don't know why