-
Notifications
You must be signed in to change notification settings - Fork 120
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
Refactor to allow invoking check and fix as library fns w/ paths #333
Refactor to allow invoking check and fix as library fns w/ paths #333
Conversation
Can you explain a little further? e.g. can you give an example of |
Sure. I have a git pre-commit hook that runs via a babashka task. It runs Since I want these git hooks to be fast and self-contained (so I don't need to require everyone else on my team to also install
The existing cljfmt.tool/check-no-config fn doesn't work well for my use case because it only returns counts (not which files failed the check, which I need to be able to tell the user which files they need to fix) and it calls I hope this clarifies the use case and motivation for the PR, but let me know if not. |
acc6a7d
to
61841ae
Compare
In case it's helpful, here is the code where I'm invoking ...and this branch of |
Okay, I believe I understand now. Let me think about how best to implement this. I don't think |
Yeah, it made more sense to use |
@weavejester Any further thoughts on what should change in here to get this (closer to) mergeable? |
Apologies for taking a while to get back to you on this. My thought is that a separate namespace doesn't seem like the way to go. Instead, what about passing a reporter function, similar to how clojure.test works. e.g.
We could also roll exit code handling into this, as arguably exit codes are a type of reporting. I don't think we need to factor out |
OK, I'll look into all that. Thanks! |
Alright I have that working in this branch: https://github.com/cap10morgan/cljfmt/tree/feature/reporting-fn Would you rather I force-pushed that to this PR or opened a new one? |
I think it feels different enough to warrant a separate PR, if that's okay by you. |
Closing in favor of a different approach |
I wanted to use this with babashka as a library to check some paths recursively in a git hook, but noticed that the library fns (that don't call e.g.
System/exit
) took Clojure code in strings. I wanted to be able to give them apaths
arg like you can do from the CLI and have it use the existing code to recursively find and ingest all the files to check. And then I needed it to return a report detailing which files failed the check, etc.I changed the CLI / tool code to call these lib fns.
This is a big change, I know. So please let me know if it needs to be rethought, implemented differently, or whatever.
I've started using it in a git hook and it works great (and fast!).