integreat-cms icon indicating copy to clipboard operation
integreat-cms copied to clipboard

pre-commit: Remove prettier because the repo is now archived

Open cclauss opened this issue 1 year ago • 4 comments

https://github.com/pre-commit/mirrors-prettier

  • prettier/prettier#16229

One of the other options could be used:

  • https://github.com/prettier/prettier/blob/main/docs/precommit.md
  - repo: https://github.com/pre-commit/mirrors-prettier
    rev: v4.0.0-alpha.8
    hooks:
      - id: prettier
        additional_dependencies:
          - [email protected]

Unrelated CodeQL warnings: https://github.blog/changelog/2024-01-23-codeql-2-16-python-dependency-installation-disabled-new-queries-and-bug-fixes/

Short description

Proposed changes

Side effects

Resolved issues

Fixes: #


Pull Request Review Guidelines

cclauss avatar May 15 '24 11:05 cclauss

Thanks for the PR! I'd argue Option 4 would probably make the most sense, given that the install script makes sure prettier is available anyways?

charludo avatar May 15 '24 14:05 charludo

I am a bit out of my depth with those options. If you know how to implement an appropriate solution then we can close this PR with unmerged commits.

cclauss avatar May 15 '24 15:05 cclauss

I am a bit out of my depth with those options. If you know how to implement an appropriate solution then we can close this PR with unmerged commits.

Is it alright with you if I push a commit with the script to this branch?

charludo avatar May 16 '24 07:05 charludo

Sure! I am interested to see if pre-commit run --all-files will run that script.

cclauss avatar May 16 '24 07:05 cclauss

Sorry for taking so long to get back to you!

I just realized I can't easily commit to your fork, so let's do it like this instead:

This works great (unmodified from the link you provided; put in .git/hooks/pre-commit and chmod +x).

#!/bin/sh
FILES=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g')
[ -z "$FILES" ] && exit 0

# Prettify all selected files
echo "$FILES" | xargs ./node_modules/.bin/prettier --ignore-unknown --write

# Add back the modified/prettified files to staging
echo "$FILES" | xargs git add

exit 0

I think the previous behavior was to write, but not re-add the changed files (delete the line with echo "$FILES" | xargs git add). This makes the hook fail if it has to re-format some file(s). I think this is the better behaviour, since this way you can manually check the changes before commiting.

All that's left is then to include

 - repo: local
    hooks:
      - id: prettier
        name: prettier (custom script)
        entry: ./.git/hooks/pre-commit
        language: script
        pass_filenames: false

in the .pre-commit-config.yaml file.

charludo avatar May 27 '24 07:05 charludo

@charludo do you think we could include this functionality into our ./tools/prettier.sh instead of the .git/hooks/pre-commit which is not part of the version control itself? :thinking:

timobrembeck avatar Jun 02 '24 22:06 timobrembeck

@charludo do you think we could include this functionality into our ./tools/prettier.sh instead of the .git/hooks/pre-commit which is not part of the version control itself? 🤔

Oops, yes, absolutely.

Actually, we could probably switch all of the pre-commit hooks for which corresponding devtools exist over to this approach...? Not sure if there are downsides, but it would ensure versions between devtool/pre-commit are always consistent, plus we could finally add a pre-commit hook for pylint

charludo avatar Jun 06 '24 14:06 charludo