Policy on the use of clang-format

Hello Swift! :)

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? 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). If there is interest for such pull request(s), how should they be split up? Per file?

Sincerely,

Omeed

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

···

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

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@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

1 Like

Hi Mark!

The general policy is no bulk reformatting.

Cool!

It’s fine to reformat lines that you otherwise change,

Got it!

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.

Awesome, thanks!

Omeed

···

On Apr 5, 2016, at 10:52 AM, Mark Lacey <mark.lacey@apple.com> wrote:

On Apr 4, 2016, at 7:18 PM, Omeed Safaee-Rad via swift-dev <swift-dev@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@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev