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
Add pre-commit hooks for formatting #10737
base: dev/7.6.x
Are you sure you want to change the base?
Conversation
@@ -20,7 +21,7 @@ | |||
"type": "git" | |||
}, | |||
"devDependencies": { | |||
"arches-dev-dependencies": "archesproject/arches-dev-dependencies#dev/7.6.x" | |||
"arches-dev-dependencies": "archesproject/arches-dev-dependencies#jtw/prettier" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course I'll revert this once archesproject/arches-dev-dependencies#15 is merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To test the pre-commit hook in a new project, you'll want to add this change to the project template file (and potentially reinstall arches) before creating it (or manually edit afterward and nuke/reinstall yarn)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I like this feature. There are some merge conflicts that need to be taken care of.
I'm wondering if instead of something like yarn format
, this could be added as a pre-commit hook to remove the friction of using this
Sure, I was planning to add something like that as a follow-up, but I'm happy to add a little PoC here. |
4aa63c6
to
6562297
Compare
6562297
to
94fedb5
Compare
Added a pre-commit hook so that folks can have a frictionless formatting experience. To use, assuming you already have the new js dependencies like prettier itself:
Then write some vue/ts by hand, attempt to commit, see the auto-fix happen as the commit aborts. You can always I can walk interested folks through this on the forum and update the contributor docs if this lands. It is truly optional, if you like waiting for Github Actions to fail and asking you to make more commits ;) |
0fbdc00
to
24b7d77
Compare
(I'll leave this in a failing state until approval, and then I can add one more formatting commit to clean up black and add it to the ignored commit hashes.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to config the formatter so this pattern doesn't happen?
Unfortunately not, there's an open issue for it. I added a playground to toy with it. You can fix it yourself by putting the closing tag on a new line, and prettier is OK with it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good just a couple of minor things.
Also holding off on merging this until #10758 is merged since it's blocking eslint/ts formatting hooks.
Also seeing the amount of files that require formatting in the GH action failures, does it make sense to have a separate commit that formats the codebase and then gets added to .git-blame-ignore-revs
?
package.json
Outdated
"eslint:check": "NODE_PATH=./arches/app/media/node_modules ./arches/app/media/node_modules/.bin/eslint ./arches/app/src --resolve-plugins-relative-to ./arches/app/media --ext .vue,.ts --parser ./arches/app/media/node_modules/vue-eslint-parser/index.js", | ||
"eslint:fix": "NODE_PATH=./arches/app/media/node_modules ./arches/app/media/node_modules/.bin/eslint ./arches/app/src --resolve-plugins-relative-to ./arches/app/media --ext .vue,.ts --parser ./arches/app/media/node_modules/vue-eslint-parser/index.js --fix", | ||
"eslint:watch": "NODE_PATH=./arches/app/media/node_modules ./arches/app/media/node_modules/.bin/nodemon --watch ./arches/app/src --ext ts,vue --exec yarn --silent eslint:check", | ||
"format": "yarn prettier arches/app/src --write", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be renamed to something like prettier:format
? All other yarn commands, save actual build processes, denote which dependency they're using
.github/workflows/main.yml
Outdated
@@ -70,6 +70,11 @@ jobs: | |||
echo "package.json not found, skipping yarn commands." | |||
fi | |||
|
|||
- name: Check formatting | |||
run: | | |||
yarn format --check --no-write |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reduces to
./arches/app/media/node_modules/.bin/prettier ./arches/app/src --write --check --no-write
The --write --no-write
isn't ideal. Is it worth taking the --write
flag out of yarn format
? Or adding a second yarn command to package.json
for exclusively checking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. If I go with prettier:check
and prettier:fix
it will rhyme with the eslint commands.
Add formatting step to template CI workflow
Yeah that was my plan. Will wait until right before merge, as we're going to merge more python code until then. |
"resolutions": { | ||
"@vue/compiler-sfc": "^3.4.21" | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this do anything? I'm reticent to include it at the project level if it's just quieting noise
@@ -1,5 +1,5 @@ | |||
[tool.black] | |||
line-length = 140 | |||
line-length = 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why shorten to 100? If we're going to shorten it why not follow PEP-8 or black
standard line length?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm with you there. I'm pretty sure the black team did a huge amount of research on this, everything from accessibility to psychology to real-world usage stats, and an arbitrary value just invites more 🚲 'shedding when the whole promise of black is to liberate your team 🏇.
Types of changes
Description of Change
Hand-formatting code is a drain on team productivity:
This PR adds
prettier
to format the frontend. Run it withyarn format
.It also adds a GitHub action that fails PRs without formatting. A hint is given:
Of course, that's a last resort, as pull request time is too late to get the real benefit. We can socialize the knowledge to enable either "format on save" in VS Code or install a pre-commit hook (included here). We might eventually have a pre-commit hook for a backend formatter also.
Demonstration
Sample changes that would be made in other pending work:
1e794537629b6d
Issues Solved
Closes #10575
Checklist
Ticket Background