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

feat: add pre-commit hooks #712

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

danthorpe
Copy link

@danthorpe danthorpe commented Apr 8, 2024

I took a shot at adding a pre-commit hooks files, according to this guide.

Fixes #676.


Once this is merged, it can be used in your other swift packages, by adding the following to the .pre-commit-config.yaml under the repos section, according to the guide.

  - repo: https://github.com/apple/swift-format
    rev: <commit hash / tag>
    hooks:
      - id: swift-format

@danthorpe danthorpe force-pushed the danthorpe/add_pre_commit_hooks branch from df58814 to 756fbb3 Compare April 10, 2024 13:06
@Feuermurmel
Copy link

I'm test-driving the hook from this MR in one of my projects using this configuration:

repos:
  - repo: https://github.com/danthorpe/swift-format
    rev: danthorpe/add_pre_commit_hooks
    hooks:
      - id: swift-format

There are two things I noticed:

  • I think the hook should have require_serial: true set, because swift-format already processes the input files in parallel.

    When require_serial is set to true, only a single process is started for the hook, with all file names passed to it.

  • IMHO it would be nice if swift-format printed the names of files that have been changed. It gives a bit more context as to why the hook failed as well as how many files have been changed.

    I'm mainly a Python dev and I'm using black and isort in most of my projects. Compare their output to that of black:

    image

    AFACIT, swift-format has no option to enable that right now.

In any case, happy to see this moving forward! 😊

@danthorpe
Copy link
Author

Thanks for the comments @Feuermurmel - I wasn't familiar with the require_serial option, I'll take a look into and update the branch/PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request for official .pre-commit-hooks.yaml
2 participants