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

chore: move all prettier formatting into individual packages #2478

Merged
merged 7 commits into from
Mar 14, 2025

Conversation

cprussin
Copy link
Collaborator

@cprussin cprussin commented Mar 12, 2025

This PR makes a few related changes:

  • Stops using pre-commit to run prettier anywhere in the monorepo, instead we now run prettier from each package and trigger the runs using turborepo at the root.

  • Upgrade the prettier version used in all packages that were previously relying on pre-commit to run prettier.

  • Reformat files that need it due to the new prettier version.

  • Cleans up the turborepo config so that it now runs some tasks in the root package, and also automatically runs pnpm install when needed.

  • Sets up pre-commit to run TURBO_SCM_BASE="HEAD^1" pnpm turbo fix --affected which triggers auto-fixes for any package that has changed in this commit, or any package depending on one that's changed in this commit. Note there are possible downsides of doing this, we'll have to keep an eye on these and maybe update in a follow up:

    • We might want to consider removing TURBO_SCM_BASE which will make turbo compare against main instead of HEAD^1. In effect this would cause pre-commit to fix anything that has changed since main in the current branch, not just in the current commit. I didn't do this because it would cause runs to be even slower and I assume the expectation is for pre-commit to fixup things that matter just for your one commit, not the whole branch.

    • This script still might be quite slow -- especially if you are changing a lot of packages or a package that has a lot of dependencies -- as it's not filtering down the sub-tasks under fix to just the files that have changes. We can probably do something here to filter further, maybe there's some way to pass the filenames in through turbo or something? It's a bit tricky as you can make changes that cause things to need to be fixed in other files, so just running fixes on affected files isn't really actually reliable....

  • Finally, this PR removes pre-commit from CI entirely, as pre-commit is now entirely redundant of other more comprehensive CI checks, and pre-commit should only be used moving forward as a devex optimization.

Note this PR is structured in logically separated commits, so please look through them independently for an easy review.

@cprussin cprussin requested a review from a team as a code owner March 12, 2025 21:49
Copy link

vercel bot commented Mar 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) Visit Preview Mar 14, 2025 7:51pm
component-library ⬜️ Ignored (Inspect) Visit Preview Mar 14, 2025 7:51pm
entropy-debugger ⬜️ Ignored (Inspect) Visit Preview Mar 14, 2025 7:51pm
insights ⬜️ Ignored (Inspect) Visit Preview Mar 14, 2025 7:51pm
proposals ⬜️ Ignored (Inspect) Visit Preview Mar 14, 2025 7:51pm
staking ⬜️ Ignored (Inspect) Visit Preview Mar 14, 2025 7:51pm

Copy link
Collaborator

@ali-bahjati ali-bahjati left a comment

Choose a reason for hiding this comment

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

(put it below)

Copy link
Collaborator

@ali-bahjati ali-bahjati left a comment

Choose a reason for hiding this comment

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

I think still a couple of us would like to use pre-commit (for personal convenience) and you can just solve it by adding the command to the pre-commit.

On another note, it's difficult to review this PR in a single commit because it contains a lot of mechanical changes in addition to your changes. Would suggest putting the prettier changes in a separate commit.

@cprussin cprussin force-pushed the cprussin/move-prettier-to-turbo branch 4 times, most recently from a3a1a0c to 08bb7fa Compare March 13, 2025 22:05
@cprussin cprussin requested a review from a team as a code owner March 13, 2025 22:05
@cprussin cprussin force-pushed the cprussin/move-prettier-to-turbo branch 2 times, most recently from 60d7968 to f1bc986 Compare March 13, 2025 23:30
Copy link
Collaborator

@ali-bahjati ali-bahjati left a comment

Choose a reason for hiding this comment

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

Amazing, thanks!

This commit makes the following connected changes:

- Removes prettier from `pre-commit` and instead moves it to be run by `turbo`,
  hooking into `test:format` and `fix:format`
- Fixes some of the linting scripts where they were incorrectly configured for
  turbo (i.e. renames the scripts to `fix:lint` and `test:lint` as needed)
- Upgrades prettier in all packgaes
This commit fixes formatting & linting issues caused by reconfiguring prettier &
eslint in the prior commit
This commit cleans up and updates the turbo config so that:

1. Tests and fixes can run on the [root
   package](https://turbo.build/repo/docs/crafting-your-repository/configuring-tasks#registering-root-tasks),
   e.g. to format or lint any files that don't exist inside a workspace package
2. More config is shared and we don't have as much config scoped to individual
   packages
3. `pnpm install` automatically runs at the right times (i.e. you don't have to
   manually run an install ever)
This workflow is now redundant since everything pre-commit does is covered by
more comprehensive CI jobs.

Moving forward, pre-commit should be treated as a devex optimization; no checks
should go into pre-commit alone.
@cprussin cprussin force-pushed the cprussin/move-prettier-to-turbo branch from 8907c56 to a909544 Compare March 14, 2025 19:49
@cprussin cprussin merged commit df1ca64 into main Mar 14, 2025
24 checks passed
@cprussin cprussin deleted the cprussin/move-prettier-to-turbo branch March 14, 2025 20:04
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.

4 participants