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

migrate code style checks to pre-commit #1579

Closed
williballenthin opened this issue Jun 30, 2023 · 1 comment · Fixed by #1591
Closed

migrate code style checks to pre-commit #1579

williballenthin opened this issue Jun 30, 2023 · 1 comment · Fixed by #1591
Labels
CI Continuous Integration configuration enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@williballenthin
Copy link
Collaborator

pre-commit is a tool to register hooks to run upon git commit and/or when a user invokes the utility. its also a convenient place to configure all the code linters (isort, black, ruff, mypy) that we might want develops to invoke. the tool can be easily run from CI, too.

i'd propose that we migrate the config here:

- name: Lint with ruff
run: ruff check --config .github/ruff.toml .
- name: Lint with isort
run: isort --profile black --length-sort --line-width 120 --skip-glob "*_pb2.py" -c .
- name: Lint with black
run: black -l 120 --extend-exclude ".*_pb2.py" --check .
- name: Lint with pycodestyle
run: pycodestyle --exclude="*_pb2.py" --show-source capa/ scripts/ tests/
- name: Check types with mypy
run: mypy --config-file .github/mypy/mypy.ini --check-untyped-defs capa/ scripts/ tests/

to pre-commit. a close example is here: https://github.com/williballenthin/ucutils/blob/master/.pre-commit-config.yaml

the benefit is that our users can then run the same code style checks as in CI with minimal effort. we don't have to share a huge bash one-liner for local development.

@williballenthin williballenthin added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed CI Continuous Integration configuration labels Jun 30, 2023
@williballenthin
Copy link
Collaborator Author

example commit in other project (no files staged, no work done):
image

running the entire config directly:
image

CI run results:
https://github.com/williballenthin/ucutils/actions/runs/5421512740/jobs/9857036678#step:4:96

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Continuous Integration configuration enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant