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

finos/a11y-theme-builder#876: adding support for prettier #948

Merged
merged 2 commits into from
Jul 15, 2024

Conversation

aaronreed708
Copy link
Contributor

Took code that @ravjot07 originally put in to make prettier work, so he should get credit for this! I'm just pushing it through.

Copy link

netlify bot commented Jun 29, 2024

Deploy Preview for glistening-gecko-6b417a ready!

Name Link
🔨 Latest commit 2df33d0
🔍 Latest deploy log https://app.netlify.com/sites/glistening-gecko-6b417a/deploys/668efb3f303b6a0008016cd3
😎 Deploy Preview https://deploy-preview-948--glistening-gecko-6b417a.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@kburk1997
Copy link
Contributor

kburk1997 commented Jul 1, 2024

Question - will a precommit hook be implemented to run prettier on changed files prior to committing? Or should that be a separate issue?

I've worked on frontend projects with precommit hooks and prettier before, and it makes reviewing PRs much smoother in my experience since we can focus on code content and be reassured that formatting was automatically applied :)

@evangk6
Copy link
Contributor

evangk6 commented Jul 1, 2024

Holding off on review until Aaron is back to answer the above question.

@aaronreed708
Copy link
Contributor Author

I'm fine with a precommit hook

@aaronreed708
Copy link
Contributor Author

aaronreed708 commented Jul 10, 2024

@kburk1997 I was looking at pre-commit hooks in Git. Particularly how to get them to work with a GitHub repo: https://stackoverflow.com/questions/427207/can-git-hook-scripts-be-managed-along-with-the-repository.

What approaches did your other projects use w.r.t. pre-commit hooks? I think putting our hooks into a folder in the repo and than asking developers to update their git config to point to them would be the best way. Of course, can't force people to do that. And it requires git version >= 2.9, which I know I personally don't have on either of my machines, so guessing a great many people also don't have this version. Nothing insurmountable, but another hurdle.

@aaronreed708
Copy link
Contributor Author

This works for me when put in a11y-theme-builder/.git/hooks/pre-commit and made executable. It came from: https://prettier.io/docs/en/precommit.html#option-4-shell-script.

#!/bin/sh
# Gather the names of files that have been staged (by "git add") and were the result of 
#  code being added, created, merged or renamed
FILES=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g')
# if there are no files then exit
[ -z "$FILES" ] && exit 0

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

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

exit 0

@aaronreed708
Copy link
Contributor Author

Per discussion in yesterday's Theme Builder call, I opened a separate issue for creating a pre-commit hook for running prettier and linting -> #960

Copy link
Contributor

@evangk6 evangk6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shear volume of changes are due to the reformatting of the entire code base with prettier - looks good to me!

@aaronreed708 aaronreed708 merged commit a81072d into finos:dev Jul 15, 2024
5 checks passed
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.

3 participants