Skip to content

Add GitHub action to format and lint code #265

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

Merged
merged 14 commits into from
Jun 27, 2023
Merged

Add GitHub action to format and lint code #265

merged 14 commits into from
Jun 27, 2023

Conversation

dyastremsky
Copy link
Contributor

@dyastremsky dyastremsky commented Jun 26, 2023

This pull request adds a pre-commit to run the following:

  • Black for formatting Python
  • Flake8 for linting Python for conformance to PEP8, PyFlakes, and circular complexity (max-line-length set to match Black's 88 default/recommended character limit; this and other settings from Black's documentation here to avoid enforcement of limit when unnecessary).
  • isort for deterministically sorting and organizing Python imports
  • Clang for formatting C++, C, Java, TextProto, Proto, and CUDA
  • Codespell for finding common spelling mistakes

In addition, this adds these native pre-commit hooks, details here:

  • check-case-conflict
  • check-executables-have-shebangs
  • check-merge-conflict
  • check-json
  • check-toml
  • check-yaml
  • check-shebang-scripts-are-executable
  • end-of-file-fixer
  • mixed-line-ending
  • requirements-txt-fixer
  • trailing-whitespace

To run these locally, you can go into the repo and run pip install pre-commit and pre-commit install. After that has been done once, you just need to run pre-commit run --all-files any time you want to apply them. Once installed, it should run automatically on commit for files included in a commit. To correct spelling errors found by codespell when possible, you can install codespell (pip install codespell and potentially pip install --upgrade codespell to use the toml file in the directory) and call codespell -w <path>.

This pull request also adds a GitHub action so that these are run for every pull request and push to main. The core changes are in pre-commit.yml, pre-commit-config.yaml, and pyproject.toml. The rest of the changes are the effect of applying the action to the current repo.

@dyastremsky dyastremsky changed the title Dyas precommit Add GitHub action to format and lint code Jun 26, 2023
@dyastremsky dyastremsky merged commit 902df12 into main Jun 27, 2023
@dyastremsky dyastremsky deleted the dyas-precommit branch June 27, 2023 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants