namazso / OpenHashTab

📝 File hashing and checking shell extension
GNU General Public License v3.0
3.12k stars 119 forks source link

Add pre-commit #166

Closed kurtmckee closed 1 year ago

kurtmckee commented 1 year ago

Description of changes

This adds a pre-commit configuration to the repo. The configuration adds the following hooks to standardize the codebase:

After adding this configuration, I ran each hook one-at-a-time and, if the hook made changes to files, committed those changes individually.

Next steps

If this is merged, be sure to enable pre-commit ci by visiting that site, clicking "Sign In With GitHub", and following the steps so that pre-commit automatically runs against PRs that are opened for this project. Then pre-commit ci will automatically fix code issues and commit the changes to the PR. For example, this recently happened on one of my projects:

image

Adding more pre-commit hooks

People have created many pre-commit hooks, including linters and formatters for C++ code. I'm only familiar with linting and formatting Python code, but I highly recommend checking for a linter/formatter that matches (or can be configured to match) how you write code.

There is a long list of pre-commit hooks. Be sure to check it out!

kurtmckee commented 1 year ago

@namazso Please let me know if there's anything you'd like to see in this PR. Thanks!

kurtmckee commented 1 year ago

@namazso I noticed that the pre-commit line-endings hook was recently updated to use CRLF, but the codebase hasn't changed to follow that.

I recommend two changes:

Once pre-commit is installed on your development PC, you can run the following command to bring the entire codebase in line with the configured settings:

pre-commit run --all --all-files

I can run this command on my PC and submit a PR to do this, but every file in the codebase will be modified (I just checked) and it would be difficult to review a PR that touched every file, even when it's just line ending changes.

namazso commented 1 year ago

@kurtmckee I have that all set up. git does automatic line end conversion, maybe your git is misconfigured, or you're using WSL git?

image

kurtmckee commented 1 year ago

Ah! You're right, I disable git's line ending conversions on all platforms so I can see what's committed to the repos I contribute to. Output from git config --list includes this:

core.autocrlf=false

I configured the pre-commit hook to enforce LF line endings because that's what (uniformly, I think?) exists in the repo.

If you rely on git to transform line endings then this probably won't end up affecting you. 👍

namazso commented 1 year ago

I changed it to auto, I think that should fix it for autocrlf=false, since it will just normalize to LF instead.

kurtmckee commented 1 year ago

Thanks @namazso! And thanks for all of your work on OpenHashTab! I use it very, very frequently!