Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve pre-commit hook to run only on staged files #480

Open
tearingItUp786 opened this issue Oct 12, 2023 · 3 comments
Open

Improve pre-commit hook to run only on staged files #480

tearingItUp786 opened this issue Oct 12, 2023 · 3 comments

Comments

@tearingItUp786
Copy link

tearingItUp786 commented Oct 12, 2023

Description

The pre-commit hook runs the others/validate.sh command on all files (not only the staged files). This leads to annoying DX where we have to stash files or revert some changes even though we might only want to add a subset of files to the commit.

Solution

The project currently has lint-staged installed and it isn't utilized by husky. After doing some digging, I think we can update it to the beow and should get us better DX. The tradeoff is that we can't run the test, lint, typecheck, and build commands concurrently anymore and they'd happen sequentially:

module.exports = {
  '*.+(js|jsx|json|yml|yaml|css|less|scss|ts|tsx|md|graphql|mdx|vue)': [
    `npm run test --silent -- --watch=false`,
    `npm run lint --silent`,
    () => `npm run typecheck --silent`,
    () => `npm run build --silent`,
    `npm run clean --silent`, // needed so that we don't have any build artifacts kicking around when we try to commit again.
  ],
}

The above code will run the test files and lint files correctly on staged files and will run the typecheck and build commands as if they were being run from root.

Link to thread on lint-staged

@kentcdodds
Copy link
Owner

Honestly, I'd rather just remove the hooks altogether 😅

@tearingItUp786
Copy link
Author

Honestly, I'd rather just remove the hooks altogether 😅

Oh why's that?!

@kentcdodds
Copy link
Owner

Because it's more in the way than valuable.

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

No branches or pull requests

2 participants