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 287 forks source link

Option to change behaviour when no .clang-format is found #94

Closed Ashton-W closed 9 years ago

Ashton-W commented 9 years ago

I dislike the default behaviour of clang-format, in that if there is no configuration it defaults to formatting with LLVM style. This is annoying if you use 'format on save', this message is also shown: "Can't find usable .clang-format, using LLVM style".

Can we get an option to default to no-format if no config is found?

tonyarnold commented 9 years ago

Sure we could look into that.

Why not just configure it, though? Add a .clang-format to the projects you work on, and then add one to your home directory (containing the no-format instructions if you want). The clang-format tool will walk back up the tree from it's PWD looking for a config and use the first one that it finds.

Ashton-W commented 9 years ago

Hi Tony,

I am using the method of having a .clang-format in my home directory. This works for me, but it makes it harder to get my whole team onboard the format train when it requires so much config - having this in the plugin would be simpler for first setup or people unfamiliar with clang-format the tool.

Somewhat related, the plugin will show the message for system headers you accidentally try and save - they won't pickup your ~/.clang-format as they are under /Library

I was thinking of adding this myself when I had time. Glad to have feedback

tonyarnold commented 9 years ago

Go for it! Contributions are always welcome — I think my concern here is that users installing the plugin expect it to do something (anything) when they run it on first install — even if it's not correct.

Format on save isn't enabled by default, is it? It seems to me that a change like this might disadvantage new users.

travisjeffery commented 9 years ago

you can check the .clang-format file into the root of your project's git repo and then everyone would automatically have it.

tonyarnold commented 9 years ago

@travisjeffery I think @Ashton-W is concerned about users who install the plugin then go to edit another project (outside of his control) without a configuration file. They'll see the error mentioned.

travisjeffery commented 9 years ago

This works for me, but it makes it harder to get my whole team onboard the format train when it requires so much config

sure. seemed he was mostly concerned about the projects his team was working on ^. supposedly they'd be the same projects. ¯(ツ)

i'm -1 on making no formatting the default too. i think that would just confuse a lot of people that it wasn't working. just disable the plugin if you're working on another project/don't want to use it.

Ashton-W commented 9 years ago

I was thinking this would be another option under 'format on save', so only projects with a .clang-format get formatting. I don't think many users actually intend to format all source files they save as LLVM style unless specified.

travisjeffery commented 9 years ago

i don't many would want it use llvm as is either, but a lot people don't want the default color scheme in vim as their color scheme as the default. neither do they want the default cover photo on fb/twitter as their cover photo but it lets them know it's there and working and that they can change it. i simply don't want to add a piece of configuration needed for people to start formatting and see that it's working. either way they'll probably configure it anyway but at least this way the default shows that it's working.

best case clang would support an option that would disable formatting. maybe there is one but i think their docs are down currently.

Ashton-W commented 9 years ago

I think we agree that we shouldn't change the default behaviour. Instead add something users can opt-in to.

This would be the same as creating ~/.clang-format with the contents DisableFormat: true, but instead of users requiring more external config, we provide an easier option (that also avoids needing a .clang-format at root /).