I'm using clang-format and I'm trying to only set e.g. 120 column limit but no matter what I try clang applies many rules besides that. If I specify all the rules and set their values then it does what I want but I, e.g., only want to set a line wrap rule. Can clang-format do that?
Thanks
Here's my .clang-format
file which is in a parent dir of the source file:
---
Language: Cpp
ColumnLimit: 120
...
Note that I don't have a BasedOnStyle
field so I'd expect clang won't use defaults from style.
Here's how I run:
clang-format -style=file -i src/foo.cpp
Here's foo.cpp
int main(int argc, char const *argv[]) {
int rc = -1;
// This if clause should be wrapped at 120 by clang which it does
if (argc == 1 && && argc != 2 && argc != 3 && argc != 4 && argc != 5 && argc != 6 && argc != 7 && argc != 8 && argc != 9 && argc != 10) {
rc = 0;
}
// This if clause shouldn't be touched by clang. but it is.
if(args > 1)
{
rc = 1;
}
return rc;
}
Expected result: Only lines longer than 120 chars are wrapped.
int main(int argc, char const *argv[]) {
int rc = -1;
// This if clause should be wrapped at 120 by clang which it does
if (argc == 1 && && argc != 2 && argc != 3 && argc != 4 && argc != 5 && argc != 6 && argc != 7 && argc != 8 &&
argc != 9 && argc != 10) {
rc = 0;
}
// This if clause shouldn't be touched by clang. but it is.
if(args > 1)
{
rc = 1;
}
return rc;
}
Actual Result: Many rules are applied and every line is changed. In this case e.g. indentation becomes 2 spaces. I a real world example many rules are applied to files with more code.
int main(int argc, char const *argv[]) {
int rc = -1;
// This if clause should be wrapped at 120 by clang which it does
if (argc == 1 && &&argc != 2 && argc != 3 && argc != 4 && argc != 5 && argc != 6 && argc != 7 && argc != 8 &&
argc != 9 && argc != 10) {
rc = 0;
}
// This if clause shouldn't be touched by clang. but it is.
if (args > 1) {
rc = 1;
}
return rc;
}