-
Notifications
You must be signed in to change notification settings - Fork 139
Updating open branches for Prettier
The Linter Reform pull request introduces Prettier, which is a much more robust auto-formatter for code, but does generate substantially different code formatting in many cases in the existing code base. The pull request updates the majority of the source files in the codebase; manually resolving conflicts would be a major hassle.
Fortunately, it is possible to update your open branches in a mostly automated way. To enable this, the Linter Reform pull was merged as two separate commits: the first adds dependencies and updates configurations; the second actually makes the changes to the source files to conform to those new configurations.
In order to run this process smoothly, you will first need to perform a normal rebase on top of the first of the two commits. Note that, since this commit does not include any of the actual formatting changes, this is equivalent to the task of rebasing on master
in any other circumstance:
$ git fetch --tags upstream
$ git rebase prettier~1
Manually resolve any conflicts that come up in this process.
Then, for the second step, we will rebase on top of the commit that makes all the formatting changes, but any conflicts will be automatically resolved in favor of the code in your branch. We will set up the rebase to then run the auto-formatter over the resulting code; this guarantees that the final outcome is code that fits the new formatting configuration.
$ git rebase --strategy-option=theirs --exec='yarn install && yarn run fixlint && yarn run lint.eslint && git add --all && git commit --amend --no-edit' prettier
Ideally, this will run through every commit in your branch, adding formatting as it goes, and complete cleanly.
If a commit fails during the rebase, it will be for one of two reasons:
- The original commit had linter errors. Your best bet here is to just fix them.
- The commit introduces ESLint directives that are no longer needed. The error message should point them out pretty clearly; just remove the unneeded directives.
Once you have fixed the problems, run the following:
$ yarn run fixlint
$ yarn run lint.eslint
$ git add --all
$ git commit --amend --no-edit
$ git rebase --continue
If you run into a problem you are having trouble resolving, just run git rebase --abort
and Slack me.