earthaccess icon indicating copy to clipboard operation
earthaccess copied to clipboard

Consider using ``pre-commit`` hooks for linting

Open jrbourbeau opened this issue 2 years ago • 5 comments

Sometimes it's easy to forget to lint code (I do this all the time!) and then CI builds fail because, for example, black isn't happy. We might consider using pre-commit hooks here to handle code formatting / linting. That way things like mypy, black, etc. all run automatically when a developer runs git commit ...

@betolink @MattF-NSIDC thoughts?

TODO

  • [ ] Remove .scripts/lint.sh and references to it
  • [ ] Add Ruff (or Flake8) hook to .pre-commit-config.yaml (add Ruff config to pyproject.toml)
  • [x] Enable pre-commit.ci (I may do this independently)
  • [ ] Move isort config from script into a file (pyproject.toml; or migrate to Ruff)
  • [ ] Move Black config from script to file
  • [ ] Move Mypy config from script to file
  • [ ] Should we run Mypy with pre-commit? It can be slow (probably not yet on this project?), and pre-commit is meant to not slow you down.
  • [ ] More pre-commit hooks?
  • [ ] Make sure pre-commit is a dev dependency (if it isn't already -- haven't checked)
  • [ ] Update CONTRIBUTING.md to include pre-commit install

jrbourbeau avatar Aug 16 '23 19:08 jrbourbeau

1000 times yes. Pre-commit gets my tools out of my way and I'm never going back :heart_eyes: Not everyone will use it, so I think we should keep the CI checks... and maybe run them in pre-commit.ci?

MattF-NSIDC avatar Aug 16 '23 21:08 MattF-NSIDC

I think we should go forward with this. While we're there, I'd like to remove Flake8 and isort to replace with Ruff (#34). Ruff also has a Black-compatible formatter that I haven't tried yet, so I would probably still leave Black in place for now?

I think we need to:

EDIT: List moved to OP

mfisher87 avatar Nov 09 '23 16:11 mfisher87

EDIT: List moved to OP

jrbourbeau avatar Nov 09 '23 16:11 jrbourbeau

Good ones! I'll merge all the checklist items into the OP now.

MattF-NSIDC avatar Nov 09 '23 16:11 MattF-NSIDC

Should we run Mypy with pre-commit? It can be slow (probably not yet on this project?), and pre-commit is meant to not slow you down.

Another concern with Mypy is its interface doesn't really work well with pre-commit. Mypy doesn't want to receive a list of changed files to check, it will not do a holistic analysis in this case, so it may pass when a change breaks type correctness.

We can configure pre-commit to not pass filenames, and then Mypy will run on the whole project, which will be slower. Maybe we should run Mypy as a separate CI step.

mfisher87 avatar Nov 09 '23 16:11 mfisher87