travisjeffery / ClangFormat-Xcode

Xcode plug-in to to use clang-format from in Xcode and consistently format your code with Clang
https://twitter.com/travisjeffery
MIT License
2.89k stars 288 forks source link

Option -sort-includes #112

Open robindegen opened 8 years ago

robindegen commented 8 years ago

Does this plugin run clang formatter with -sort-includes? If so, could an option be added to disable this? When using clang formatter through this plugin, all my headers get shuffled around causing the code to break. I don't have this issue when running clang-format manually on my files.

tonyarnold commented 8 years ago

Yes, that's a good idea. In the meantime, you can always refer to Clang-Format Style Options to see how to enable/disable features in the clang-format binary itself.

tonyarnold commented 8 years ago

To answer whether it does this… it doesn't specify it, but perhaps this is the default in the upstream binary?

robindegen commented 8 years ago

It's a bit of a mistery to me what's actually going on here. The "official" clang format plugin for visual studio has explicit mention of a -sort-includes parameter given: https://github.com/llvm-mirror/clang/blob/master/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs#L259

I can't seem to find that in the sources here (maybe i'm not looking well enough?). I wonder if behavior is different between platforms, or if it's just a matter of which version you use.

tonyarnold commented 8 years ago

This is just an Xcode plugin that calls through to the clangformat binary. If you've got a more recent version installed with support for sorting includes, and your configuration specifies it, it will be used (I believe the option appeared in Clang 3.8).

This plugin is not clang format, so there wouldn't be any mention of a specific config option here.

robindegen commented 8 years ago

It was my understanding however that it's disabled by default on the command-line. I'm trying to figure out what's causing it to get enabled. My configuration file has no mention of this.

I found this from chromium: https://codereview.chromium.org/1616263006

Where they mention that header sorting is disabled if the Chromium style is used, I guess possible through BasedOnStyle: Chromium in the config.

There seems to be a lot of scattered information about this topic all over the place with no clear consensus about the actual default behavior of this.