-
-
Notifications
You must be signed in to change notification settings - Fork 322
Add exec-staged plugin
#1153
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
base: main
Are you sure you want to change the base?
Add exec-staged plugin
#1153
Conversation
commit: |
|
@webpro Can this be merged? I have about a dozen packages I want to add |
|
I've been holding back for a bit, because currently it looks like the On the other hand, it does provide a way for users to have something like lint-staged but with support for Knip, iiuc. Personally I'm not a fan of such tooling in general (who actually wants to wait for Knip to finish just to commit something?), but that's irrelevant I guess. I'll review in the coming days. |
@webpro In the age of AI enabled coding Knip.js is an absolute godsend as a commit hook. The time we save using AI and Knip.js preventing unused code from being committed is a godlike combo! |
|
|
|
@ItsNickBarry Just curious if you’ve already given lefthook a try. I haven’t personally tried using it with Knip but have had a good experience switching to it over husky+lint-staged for other pre-commit checks. https://lefthook.dev/examples/stage_fixed.html#stage-fixed-files |
|
I hadn't heard of lefthook. Based on the examples, I don't think it would work with Knip. It appears to have a higher level syntax for selecting input files ( I don't see how lefthook replaces lint-staged, however, so I might be missing something. |
|
To clarify a but, I'm slow to add new features to lint-staged because I'm the only maintainer and then it's my problem to keep it working. I did just release I also probably won't use it myself, instead running Knip separately in the CI or |
|
@iiroj Yeah, all open-source maintainers are slow to add features. I recently merged at least one PR from as far back as 2022. I felt bad about disrespecting the author's contribution, but everyone involved understands that open-source moves at its own pace. What I haven't done is request changes from a PR author, let them continually resolve merge conflicts for three months, regret the consequences of the requested changes, and then reimplement the PR myself without including that author's commits. Why comment here anyway? You feel that it's important to mention that lint-staged will soon support Knip, so that exec-staged can be dismissed as redundant? (It's better, actually. See the readme for some ideas.) @webpro It's really a shame that the Knip "plugin" system is a walled garden with a fixed list of supported packages. Reminds me of the Google Play store. Such an environment stifles innovation and rewards rent seekers. What's especially disappointing is that the weeks of work I have wasted were specifically for the purpose of improving the compatibility and usefulness of Knip itself. |
|
Here is an example of configuring knip with lefthook . It seems to work exactly as I would have expected. Since knip runs on the whole repo you don't need to pass it the Unless I am missing something, I think with husky + lint-staged, I personally would run knip in husky. Since lint-staged is doing the work to just to get the subset of staged files which knip doesn't need. |
|
@cylewaitforit Looks like lefthook is a direct replacement for husky, but not lint-staged. Running Knip as you have configured it won't work because Knip will run against unstaged changes and untracked files that may be present. For example, maybe you add a new dependency to |
|
Note that the same is true for a pre-push hook. |
|
@ItsNickBarry Thanks for the explanation, I figured there was some information I was missing. I wasn't aware that lint-staged stashed/unstashed the unstaged files. I personally think I would still handle that in a hook directly rather than bringing in an additional dependency. Something like: pre-commit:
commands:
knip:
run: |
git stash push --keep-index -m "lefthook-knip" 2>/dev/null || true
trap 'git stash list | grep -q "lefthook-knip" && git stash pop 2>/dev/null' EXIT
npx knipI'm certain that husky could do the same. |
I wrote
exec-stagedbecauselint-stageddoesn't support Knip. This PR adds Knip support forexec-staged.