-
Notifications
You must be signed in to change notification settings - Fork 684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clang format for Common++
#1451
Conversation
105ba35
to
c961720
Compare
AllowShortFunctionsOnASingleLine: All | ||
NamespaceIndentation: All | ||
|
||
SortIncludes: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prevent some possible includes' error due to the ordering.
.clang-format
Outdated
@@ -1,7 +1,8 @@ | |||
--- | |||
BasedOnStyle: Microsoft | |||
UseTab: Always | |||
BreakBeforeBraces: Allman |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the style like this:
void Foo ()
{
// ...
}
.github/workflows/build_and_test.yml
Outdated
@@ -30,6 +30,7 @@ jobs: | |||
run: | | |||
apk update && apk add cppcheck python3-dev | |||
python3 -m pip install cmake-format | |||
pip install clang-format==18.1.6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
specify the clang-formant here.
@@ -16,9 +16,11 @@ repos: | |||
- repo: https://github.com/pocc/pre-commit-hooks | |||
rev: v1.3.5 | |||
hooks: | |||
- id: clang-format | |||
args: ["--style=file"] # Use the .clang-format file for configuration | |||
files: ^Common\+\+/.*\.(cpp|h)$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apply on Common++
for now.
#pragma message("WARNING: Disabling of warnings is not implemented for this compiler") | ||
#define DISABLE_WARNING_PUSH | ||
#define DISABLE_WARNING_POP | ||
// clang-format off |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here is the manual fix, since the clang-formant cannot do the formating well here. it tries to separate -Wdeprecated-declarations
to -Wdeprecated - declarations
2aca568
to
9c7986b
Compare
9c7986b
to
8531104
Compare
@tigercosmos the PR title should be: |
sorry, fixed the title. btw, seems that the CI already runs the check for clang-format |
This reverts commit 8531104.
Sorry, I think it's okay to squash the commits, and we can add the ignore hash in the next PR. |
AllowShortFunctionsOnASingleLine: All | ||
NamespaceIndentation: All | ||
|
||
SortIncludes: false | ||
IndentPPDirectives: AfterHash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let the macro has indent
|
||
SortIncludes: false | ||
IndentPPDirectives: AfterHash | ||
IndentWidth: 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
macro indent width
sstream << file << ": " << method << ":" << line; | ||
std::cout << std::left << "[" << std::setw(5) << Logger::logLevelAsString(logLevel) << ": " << std::setw(45) | ||
<< sstream.str() << "] " << logMessage << std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually like the previous version better, but not sure if there is a way to keep it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot find the solution for this.
Common++/header/IpAddress.h
Outdated
IPv4Address(const std::array<uint8_t, 4>& bytes) : m_Bytes(bytes) | ||
{ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This formatting change doesn't make a lot of sense, is there an option to avoid it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one is due to BreakBeforeBraces: Allman
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we change to Custom
we can set SplitEmptyFunction: false
which I think should solve it:
https://clang.llvm.org/docs/ClangFormatStyleOptions.html#bracewrapping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, I would stand for splitting the braces in this case. shall we just use the default Allman
settings to prevent too much customization from using Custom
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the default values of the different flags under BraceWrapping
. If all the defaults are what we need, I think it's ok to set:
BreakBeforeBraces: Custom
BraceWrapping:
SplitEmptyFunction: false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried your config, and the effect is like this:
void matchNetwork(const std::string& network) {}
become this:
void matchNetwork(const std::string& network)
{}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is slightly better I think. The rest of the curly braces formatting stays the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there is something in the braces, yes, it will be the same.
void matchNetwork(const std::string& network)
{
// ...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, applied your config.
Common++/header/MacAddress.h
Outdated
MacAddress(const T& addr) : MacAddress(static_cast<std::string>(addr)) {}; | ||
|
||
template <typename T, typename = typename std::enable_if<std::is_convertible<T, std::string>::value>::type> | ||
MacAddress(const T& addr) : MacAddress(static_cast<std::string>(addr)){}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it keeps the empty curly braces {}
in the same line, as opposed to IpAddress.h
where it didn't. Any idea why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe because it's a template?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I know why, probably due to ;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, after I removed ;
, it becomes normal.
But for now I can do manually fixing, but after when we apply a lot of files, it's hard to pick these syntax issues one by one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, maybe we should just remove the ;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, after I removed
;
, it becomes normal. But for now I can do manually fixing, but after when we apply a lot of files, it's hard to pick these syntax issues one by one.
we should fix things whenever we see them, of course we might miss some...
Common++/src/OUILookup.cpp
Outdated
vendorMap.insert({ | ||
std::stoull(line.key()), { val["vendor"], vLocalMaskedFilter } | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a weird mix of tabs and spaces in these lines, but not sure if it can be fixed 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is in purpose. the indent is tab, the alignment is space.
for example:
<tab> void foo(int a,
<tab><spaces> int b) {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, but why does line 57 has spaces instead of tabs? Maybe we should just move });
to line 56?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah... you are right.. it's weird here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried all options of UseTab
, and all options decide to use spaces there
https://clang.llvm.org/docs/ClangFormatStyleOptions.html#usetab
Seems it is something that we cannot control, sometime clang-tidy is stupid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you try moving });
from line 57 to line 56 before running clang-format
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried, it doesn't help
no matter this;
vendorMap.insert({std::stoull(line.key()), { val["vendor"], vLocalMaskedFilter }});
or
vendorMap.insert(
{std::stoull(line.key()), { val["vendor"], vLocalMaskedFilter }});
they will be formatted as:
vendorMap.insert({
std::stoull(line.key()), { val["vendor"], vLocalMaskedFilter }
});
one way is to use // clang-format off
here, but I would suggest just let it be this if it doesn't break the build.
according to my experience, when there is too many braces, clang-format becomes stupid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we can just leave it the way it is... 😕
. git-blame-ignore-revs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add this as empty file in this commit, or add it later after we merge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can have it now, we will add the file anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong opinion, but I think it's better to add the file after we have the commit hash. But if you feel strongly about keeping it, I'm ok with it
apply clang-format for
Common++