Skip to content

More clang format options #337

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 88 additions & 54 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,38 +1,72 @@
---
Language: Cpp
# BasedOnStyle: Google
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignArrayOfStructures: Right
AlignConsecutiveAssignments:
Enabled: true
AcrossEmptyLines: true
AcrossComments: false
AlignCompound: true
PadOperators: true
AlignConsecutiveBitFields:
Enabled: true
AcrossEmptyLines: true
AcrossComments: false
AlignCompound: true
PadOperators: true
AlignConsecutiveDeclarations:
Enabled: true
AcrossEmptyLines: true
AcrossComments: false
AlignCompound: true
PadOperators: true
AlignConsecutiveMacros:
Enabled: true
AcrossEmptyLines: true
AcrossComments: false
AlignCompound: true
PadOperators: true
AlignConsecutiveShortCaseStatements:
Enabled: true
AcrossEmptyLines: true
AcrossComments: false
AlignCaseColons: true
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AlignOperands: AlignAfterOperator
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: Empty
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
BinPackParameters: false
BitFieldColonSpacing: Both
BraceWrapping:
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
Expand All @@ -46,46 +80,47 @@ BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
FixNamespaceComments: true
ForEachMacros:
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '.\*'
Priority: 1
- Regex: '^"'
Priority: 2
- Regex: '^<.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
KeepEmptyLinesAtTheStartOfBlocks: true
KeepEmptyLinesAtEOF: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PackConstructorInitializers: NextLine
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 100
PenaltyBreakComment: 300
Expand All @@ -95,9 +130,9 @@ PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 2000
PointerAlignment: Left
RawStringFormats:
- Language: Cpp
Delimiters:
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
Expand All @@ -106,14 +141,14 @@ RawStringFormats:
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
Expand All @@ -122,10 +157,11 @@ RawStringFormats:
- ParseTextOrDie
- ParseTextProtoOrDie
CanonicalDelimiter: ''
BasedOnStyle: google
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
BasedOnStyle: google
ReferenceAlignment: Pointer
ReflowComments: true
SortIncludes: CaseSensitive
SortUsingDeclarations: LexicographicNumeric
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
Expand All @@ -136,16 +172,14 @@ SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
StatementMacros:
Standard: Auto
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseTab: Never
...

TabWidth: 8
UseTab: Never
4 changes: 3 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ jobs:
run: |
# Installing packages might fail as the github image becomes outdated
sudo apt update
sudo apt install dos2unix clang-format
sudo apt install dos2unix
pip install cmake-format
# Default clang-format version is too old, some new clang-format options are not supported. Install newest stable llvm version
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh) && apt install -y clang-format-\$LLVM_VERSION && ln -snf /usr/bin/clang-format-\$LLVM_VERSION /usr/bin/clang-format"

- name: Lint
run: ./format.sh && git diff --exit-code
12 changes: 6 additions & 6 deletions format.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/sh

clang-format --version
echo "cmake-format version: $(cmake-format --version)"

find trantor -name *.h -o -name *.cc -exec dos2unix {} \;
find trantor -name *.h -o -name *.cc|xargs clang-format -i -style=file

cmake-format --version
find . -maxdepth 1 -name CMakeLists.txt|xargs cmake-format -i
find trantor -name CMakeLists.txt|xargs cmake-format -i
find cmake -name *.cmake -o -name *.cmake.in|xargs cmake-format -i
find cmake_modules -name *.cmake -o -name *.cmake.in|xargs cmake-format -i
find trantor -name *.h -o -name *.cc|xargs clang-format -i -style=file \
&& find . -maxdepth 1 -name CMakeLists.txt|xargs cmake-format -i \
&& find trantor -name CMakeLists.txt|xargs cmake-format -i \
&& find cmake -name *.cmake -o -name *.cmake.in|xargs cmake-format -i \
&& find cmake_modules -name *.cmake -o -name *.cmake.in|xargs cmake-format -i
4 changes: 2 additions & 2 deletions trantor/net/AsyncStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

#pragma once

#include <trantor/utils/NonCopyable.h>
#include <memory>
#include <trantor/utils/NonCopyable.h>

namespace trantor
{
Expand All @@ -38,7 +38,7 @@ class TRANTOR_EXPORT AsyncStream : public NonCopyable
* @return false if the connection is closed.
*/
virtual bool send(const char *data, size_t len) = 0;
bool send(const std::string &data)
bool send(const std::string &data)
{
return send(data.data(), data.length());
}
Expand Down
8 changes: 4 additions & 4 deletions trantor/net/Certificate.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#pragma once
#include <string>
#include <memory>
#include <string>

namespace trantor
{
struct Certificate
{
virtual ~Certificate() = default;
virtual std::string sha1Fingerprint() const = 0;
virtual ~Certificate() = default;
virtual std::string sha1Fingerprint() const = 0;
virtual std::string sha256Fingerprint() const = 0;
virtual std::string pem() const = 0;
virtual std::string pem() const = 0;
};
using CertificatePtr = std::shared_ptr<Certificate>;

Expand Down
15 changes: 8 additions & 7 deletions trantor/net/Channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,25 @@
*/

#include "Channel.h"

#include <trantor/net/EventLoop.h>
#ifdef _WIN32
#include "Wepoll.h"
#define POLLIN EPOLLIN
#define POLLPRI EPOLLPRI
#define POLLOUT EPOLLOUT
#define POLLHUP EPOLLHUP
#define POLLIN EPOLLIN
#define POLLPRI EPOLLPRI
#define POLLOUT EPOLLOUT
#define POLLHUP EPOLLHUP
#define POLLNVAL 0
#define POLLERR EPOLLERR
#define POLLERR EPOLLERR
#else
#include <poll.h>
#endif
#include <iostream>
namespace trantor
{
const int Channel::kNoneEvent = 0;
const int Channel::kNoneEvent = 0;

const int Channel::kReadEvent = POLLIN | POLLPRI;
const int Channel::kReadEvent = POLLIN | POLLPRI;
const int Channel::kWriteEvent = POLLOUT;

Channel::Channel(EventLoop *loop, int fd)
Expand Down
36 changes: 18 additions & 18 deletions trantor/net/Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

#pragma once

#include <trantor/utils/Logger.h>
#include <trantor/utils/NonCopyable.h>
#include <trantor/exports.h>
#include <functional>
#include <assert.h>
#include <functional>
#include <memory>
#include <trantor/exports.h>
#include <trantor/utils/Logger.h>
#include <trantor/utils/NonCopyable.h>
namespace trantor
{
class EventLoop;
Expand Down Expand Up @@ -268,7 +268,7 @@ class TRANTOR_EXPORT Channel : NonCopyable
*/
void tie(const std::shared_ptr<void> &obj)
{
tie_ = obj;
tie_ = obj;
tied_ = true;
}

Expand All @@ -284,7 +284,7 @@ class TRANTOR_EXPORT Channel : NonCopyable
void update();
void handleEvent();
void handleEventSafely();
int setRevents(int revt)
int setRevents(int revt)
{
// LOG_TRACE<<"revents="<<revt;
revents_ = revt;
Expand All @@ -298,18 +298,18 @@ class TRANTOR_EXPORT Channel : NonCopyable
{
index_ = index;
};
EventLoop *loop_;
const int fd_;
int events_;
int revents_;
int index_;
bool addedToLoop_{false};
EventCallback readCallback_;
EventCallback writeCallback_;
EventCallback errorCallback_;
EventCallback closeCallback_;
EventCallback eventCallback_;
EventLoop *loop_;
const int fd_;
int events_;
int revents_;
int index_;
bool addedToLoop_{false};
EventCallback readCallback_;
EventCallback writeCallback_;
EventCallback errorCallback_;
EventCallback closeCallback_;
EventCallback eventCallback_;
std::weak_ptr<void> tie_;
bool tied_;
bool tied_;
};
} // namespace trantor
Loading