Skip to content

migrate to lefthook from husky#51

Merged
technophile-04 merged 4 commits intomainfrom
lefthook
Jun 14, 2024
Merged

migrate to lefthook from husky#51
technophile-04 merged 4 commits intomainfrom
lefthook

Conversation

@technophile-04
Copy link
Collaborator

@technophile-04 technophile-04 commented Jun 14, 2024

Description:

Migrated to lefhook from husky due #49.

The main selling point of lefthook for us:

  1. It doesn't require postinstall to work
  2. since its a single machine code binary also remove the need to mind external dependencies like (Husky + lint-staged , they both add roughly around fifften hundred dependencies to node_modules <- it was mentioned here

Fixes #48

Notes

LeftHook:

A bit about Git hooks

Git Hooks lets you fire some custom scripts when certain actions happens like (commit, push, etc). All you need is good knowledge of Bash scripts and internals of git. You can configure it in ./.git/hooks/pre-commit .

But while working on project you are interested in that project’s code—not the code that checks it. Hence tools like husky, lefthook were born.

Lefthook:

The important selling point is that :

  1. If you have repo with multiple languages like Ruby and TS you don’t need two separate tools like for TS [husky](https://github.com/typicode/husky) and for ruby [Overcommit](https://github.com/sds/overcommit).
  2. Written in Go so fast and since its a single machine code binary also remove the need to mind external dependencies like (Husky + [lint-staged](https://github.com/okonet/lint-staged) , they both add roughly around fifften hundred dependencies to node_modules)

Configuring Lefthook:

  1. Add lefthook as dev dependency in package.json

    yarn add -D lefthook
  2. Run lefthook

    lefthook install

    The above should create an lefthook.yml file

  3. Example :

    # lefthook.yml
    
    pre-commit:
      commands:
        eslint:
          glob: "*.{js,ts,jsx,tsx}"
          run: yarn eslint --fix {staged_files}

    Checkout this [exmaple](https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md#run) for various commands

removed by running following command:

yarn remove husky && git config --unset core.hooksPath
@technophile-04 technophile-04 marked this pull request as ready for review June 14, 2024 06:19
@technophile-04 technophile-04 requested a review from carletex June 14, 2024 06:39
Copy link
Member

@rin-st rin-st left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a great solution!

@carletex
Copy link
Member

This is cool! Working great.

Should we consider lefthook for SE-2 too?

@technophile-04
Copy link
Collaborator Author

technophile-04 commented Jun 14, 2024

Should we consider lefthook for SE-2 too?

Yeah lol was actually thinking the same, the only one point where husky shines is due to its popularity and some people might feel home when using it in SE-2 instead of seeing lefthook but its just small thing and don't think it will cause a lot of difference.

Maybe we test the lefthook here see how it plays and we then we could add it in SE-2 too ?


Also cc @Pabl0cks could you please also give it a shot once on windows?

To test, you could follow "To test" section of this #35 (comment)

@Pabl0cks
Copy link
Collaborator

Also cc @Pabl0cks could you please also give it a shot once on windows?

It's working nicely on Windows! Tried GH Desktop, Git bash and VSCode. Similar outputs:

image

@carletex carletex mentioned this pull request Jun 14, 2024
@technophile-04 technophile-04 merged commit bd30a58 into main Jun 14, 2024
@technophile-04 technophile-04 deleted the lefthook branch June 14, 2024 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants