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

Initial config for pre-commit #2670

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

dannosliwcd
Copy link
Contributor

@dannosliwcd dannosliwcd commented Oct 25, 2022

Some of these pre-commit tests fail on the current contents of the repo. Some pre-work exists to resolve those failures.

To run a single check on all files in the repo, use the --all-files option in pre-commit run. E.g., for the geopm license checks (that one succeeds for all files right now):

pre-commit run geopm-license --all-files

Or to find issues with rst file backtick usage:

pre-commit run rst-backticks --all-files

- Add an initial configuration for pre-commit.com checks to run on this
  repository
- Related to geopm#2530
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Auto-removes trailing whitespace

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: pre-commit has a way to tell per-file hooks to skip file patterns/types. Skip patch files for this one. e.g., by exclude_types diff or by exclude \.patch$

rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ensures that a file is either empty, or ends with one newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also ignore patch files

hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
Copy link
Contributor Author

Choose a reason for hiding this comment

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

checks yaml files for parseable syntax.

- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
Copy link
Contributor Author

Choose a reason for hiding this comment

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

checks json files for parseable syntax.

- id: end-of-file-fixer
- id: check-yaml
- id: check-json
- id: check-added-large-files
Copy link
Contributor Author

Choose a reason for hiding this comment

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

prevents giant files from being committed.

Comment on lines +32 to +33
- id: flake8
args: ["--max-line-length=120", "--extend-ignore=E261"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will need more discussion. Our contributor guidelines say we follow pep8, but I think we're following a modified version of it. Which errors do we want to track?

Comment on lines +37 to +39
- id: bandit
# Only gate high-severity issues
args: ["-lll"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This checks for common security issues in python code.

It can be pretty nit-picky by default. Should we just gate on high-severity issues?

Also note that the pre-commit framework is opt-in, so this config file doesn't actually prevent these issues from getting committed. It's a convenience for committers to see issues when they introduce them instead of later during review or during our pre-release checklist.

Comment on lines +43 to +44
- id: codespell
args: ["--ignore-words-list", "atleast,clos"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a low-false-positive-rate code-friendly spell checker. It isn't grammar-aware or completely spelling-aware. But it does a good job of catching common mis-spellings and recommending reasonable fixes in the error message.

It also allows us to add custom confusion lists. Would we want to do that with anything? E.g. geomp -> geopm.

Comment on lines +47 to +53
- id: geopm-license
name: GEOPM License Checks
description: This hook checks whether files have the right license header.
pass_filenames: false
entry: ./check-precommit-license
language: script
types: [file]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can also run scripts to do any project-specific checks. We want these to be fast things (like checking for license headers), not long things that would disrupt commit workflows (like build-and-UT). Anything else to add?

@@ -0,0 +1,53 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any others from there that we want to add?

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.

None yet

1 participant