Skip to content

Commit 4ffa7bb

Browse files
committed
style & ci: Add .clang-format and Check Format workflow
1 parent b644aeb commit 4ffa7bb

34 files changed

+463
-650
lines changed

.clang-format

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: Microsoft
4+
AccessModifierOffset: -2
5+
AlignAfterOpenBracket: Align
6+
AlignConsecutiveMacros: false
7+
AlignConsecutiveAssignments: false
8+
AlignConsecutiveDeclarations: false
9+
AlignEscapedNewlines: Right
10+
AlignOperands: true
11+
AlignTrailingComments: true
12+
AllowAllArgumentsOnNextLine: true
13+
AllowAllConstructorInitializersOnNextLine: true
14+
AllowAllParametersOfDeclarationOnNextLine: true
15+
AllowShortBlocksOnASingleLine: false
16+
AllowShortCaseLabelsOnASingleLine: false
17+
AllowShortFunctionsOnASingleLine: None
18+
AllowShortLambdasOnASingleLine: All
19+
AllowShortIfStatementsOnASingleLine: Never
20+
AllowShortLoopsOnASingleLine: false
21+
AlwaysBreakAfterDefinitionReturnType: None
22+
AlwaysBreakAfterReturnType: None
23+
AlwaysBreakBeforeMultilineStrings: false
24+
AlwaysBreakTemplateDeclarations: MultiLine
25+
BinPackArguments: true
26+
BinPackParameters: true
27+
BraceWrapping:
28+
AfterCaseLabel: false
29+
AfterClass: true
30+
AfterControlStatement: true
31+
AfterEnum: true
32+
AfterFunction: true
33+
AfterNamespace: true
34+
AfterObjCDeclaration: true
35+
AfterStruct: true
36+
AfterUnion: false
37+
AfterExternBlock: true
38+
BeforeCatch: true
39+
BeforeElse: true
40+
IndentBraces: false
41+
SplitEmptyFunction: true
42+
SplitEmptyRecord: true
43+
SplitEmptyNamespace: true
44+
BreakBeforeBinaryOperators: None
45+
BreakBeforeBraces: Custom
46+
BreakBeforeInheritanceComma: false
47+
BreakInheritanceList: BeforeColon
48+
BreakBeforeTernaryOperators: true
49+
BreakConstructorInitializersBeforeComma: false
50+
BreakConstructorInitializers: BeforeColon
51+
BreakAfterJavaFieldAnnotations: false
52+
BreakStringLiterals: true
53+
ColumnLimit: 120
54+
CommentPragmas: '^ IWYU pragma:'
55+
CompactNamespaces: false
56+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
57+
ConstructorInitializerIndentWidth: 4
58+
ContinuationIndentWidth: 4
59+
Cpp11BracedListStyle: true
60+
DerivePointerAlignment: false
61+
DisableFormat: false
62+
ExperimentalAutoDetectBinPacking: false
63+
FixNamespaceComments: true
64+
ForEachMacros:
65+
- foreach
66+
- Q_FOREACH
67+
- BOOST_FOREACH
68+
IncludeBlocks: Preserve
69+
IncludeCategories:
70+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
71+
Priority: 2
72+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
73+
Priority: 3
74+
- Regex: '.*'
75+
Priority: 1
76+
IncludeIsMainRegex: '(Test)?$'
77+
IndentCaseLabels: false
78+
IndentPPDirectives: None
79+
IndentWidth: 4
80+
IndentWrappedFunctionNames: false
81+
JavaScriptQuotes: Leave
82+
JavaScriptWrapImports: true
83+
KeepEmptyLinesAtTheStartOfBlocks: true
84+
MacroBlockBegin: ''
85+
MacroBlockEnd: ''
86+
MaxEmptyLinesToKeep: 1
87+
NamespaceIndentation: None
88+
ObjCBinPackProtocolList: Auto
89+
ObjCBlockIndentWidth: 2
90+
ObjCSpaceAfterProperty: false
91+
ObjCSpaceBeforeProtocolList: true
92+
PenaltyBreakAssignment: 2
93+
PenaltyBreakBeforeFirstCallParameter: 19
94+
PenaltyBreakComment: 300
95+
PenaltyBreakFirstLessLess: 120
96+
PenaltyBreakString: 1000
97+
PenaltyBreakTemplateDeclaration: 10
98+
PenaltyExcessCharacter: 1000000
99+
PenaltyReturnTypeOnItsOwnLine: 1000
100+
PointerAlignment: Right
101+
ReflowComments: true
102+
SortIncludes: true
103+
SortUsingDeclarations: true
104+
SpaceAfterCStyleCast: false
105+
SpaceAfterLogicalNot: false
106+
SpaceAfterTemplateKeyword: true
107+
SpaceBeforeAssignmentOperators: true
108+
SpaceBeforeCpp11BracedList: false
109+
SpaceBeforeCtorInitializerColon: true
110+
SpaceBeforeInheritanceColon: true
111+
SpaceBeforeParens: ControlStatements
112+
SpaceBeforeRangeBasedForLoopColon: true
113+
SpaceInEmptyParentheses: false
114+
SpacesBeforeTrailingComments: 1
115+
SpacesInAngles: false
116+
SpacesInContainerLiterals: true
117+
SpacesInCStyleCastParentheses: false
118+
SpacesInParentheses: false
119+
SpacesInSquareBrackets: false
120+
Standard: Cpp11
121+
StatementMacros:
122+
- Q_UNUSED
123+
- QT_REQUIRE_VERSION
124+
TabWidth: 4
125+
UseTab: Never
126+
...
127+

.github/workflows/build_test.yml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
name: "CI: Build Test"
22

3-
on:
4-
push:
5-
paths-ignore:
6-
- '*.md'
7-
- '*/*.md'
8-
- '*/*/*.md'
9-
pull_request:
10-
paths-ignore:
11-
- '*.md'
12-
- '*/*.md'
13-
- '*/*/*.md'
3+
on: [push, pull_request]
144

155
env:
166
CMAKE_VERSION: 3.17.1

.github/workflows/check_format.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: "Check Format"
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
format:
7+
name: "Check Clang Format"
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- name: "Install clang-format-9"
12+
run: |
13+
sudo apt-get update
14+
sudo apt-get install clang-format-9
15+
- name: "Format Codes"
16+
run: clang-format-9 -i src/internal/*.cpp include/internal/*.hpp
17+
- name: Check diff
18+
run: git diff --exit-code HEAD
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
22

33
// QCodeEditor
4-
#include <QStyleSyntaxHighlighter> // Required for inheritance
54
#include <QHighlightRule>
5+
#include <QStyleSyntaxHighlighter> // Required for inheritance
66

77
// Qt
88
#include <QRegularExpression>
@@ -17,19 +17,17 @@ class QSyntaxStyle;
1717
class QCXXHighlighter : public QStyleSyntaxHighlighter
1818
{
1919
Q_OBJECT
20-
public:
21-
20+
public:
2221
/**
2322
* @brief Constructor.
2423
* @param document Pointer to document.
2524
*/
26-
explicit QCXXHighlighter(QTextDocument* document=nullptr);
25+
explicit QCXXHighlighter(QTextDocument *document = nullptr);
2726

28-
protected:
29-
void highlightBlock(const QString& text) override;
30-
31-
private:
27+
protected:
28+
void highlightBlock(const QString &text) override;
3229

30+
private:
3331
QVector<QHighlightRule> m_highlightRules;
3432

3533
QRegularExpression m_includePattern;
@@ -39,4 +37,3 @@ class QCXXHighlighter : public QStyleSyntaxHighlighter
3937
QRegularExpression m_commentStartPattern;
4038
QRegularExpression m_commentEndPattern;
4139
};
42-

include/internal/QGLSLCompleter.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ class QGLSLCompleter : public QCompleter
1111
{
1212
Q_OBJECT
1313

14-
public:
15-
14+
public:
1615
/**
1716
* @brief Constructor.
1817
* @param parent Pointer to parent QObject.
1918
*/
20-
explicit QGLSLCompleter(QObject* parent=nullptr);
19+
explicit QGLSLCompleter(QObject *parent = nullptr);
2120
};
22-
23-
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
22

33
// QCodeEditor
4-
#include <QStyleSyntaxHighlighter> // Required for inheritance
54
#include <QHighlightRule>
5+
#include <QStyleSyntaxHighlighter> // Required for inheritance
66

77
// Qt
88
#include <QRegularExpression>
@@ -17,19 +17,17 @@ class QSyntaxStyle;
1717
class QGLSLHighlighter : public QStyleSyntaxHighlighter
1818
{
1919
Q_OBJECT
20-
public:
21-
20+
public:
2221
/**
2322
* @brief Constructor.
2423
* @param document Pointer to document.
2524
*/
26-
explicit QGLSLHighlighter(QTextDocument* document=nullptr);
25+
explicit QGLSLHighlighter(QTextDocument *document = nullptr);
2726

28-
protected:
29-
void highlightBlock(const QString& text) override;
30-
31-
private:
27+
protected:
28+
void highlightBlock(const QString &text) override;
3229

30+
private:
3331
QVector<QHighlightRule> m_highlightRules;
3432

3533
QRegularExpression m_includePattern;
@@ -39,4 +37,3 @@ class QGLSLHighlighter : public QStyleSyntaxHighlighter
3937
QRegularExpression m_commentStartPattern;
4038
QRegularExpression m_commentEndPattern;
4139
};
42-

include/internal/QHighlightBlockRule.hpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@
66

77
struct QHighlightBlockRule
88
{
9-
QHighlightBlockRule() :
10-
startPattern(),
11-
endPattern(),
12-
formatName()
13-
{}
9+
QHighlightBlockRule() : startPattern(), endPattern(), formatName()
10+
{
11+
}
1412

15-
QHighlightBlockRule(QRegularExpression start, QRegularExpression end, QString format) :
16-
startPattern(std::move(start)),
17-
endPattern(std::move(end)),
18-
formatName(std::move(format))
19-
{}
13+
QHighlightBlockRule(QRegularExpression start, QRegularExpression end, QString format)
14+
: startPattern(std::move(start)), endPattern(std::move(end)), formatName(std::move(format))
15+
{
16+
}
2017

2118
QRegularExpression startPattern;
2219
QRegularExpression endPattern;

include/internal/QHighlightRule.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66

77
struct QHighlightRule
88
{
9-
QHighlightRule() :
10-
pattern(),
11-
formatName()
12-
{}
9+
QHighlightRule() : pattern(), formatName()
10+
{
11+
}
1312

14-
QHighlightRule(QRegularExpression p, QString f) :
15-
pattern(std::move(p)),
16-
formatName(std::move(f))
17-
{}
13+
QHighlightRule(QRegularExpression p, QString f) : pattern(std::move(p)), formatName(std::move(f))
14+
{
15+
}
1816

1917
QRegularExpression pattern;
2018
QString formatName;
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
22

33
// QCodeEditor
4-
#include <QStyleSyntaxHighlighter> // Required for inheritance
54
#include <QHighlightRule>
5+
#include <QStyleSyntaxHighlighter> // Required for inheritance
66

77
// Qt
88
#include <QVector>
@@ -14,20 +14,17 @@
1414
class QJSONHighlighter : public QStyleSyntaxHighlighter
1515
{
1616
Q_OBJECT
17-
public:
18-
17+
public:
1918
/**
2019
* @brief Constructor.
2120
* @param document Pointer to document.
2221
*/
23-
explicit QJSONHighlighter(QTextDocument* document=nullptr);
22+
explicit QJSONHighlighter(QTextDocument *document = nullptr);
2423

25-
protected:
24+
protected:
25+
void highlightBlock(const QString &text) override;
2626

27-
void highlightBlock(const QString& text) override;
28-
29-
private:
27+
private:
3028
QVector<QHighlightRule> m_highlightRules;
3129
QRegularExpression m_keyRegex;
3230
};
33-
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
22

33
// QCodeEditor
4-
#include <QStyleSyntaxHighlighter> // Required for inheritance
54
#include <QHighlightRule>
5+
#include <QStyleSyntaxHighlighter> // Required for inheritance
66

77
// Qt
88
#include <QRegularExpression>
@@ -16,27 +16,24 @@ class QSyntaxStyle;
1616
class QJavaHighlighter : public QStyleSyntaxHighlighter
1717
{
1818
Q_OBJECT
19-
public:
20-
19+
public:
2120
/**
2221
* @brief Constructs a new instance of a Java highlighter.
2322
* @param document The text document to be highlighted.
2423
* This may be a null pointer.
2524
*/
26-
explicit QJavaHighlighter(QTextDocument* document=nullptr);
25+
explicit QJavaHighlighter(QTextDocument *document = nullptr);
2726

28-
protected:
27+
protected:
2928
/**
3029
* @brief Derived to highlight blocks of Java code.
3130
* @param text The block of text containing Java code.
3231
*/
33-
void highlightBlock(const QString& text) override;
34-
35-
private:
32+
void highlightBlock(const QString &text) override;
3633

34+
private:
3735
QVector<QHighlightRule> m_highlightRules;
3836

3937
QRegularExpression m_commentStartPattern;
4038
QRegularExpression m_commentEndPattern;
4139
};
42-

0 commit comments

Comments
 (0)