reactpy icon indicating copy to clipboard operation
reactpy copied to clipboard

Added pre-commit hook

Open Smit-Parmar opened this issue 2 years ago • 5 comments

Issues

Resolve #925

Summary

Added back Pre-Commit Hook

Checklist

  • [ ] Tests have been included for all bug fixes or added functionality.
  • [ ] The changelog.rst has been updated with any significant changes.

Smit-Parmar avatar Jun 08 '23 13:06 Smit-Parmar

A couple areas for improvement:

  • It might make sense to have hatch actually run pre-commit rather than the other way around. Dong it this way, where pre-commit tells hatch to execute the set of linting tools might introduce a fair bit of latency to the typical git commit workflow that could be avoided. I could be wrong about that though.
  • We'd also like to run the steps that are presently in lint-js with pre-commit as well.
  • We want pre-commit to fix what it can. Presently that involves passing a --fix flag to hatch run lint-*

rmorshea avatar Jun 08 '23 19:06 rmorshea

@rmorshea Opinion on respective point

  1. If pre-commit is running hatch command then it will be automated process whenever someone commits . Latency will be negligible I guess.
  2. Sure we can add lint-js
  3. We can add --fix as well

Planning to execute pre-commit in following order

  • Fix Python lint.
  • Check Python Lint
  • Fix JS lint.
  • Check JS lint. Let me know your thoughts on this.

Smit-Parmar avatar Jun 09 '23 12:06 Smit-Parmar

We should make it so you don't have to run "fix" and then "check". The "fix" command should return a non-zero exit code if it needs to make corrections. For example, Ruff has a flag for this (--exit-non-zero-on-fix). I believe black does this by default. Not entirely sure if the JS tools are like Ruff (need a flag) or Black (non-zero on fix by default).

rmorshea avatar Jun 09 '23 17:06 rmorshea

@rmorshea Actually I tried using --exit-non-zero-on-fix even without using it pre-commit will fail even if code has been auto formatted by --fix.

    repo: https://github.com/astral-sh/ruff-pre-commit
    # Ruff version.
    rev: 'v0.0.272'
    hooks:
      - id: ruff
        args: [--fix, --exit-non-zero-on-fix]

pre-commit will keep failing unless 4 of the steps completed successfully. What's your suggestion should we make pre-commit like above example (without hatch) or use hatch?

Smit-Parmar avatar Jun 09 '23 18:06 Smit-Parmar

I'll take a closer look at this shortly.

rmorshea avatar Jun 09 '23 19:06 rmorshea

I think we can proceed using hatch run lint-<lang> --fix. Can you add pre-commit as a dependency in the root pyproject.toml file?

rmorshea avatar Jun 10 '23 18:06 rmorshea

@rmorshea We still need to enable precommit on the repo

Archmonger avatar Jun 14 '23 05:06 Archmonger