-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 prettier to pre-commit, install pre-commit in prebuild #8655
Conversation
@easyCZ Note that we should be careful with touching files that are not 💯 under Webapp control. IMO those would also benefit from prettier, but I a separate step/process, incl. getting other teams on board. For starts, we should explicitly restrict prettier to our components. And maybe On the other hand, those are our files, so: let's just do the per-component filter. |
I've now scoped it to only a couple of WebApp components. If landed in this form, I'll cut a ticket to expand it for tracking. |
@@ -29,7 +29,7 @@ async function branchNameCheck(werft: Werft, config: JobConfig) { | |||
|
|||
async function preCommitCheck(werft: Werft) { | |||
werft.log("pre-commit checks", "Running pre-commit hooks.") | |||
const preCommitCmd = exec(`pre-commit run --all-files --show-diff-on-failure`, { slice: "pre-commit checks" }); | |||
const preCommitCmd = exec(`pre-commit run --show-diff-on-failure`, { slice: "pre-commit checks" }); |
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.
IMO, there's limited value in running pre-commit on all files. Not only does it prevent incremental lint fix, it also takes longer.
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.
Fine with that. I don't think we have a case of "transitive invalidation" in any of our checks,
Codecov Report
@@ Coverage Diff @@
## main #8655 +/- ##
==========================================
- Coverage 12.31% 11.17% -1.14%
==========================================
Files 20 18 -2
Lines 1161 993 -168
==========================================
- Hits 143 111 -32
+ Misses 1014 880 -134
+ Partials 4 2 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Example of the current reformat is in https://github.com/gitpod-io/gitpod/pull/8664/files, which is based on top of this PR. |
.gitpod.yml
Outdated
@@ -40,6 +40,9 @@ tasks: | |||
- name: Go | |||
init: leeway exec --filter-type go -v -- go mod verify | |||
openMode: split-right | |||
- name: pre-commit | |||
# install pre-commit hooks into git | |||
before: pre-commit install |
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.
Could it be that we already install them elsewhere? 🤔 I wondering because I think I sometimes see warnings printed on commit.
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.
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.
Outside of that, I haven't found any other usages of pre-commit install
. pre-commit itself is installed in the dev Dockerfile.
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 thought about in IDE, but cannot find 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.
Ah, doesn't the Git initializer already install all hooks? (I think I saw it fail once because of Git hook errors like a year ago)
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.
In my test workspace runs, it didn't install the hooks. I also didn't find any referneces to pre-commit install
in the codebase so this would need to happen somewhere outside (I don't yet have context where that would be).
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.
Also worth noting: I believe the latest Terminal (i.e. -
) in tasks
ends up being the one visible by default. So here, you're hiding the right Go Terminal, and showing a Terminal on top that does just pre-commit install
.
Suggestions:
- Maybe it's better to add
pre-commit install
as abefore
to any other task listed above - I personally really dislike the split Terminals (TypeScript on left, Go on right) and would also be very happy if we remove the split (but this is unrelated to this PR, and others might really like the split)
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.
Thanks for raising this. I will make the requested change here to not change the experience.
hooks: | ||
- id: prettier | ||
# Only enabled for WebApp components initially, to build consensus and incrementally onboard others | ||
files: ^components\/(server|gitpod-protocol|gitpod-db|dashboard)\/.*\.ts(x?)$ |
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.
👍
Worth pointing out that the default prettier config uses |
@easyCZ Agree 💯 with the attitude. Just looked at the diff of some larger files, though, and it's insanely hard to read. 🙈 😆 I guess that's mostly me, and the whole point of this exercise (unification). But maybe we should double check with the other internally what they think about the specific style. Really really don't want to have these kind of discussions go astray but we also have to make sure we have an immediate benefit from this. 👍 |
I found some time to look into how other big TS projects do it (Theia, vscode): If they use prettier, they have a minimal
Especially the
Yet I think we should:
|
I've updated the PR to include a default prettier config as suggested - you can view how the changes look like here: https://github.com/gitpod-io/gitpod/pull/8664/files
The goal here shouldn't be to configure the IDEs, at lest not yet. We're trying to prevent inconsistent formatting from entering the main branch. As such, formatting on-commit feels appropriate, and also independent of any editor or IDE.
The first one takes a bit longer as it pulls the config, subsequent ones are pretty fast. It's always an option to run We can do a follow-up to tweak how the VSCode behaves and what to do there. |
bcc71fd
to
eba6f73
Compare
/hold |
Thank you for this, @easyCZ! |
This only happens for the type definitions and is actually consistent with how type definitions are specified - for example when you're defining an interface it uses semicolons for properties. TS is lax in this and also allows commands (to make it look like a JS object notation). Again, a single style over personal preference. Here I blame TS for allowing multiple styles :) |
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 looks good. Thanks for setting this up. Strongly agree with the sentiment of sane consistent formatting over catering for personal preferences.
TIL! |
.prettierrc.json
Outdated
@@ -0,0 +1,7 @@ | |||
{ | |||
"singleQuote": true, |
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.
Sorry to actually bike shed on this. 🙈
For JS, I'm usually team single quote, but our code base seems to use mostly double quotes. If it's okay with everyone, I think we should probably default to double quotes to make this less disruptive.
Thanks for your input everyone. Turned out relatively well, sans the bikeshedding around quotes. 🙏 😉 To shortcut the discussion here, and get this merged quickly I suggest:
@easyCZ Could you take care and ping me for ✔️ after that? 🙏 |
|
@geropl This is now fixed up.
|
The example PR has also been updated to reflect the changes - https://github.com/gitpod-io/gitpod/pull/8664/files |
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.
console.log("Nice!");
^
| note the 4 spaces here (-:
/unhold |
Description
prettier
(already installed in container). This will lint + fix files which do not conform to the default prettier style guide - we can tweak this if we are not happy with the defaults (discouraged).pre-commit
hook into the workspace. This trigger the pre-commit run each timegit commit ...
is invoked. User can always run withgit commit ... --no-verify
to skip the hooks.This is an incremental linter/fixer - files will be modified only when changed. This avoid a massive reformatting PR.
Where there are bigger changes, authors are encouraged to first re-format the file/s and raise a "just reformat PRs" and base their changes on top.
Related Issue(s)
This PR is complementary to some of the PRs linked in that here we wire-up pre-commit into git and run prettier, other PRs configure prettier to be prettier..
How to test
git add .
git commit -m "test"
- observe linted & formatted fileRelease Notes
Documentation