CesiumJS updated Prettier to version 3.3.3

It’s been a little over 4 years since we started using prettier to format all the code in CesiumJS. Prettier itself has had many changes since then. We recently updated to the most recent version of Prettier going from version 2.1.2 to version 3.3.3. Prettier made a large change with 3.0 to turn on trailing commas everywhere. This resulted in touching nearly every file we have in the library in one large PR.

This can make merging any active PRs very noisy. However, similar to when we first introduced it, we’ve put together easy step-by-step instructions to update your branches!

  1. Fetch changes from the upstream git fetch upstream. Replace upstream with the name of your git remote that points to the official CesiumGS/cesium repo.
  2. Create a new branch for your merge: git checkout -b whatever-merge. This is not strictly necessary, but it makes it easier to start over if something goes wrong in this process.
  3. Merge the last commit before Prettier v3 into your branch: git merge pre-prettier-v3 . Resolve any conflicts as you usually do.
  4. Commit the merge above.
  5. Merge the Prettier formatting changes, accepting your own changes in all cases: git merge post-prettier-v3 -Xours --no-commit Accepting yours is safe because this commit only changes formatting. Do NOT commit yet.
  6. Run npm install to make sure you’re on the latest version of prettier and then run npm run prettier on the result of the merge before committing it
  7. Commit these changes (which is technically a merge commit).
  8. Merge main into your branch in order to pick up any changes in main that happened after Prettier was introduced: git merge upstream/main . You can also merge a release tag here instead of main, if desired. Resolve any conflicts as normal and commit; there shouldn’t be any Prettier-related conflicts.
  9. Once you’re satisfied with the result, merge it back into your original branch, if you created a new one in step 2: git checkout my-original-branch && git merge whatever-merge
  10. You may need to restart editors like VSCode to pick up the new version of prettier if they give you any issues with auto-formatting.

It may seem like a lot to do but if you follow those steps it should be a seamless update and you can get back to focusing on what the PR is for.

Please let us know here or on Github if you run into any issues!

2 Likes