Add pre-commit config with ruff and prettier#185
Add pre-commit config with ruff and prettier#185consideRatio merged 6 commits intosensmetry:mainfrom
Conversation
8142724 to
f864ec9
Compare
|
Just a note: prek is a faster alternative. It reads the same |
7b0560b to
5611a6b
Compare
Nice I hadn't heard about it before, tested it now and am happy about the outcome! |
| # pre-commit.ci is a free automation service that can both run a validation job | ||
| # and push commits with fixes to PRs, and keep the versions of configured | ||
| # pre-commit hooks up to date by creating version bumping PRs. | ||
| # | ||
| # pre-commit.ci config reference: https://pre-commit.ci/#configuration | ||
| ci: | ||
| autoupdate_schedule: monthly |
There was a problem hiding this comment.
Have/will you set this up on sysand repo side?
There was a problem hiding this comment.
Or does this need setup per-person?
There was a problem hiding this comment.
I don't remember off the top of my head, but its a matter of a change in the github repo or github or org settings, adding pre-commit.ci as an integration with no further config needed etc.
I typically go to org settings in jupyterhub, enabling it for another specific repo as we add a project.
Edit: under github org settings, third party apps. However, it needs to be initially setup, so maybe via pre-commit.ci website i think
There was a problem hiding this comment.
Also, maybe renovate can update deps here?
victor-linroth-sensmetry
left a comment
There was a problem hiding this comment.
Just because something hasn't been included in the CI (yet) doesn't mean it's not used.
5611a6b to
5120b00
Compare
|
Having thought about this a bit more and I still would prefer to handle the Java and
|
5120b00 to
6e34172
Compare
Signed-off-by: Erik Sundell <erik.sundell@sensmetry.com>
6e34172 to
cec4893
Compare
Signed-off-by: Erik Sundell <erik.sundell+2025@sensmetry.com>
Signed-off-by: Erik Sundell <erik.sundell@sensmetry.com> Signed-off-by: Erik Sundell <erik.sundell+2025@sensmetry.com>
Signed-off-by: Erik Sundell <erik.sundell@sensmetry.com> Signed-off-by: Erik Sundell <erik.sundell+2025@sensmetry.com>
Signed-off-by: Erik Sundell <erik.sundell@sensmetry.com> Signed-off-by: Erik Sundell <erik.sundell+2025@sensmetry.com>
Signed-off-by: Erik Sundell <erik.sundell@sensmetry.com> Signed-off-by: Erik Sundell <erik.sundell+2025@sensmetry.com>
cec4893 to
f8126ae
Compare
Thank you for reviewing this @andrius-puksta-sensmetry and @victor-linroth-sensmetry!! For now I removed the addition related to XML and Java autoformatting. The XML was broken in how it formatted things, and probably caused issues by itself. Findings about the the prettier-java plugin
Notes on re-activating the prettier-java pluginIf we want the Java formatter in the future from pre-commit's prettier system, we should add a import { createRequire } from "module";
const require = createRequire(import.meta.url);
const javaPlugin = await import(require.resolve("prettier-plugin-java"));
export default {
plugins: [javaPlugin.default],
overrides: [
{
files: "*.java",
options: {
tabWidth: 4,
},
},
],
};And in our .pre-commit-config.yaml, add the following to the prettier hook: additional_dependencies:
# https://www.npmjs.com/package/prettier
- "prettier@3.8.1"
# https://www.npmjs.com/package/prettier-plugin-java
- "prettier-plugin-java@2.8.1" |
victor-linroth-sensmetry
left a comment
There was a problem hiding this comment.
Not sure I fully understand how pre-commits work, but seems worth trying out.
pre-commit, and the rust replacementprekis a CLI that helps run autoformatters etc configured via a .pre-commit-config.yamlfile, and can be configured to run before yourgit commitsucceeds as a git hook by usingprek install` for example.I have configured prek / pre-commit to use ruff and prettier, where prettier makes use of plugins for formatting xml, and java. Out of the box we get formatting for markdown, json, yaml, html, css, for example.
Meant to go hand in hand with activating pre-commit.ci via https://pre-commit.ci/ for automation integrated with GitHub to check the pre-commit hooks run correctly. We could also have a github workflow / job for this, but the pre-commit ci is very fast, no maintenance, and helps with both updates of the pre-commit hook versions and can push commits to PRs with fixes (can be opted out of).
Why .pre-commit-hooks.yaml?
I appreciate use of .pre-commit-hooks.yaml (with prek or pre-commit) because:
Why pre-commit.ci to run the check?
I appreciate use of pre-commit.ci to run the automated checks as it offloads us from maintaining another Github workflow job, and has worked reliably and efficiently for a long time now. It also helps us bump the versions, and if we want, also push commit with fixes.