[swift-dev] Policy on the use of clang-format

Mark Lacey mark.lacey at apple.com
Tue Apr 5 09:52:59 CDT 2016


> On Apr 4, 2016, at 7:18 PM, Omeed Safaee-Rad via swift-dev <swift-dev at swift.org> wrote:
> 
> Hello Swift! :)

Hi Omeed,

> 
> First off, thank you for the wonderful project!
> 
> I noticed that a number of C++ files in the Swift compiler could use a pass of clang-format. What is the general policy on this?

The general policy is no bulk reformatting.

> Given that clang-format can be invasive (affecting commit history - `git blame` that is), my understanding is that it’s use is on a case by case basis (if a file has a short history for example). Noticed this reasoning in a recent commit message (d03539c1277f4379d17afb6712bebc2c7ddf789a).

It’s fine to reformat lines that you otherwise change, but as you mention going beyond that can make it more difficult to understand the history in a file.

There’s a tool called git-clang-format which makes it easy to run clang-format but only touch the lines you’ve already modified. It lives in $SWIFT_SOURCE_ROOT/clang/tools/clang-format. By adding that to your PATH, along with having clang-format itself in your path, you are able to reformat the lines you have already changed by doing:

  git add files-i-have-changed.cpp
  git clang-format

The result will be unstaged lines with the formatting changes, which you can review with ‘git diff’ before staging those updated lines with ‘git add’.

Mark


> If there is interest for such pull request(s), how should they be split up? Per file?
> 
> Sincerely,
> 
> Omeed
> _______________________________________________
> swift-dev mailing list
> swift-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-dev



More information about the swift-dev mailing list