-
Notifications
You must be signed in to change notification settings - Fork 975
pre-commit hooks demo
#8193
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: master
Are you sure you want to change the base?
pre-commit hooks demo
#8193
Conversation
55bb20c to
532d4a9
Compare
|
@s373nZ hi! noting your recent reference to this PR.... do you plan on returning to this PR anytime soon? I'm doing some spring cleaning of our open PRs |
532d4a9 to
69c9df7
Compare
|
Hi @madelinevibes! 👋 Updated this by rebasing against Marking this ready for review and removing the |
|
Hey! Thank you for this awesome PR! I had been running this heavily vibecoded (and very verbose) precommit hook to fix up my nits but this looks very neat and tidy! The repos used for the most part also seem reliable and maintained. I would also add whitespace fixing and flake8 fixing in this PR as well, I find that most of the time my prebuild checks fail because of whitespace and flake8 errors :( |
| connectd | ||
| crate | ||
| mut |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a comprehensive list based on what's triggered by codespell? Does this also run on all files, or all C files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a comprehensive list based on what's triggered by codespell?
Not by any means. This is just demo of how to add words to the ignore list. Attached is recent output for pre-commit run --all-files codespell > codespell.txt
I suggest going through these items to decide which typos to fix versus which to add to the ignore list is worth a separate PR?
Does this also run on all files, or all C files?
This runs on all files submitted with the changeset (during a commit) and all files in total when using pre-commit run --all-files. The mut in the ignore list is actually for Rust code.
| - refactor | ||
| - perf | ||
| - test | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You maybe able to use https://github.com/hhatto/autopep8 and https://github.com/PyCQA/flake8 for python style fixes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intentionally didn't include flake8 due to this discussion: #7884 (comment)
I can add it and/or autopep8 in if you require in order to accept this work. Just LMK! :)
|
Also, have you checked how long it takes to run this? Just wondering because we're making a fair few external requests. |
69c9df7 to
1929a12
Compare
|
Rebased against
First run ALL FILES (fresh install): Regular run ALL FILES: Regular run on Regular run on During a commit, |
|
It's always good to have an opinionated list. The downside is, we might all disagree with that list! In particular, the conventionalcommits.org is crap. I hate "chore:" as a prefix. It's non-informative. Prefixes should refer to subsystems, e.g:
If there's no logical subsystem, I sometimes omit it, and sometimes use "global". But usually I talk about what system, or subdaemon, or plugin is hit (even if, as a side effect, other code needs to be adapted!). |
|
Will this be integrated into the CI, or is it intended only for local testing? My local run is currently failing on almost all steps :(. |
1929a12 to
2a39948
Compare
@rustyrussell this list was a best-guess demo derived by scanning a few pages of the commit history in April and configuring based on observed conventions.
Noted, and removed it as a commit linter. The prior configuration should have required
If the team wanted to formalize conventions for commit messages and add them to the developer documentation, it may be possible to leverage the Conventional Commit hook to enforce it. Although, it might not make sense to bend that tool too far and consider a customized implementation.
@ShahanaFarooqui Definitely not ready for CI yet, IMO. An idea for a "mini road map" toward this might be something like:
I would be interested / curious to help out with the follow ups in |
|
Hey! Here's a list of requirements that @ShahanaFarooqui and I came up with: Must-haves:
Nice-to-haves:
@s373nZ Let me know what you think? |
|
@sangbida @ShahanaFarooqui This is a great list. Thanks! I'm happy you're interested in restoring Slightly concerned about a conflict between the requirements
I assume this means you prefer
Would you like to supply a list of available subsystems? I can also just take a first guess based on Rusty's and the commit log... Given the present information, here's my current plan:
A bit of work and a lot of testing ahead, but optimistic many of the requirements are already mostly addressed. Let me know if you have feedback or corrections. |
|
@s373nZ Let's start with the following list of subsystem prefixes for now. We can continue refining it iteratively until it's sufficiently mature: |
I "truely" tested
My understanding is that we should run all prebuild checks (i.e., will cause the prebuild checks fail) in this stage. Then extra checks like
AFAIU, both Ruff and flake8 are Python-only tools. I may be mistaken, but if you and @cdecker prefer Ruff, then Ruff it is. I just want to ensure Ruff doesn’t miss any flake8 checks that would cause the hook to pass but the prebuild check to fail.
Shared in my earlier comment above.
Umm..How about we let clang-format and codespell take a back seat as manual hooks for now? Sorry for the mix-up earlier 😄. We can enable them once the codebase is more cleaned up accordingly.
Yes, agreed. These two seem like the right candidates for now, but feel free to include additional tools if needed.
It looks great, but is it not too big of a change at this stage?
Thank you so much. Truly appreciate it!!! ❤️ |
2a39948 to
ae10cd7
Compare
|
Apologies for the lengthy time between feedback. Was mostly offline during the holidays and it's been slow coming out of hibernation and amidst other priorities. The latest push:
This could always use more testing, but I wanted to aggregate the developments over the last month and provide an update. |
|
This looks amazing to me! I love that it runs when you install the hook and does not run when you do not install the hook! I tested most of the features and they are working great. Sorry to be a pain, but my only suggestion is if the include order fixer could also detect duplicate includes and fix them? Other than that looks great would be happy to approve. @ShahanaFarooqui what do you think? |
Reimplements `make check-amount-access` for Python regex.
Reimplements `make check-discouraged-functions` for Python regex.
Includes default config file and an initial word list to ignore.
A helper tool to fix code style errors using `ruff` and `clang-format` and correct spelling.
Also fixes some exising file spacing issues. Preserves whitespace and comments. Assisted by Cursor Auto.
ae10cd7 to
f9ad52e
Compare
Good call. I've updated the script to de-duplicate the includes. Thanks @sangbida! Latest push:
|
ShahanaFarooqui
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just one update: I had to add either language: system or language_version: "18.19.0" for commitlint to run successfully.
ACK f9ad52e
Interesting. My local NodeJS for testing was |
It also worked for me with Node v20 and v22. The point I was trying to make is that I had to explicitly specify either the Node version or request the system-installed Node.js, as it did not work implicitly for me.
This may be related to my use of
Setting defaults usually sounds like a good idea to me… until proven otherwise 😄 |
Default to Python 3 and NodeJS to use that which is on the system, avoiding conflicts with `nodeenv`.
There might be some unexpected behavior here. Added a new commit to set |
This PR expands upon #7884 to demo some potential DX improvements through adding pre-commit hooks. It contains the following features:
shellcheck.make check-amount-accessas a local pygrep hook.make check-discouraged-functionsas a local pygrep hook.codespell, manually, to check for common spelling errors.doc/directory.JSONschemasdevtools/fix-style-errorsconvenience script which runs the more destructive fixers like clang-format and codespell.devtools/include-order-fixer.pyscript to scan the build's source and header files and fix them for Core Lightning conventions (agent assisted by Cursor).ruffwithflake8in pre-commit config.Many of these experiments output a lot of errors/warnings against the existing code. Generally,
pre-commitshould be only checking the current changeset and provoking the developer to address issues incrementally. Interested parties can run specific hooks on the entire codebase withpre-commit run --all-files [hook-id]Particular checks and standards may not be applicable or aligned with the workflow of the maintainers. I'd be happy and interested to break this work into separate PRs for specific hooks where there is interest, or explore adding more.
Relates to #7765.
Checklist
Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked:
Changelog-None