Add code formatter - #330
Open
tachyonicClock wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A code formatter is a tool to enforce a specific code formatting style across a codebase. I propose using the Google Java Style Guide, since it is popular and tooling exists.
Pros:
Cons:
.git-blame-ignore-revsfile. https://stackoverflow.com/questions/53502654/how-do-i-run-a-code-formatter-over-my-source-without-modifying-git-historygit config blame.ignoreRevsFile .git-blame-ignore-revsto havegit blamework correctly..git-blame-ignore-revsREADME.mdwith instructions on using theRe-base Guide
A formatter was run on the codebase, which likely created merge conflicts.
If your branch does not contain extensive changes, running
git fetch upstreamfollowed bygit rebase upstream/masterwill likely work for you.If your merge changes many files, below is the recommended approach to handle these conflicts by: squashing, reformatting to match the standard changes, and then re-basing.
(Note: This guide assumes the main repository is configured as a remote named
upstream, and your personal fork isorigin.)1. Fetch the latest changes and create a new branch.
git fetch upstream git checkout feature # Your feature left unchanged, used as a backup in-case something goes wrong. git checkout -b feature-fmt2. Squash your feature commits
This condenses all your work into a single commit before applying the new formatting or rebasing, making conflicts much easier to handle. We do this by resetting to the point where your branch originally diverged from master.
3. Format your changed files
Now, apply the formatter to the files that were modified in your squashed commit. You will need to download the formatter. Note the
--replaceflag, which ensures the files are modified in place.4. Stage and amend the feature commit
Add the formatting changes to your staging area and amend your squashed commit so that the formatting is baked in.
5. Rebase onto upstream/master
Now that your single commit is formatted to match the new codebase standards, rebase it onto the updated master branch. Passing the ignore-space-change flag helps smooth over any lingering whitespace-related conflicts.
6. Update your branch
If you check GitHub and something went wrong don't fear because your local
featurebranch is still there.