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

Add pre-commit for Linting #207

Closed
wants to merge 1 commit into from
Closed

Add pre-commit for Linting #207

wants to merge 1 commit into from

Conversation

bhoberman
Copy link

@bhoberman bhoberman commented Jun 29, 2024

pre-commit is a useful tool that automatically and universally enforces linting standards before each commit. It also lets us use the exact same automation for linting locally as in CI, which saves headaches.

As a rule, pre-commit hooks should avoid compiling code or doing anything that risks a serious slowdown, which is why I omitted cargo check and cargo clippy from these checks; they make most sense left as-is, as separate CI jobs.

I applied the lints I configured to the existing repo, which has unfortunately mostly generated small edits adding or removing spaces. Fortunately, this type of thing only has to happen once.

To set this up locally, you can run

pip install pre-commit
cd <nexus repo root>
pre-commit install

Copy link

vercel bot commented Jun 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nexus-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 29, 2024 9:04pm

@bhoberman bhoberman marked this pull request as ready for review June 29, 2024 21:19
Copy link
Contributor

@sjudson sjudson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no objection to adding this, but should confirm with @slumber

Copy link
Contributor

@slumber slumber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This workflow runs in parallel with the rest, so it doesn't serve as a shortcut to failure because there's no jobs dependencies, unlike in the main workflow.

which saves headaches

From my experience, precommit hooks are headaches. Any project I worked on stopped using it eventually. This one is implemented as a workflow, not as a githook, so setting it up with pip is required because of non-trivial checks like protobuf files linter which will fail ci on your PR.

Obviously, I can follow this routine, it won't take more than couple minutes in total. But this is something I don't want to think about everytime I'm writing code.

- id: protolint
- repo: local
hooks:
- id: cargo fmt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this job is present in the main workflow

  1. means it's done twice
  2. in fact, the main job can fail while this one succeeds, because they're not in sync.

Comment on lines +9 to +12
- repo: https://github.com/yoheimuta/protolint
rev: v0.50.2 # Select a release here like v0.44.0
hooks:
- id: protolint
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workflow says there're no files to check.

@bhoberman
Copy link
Author

Closing because this seems unwanted. Can be easily re-opened in the future if we want

@bhoberman bhoberman closed this Jul 1, 2024
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

Successfully merging this pull request may close these issues.

3 participants