-
Notifications
You must be signed in to change notification settings - Fork 625
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
Introduce pre-commit hooks and GitHub Actions #1316
Conversation
Signed-off-by: Yu Ishikawa <[email protected]>
Signed-off-by: Yu Ishikawa <[email protected]>
Signed-off-by: Yu Ishikawa <[email protected]>
Signed-off-by: Yu Ishikawa <[email protected]>
name: pre-commit | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: [main] | ||
|
||
jobs: | ||
pre-commit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v5 | ||
# SEE https://github.com/pre-commit/action | ||
- uses: pre-commit/[email protected] |
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.
This GitHub Action comes from https://github.com/pre-commit/action .
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v5.0.0 | ||
hooks: | ||
- id: check-added-large-files | ||
- id: check-toml | ||
- id: check-yaml | ||
- id: end-of-file-fixer | ||
- id: trailing-whitespace |
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.
We can go with basic pre-commit hooks to format code. Then, we can take other hooks if ok.
- repo: https://github.com/pycqa/isort | ||
# rev must match what's in dev-requirements.txt | ||
rev: 5.13.2 | ||
hooks: | ||
- id: isort |
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.
ditto
@yu-iskw thanks for the PR. I was starting an answer describing how much I hate linters (especially auto line breaks, which usually make the code unreadable), but when reviewing the results, I actually kind of like them. It mainly orders things in alphabetical order, which is good, and makes the spacing more consistent. How will this hook work in practice ? what happens when I open a PR that is not complaint with its rules? |
The hooks enabled in the pull request automatically formats code. As long as pre-commit is installed locally, pre-commit hooks are automatically triggered when committing and pushing commits. Apart from formating code, some pre-commit hooks like bandit and semgrep helps us to automatically find vulnerabilities and security issues to some degree. That would be useful to keep our code secure. |
/improve |
PR Code Suggestions ✨
|
@mrT23 Thank you for merging! |
Motivation
pre-commit is very useful to apply static code analyzers including linters to code using git hooks. This pull request aims to implement basic pre-commit hooks to keep the code quality pr-agent great.