Skip to content

Commit 6d2137c

Browse files
committed
chore: Add clang-format
1 parent 1f12bc1 commit 6d2137c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+761
-774
lines changed

.clang-format

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
BasedOnStyle: Google
2+
AccessModifierOffset: -2
3+
BreakBeforeTernaryOperators: true
4+
BreakConstructorInitializers: BeforeComma
5+
ConstructorInitializerIndentWidth: 2
6+
BracedInitializerIndentWidth: 2
7+
ContinuationIndentWidth: 2
8+
Cpp11BracedListStyle: true
9+
IndentAccessModifiers: false
10+
InsertNewlineAtEOF: true
11+
LambdaBodyIndentation: Signature
12+
AlignAfterOpenBracket: BlockIndent
13+
AllowShortIfStatementsOnASingleLine: Never
14+
BinPackArguments: false
15+
BinPackParameters: false
16+
AllowShortLambdasOnASingleLine: All
17+
SpacesBeforeTrailingComments: 1
18+
BreakBeforeBraces: Custom
19+
BraceWrapping:
20+
AfterCaseLabel: true
21+
AfterClass: true
22+
AfterControlStatement: Always
23+
AfterEnum: true
24+
AfterFunction: true
25+
AfterNamespace: false
26+
AfterStruct: true
27+
AfterUnion: true
28+
AfterExternBlock: false
29+
BeforeCatch: true
30+
BeforeElse: true
31+
BeforeLambdaBody: true
32+
IndentBraces: false
33+
BeforeWhile: true
34+
SplitEmptyFunction: false
35+
SplitEmptyRecord: false
36+
SplitEmptyNamespace: false
37+
IncludeCategories:
38+
- Regex: '^<.*>'
39+
Priority: 1
40+
- Regex: '^"maddy/.*'
41+
Priority: 3
42+
- Regex: '.*'
43+
Priority: 2
44+
SortIncludes: true
45+
IncludeBlocks: Regroup
46+
InsertTrailingCommas: Wrapped

.editorconfig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@ indent_style = space
88
insert_final_newline = true
99
trim_trailing_whitespace = true
1010

11-
[*.{h,hh,hpp,c,cc,cpp,cxx,yml}]
11+
[*.{h,hh,hpp,c,cc,cpp,cxx,yml,py,md}]
12+
indent_size = 2
13+
14+
[CMakeLists.txt]
1215
indent_size = 2
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Format Dry Run
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
dry-run:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v2
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: '3.8'
21+
22+
- name: Install clang-format
23+
run: |
24+
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
25+
sudo add-apt-repository "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs) main"
26+
sudo apt-get update
27+
sudo apt-get install -y clang-format-18=18.1.8
28+
sudo ln -s /usr/bin/clang-format-18 /usr/bin/clang-format
29+
30+
- name: Run format script with dry_run
31+
run: |
32+
python tools/format.py dry_run

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ maddy uses [semver versioning](https://semver.org/).
1515
## Upcoming
1616

1717
* ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) Updated google test to v1.15.0.
18+
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) clang-format
1819

1920
## version 1.3.0 2023-08-26
2021

include/maddy/blockparser.h

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include <sstream>
1111
#include <string>
1212
// windows compatibility includes
13-
#include <cctype>
1413
#include <algorithm>
14+
#include <cctype>
1515

1616
// -----------------------------------------------------------------------------
1717

@@ -36,11 +36,13 @@ class BlockParser
3636
*
3737
* @method
3838
* @param {std::function<void(std::string&)>} parseLineCallback
39-
* @param {std::function<std::shared_ptr<BlockParser>(const std::string& line)>} getBlockParserForLineCallback
39+
* @param {std::function<std::shared_ptr<BlockParser>(const std::string&
40+
* line)>} getBlockParserForLineCallback
4041
*/
4142
BlockParser(
4243
std::function<void(std::string&)> parseLineCallback,
43-
std::function<std::shared_ptr<BlockParser>(const std::string& line)> getBlockParserForLineCallback
44+
std::function<std::shared_ptr<BlockParser>(const std::string& line)>
45+
getBlockParserForLineCallback
4446
)
4547
: result("", std::ios_base::ate | std::ios_base::in | std::ios_base::out)
4648
, childParser(nullptr)
@@ -64,8 +66,7 @@ class BlockParser
6466
* @param {std::string&} line
6567
* @return {void}
6668
*/
67-
virtual void
68-
AddLine(std::string& line)
69+
virtual void AddLine(std::string& line)
6970
{
7071
this->parseBlock(line);
7172

@@ -113,11 +114,7 @@ class BlockParser
113114
* @method
114115
* @return {std::stringstream}
115116
*/
116-
std::stringstream&
117-
GetResult()
118-
{
119-
return this->result;
120-
}
117+
std::stringstream& GetResult() { return this->result; }
121118

122119
/**
123120
* Clear
@@ -129,11 +126,7 @@ class BlockParser
129126
* @method
130127
* @return {void}
131128
*/
132-
void
133-
Clear()
134-
{
135-
this->result.str("");
136-
}
129+
void Clear() { this->result.str(""); }
137130

138131
protected:
139132
std::stringstream result;
@@ -143,47 +136,42 @@ class BlockParser
143136
virtual bool isLineParserAllowed() const = 0;
144137
virtual void parseBlock(std::string& line) = 0;
145138

146-
void
147-
parseLine(std::string& line)
139+
void parseLine(std::string& line)
148140
{
149141
if (parseLineCallback)
150142
{
151143
parseLineCallback(line);
152144
}
153145
}
154146

155-
uint32_t
156-
getIndentationWidth(const std::string& line) const
147+
uint32_t getIndentationWidth(const std::string& line) const
157148
{
158149
bool hasMetNonSpace = false;
159150

160-
uint32_t indentation = static_cast<uint32_t>(
161-
std::count_if(
162-
line.begin(),
163-
line.end(),
164-
[&hasMetNonSpace](unsigned char c)
151+
uint32_t indentation = static_cast<uint32_t>(std::count_if(
152+
line.begin(),
153+
line.end(),
154+
[&hasMetNonSpace](unsigned char c)
155+
{
156+
if (hasMetNonSpace)
165157
{
166-
if (hasMetNonSpace)
167-
{
168-
return false;
169-
}
170-
171-
if (std::isspace(c))
172-
{
173-
return true;
174-
}
175-
176-
hasMetNonSpace = true;
177158
return false;
178159
}
179-
)
180-
);
160+
161+
if (std::isspace(c))
162+
{
163+
return true;
164+
}
165+
166+
hasMetNonSpace = true;
167+
return false;
168+
}
169+
));
181170

182171
return indentation;
183172
}
184173

185-
std::shared_ptr<BlockParser>
186-
getBlockParserForLine(const std::string& line)
174+
std::shared_ptr<BlockParser> getBlockParserForLine(const std::string& line)
187175
{
188176
if (getBlockParserForLineCallback)
189177
{
@@ -195,7 +183,8 @@ class BlockParser
195183

196184
private:
197185
std::function<void(std::string&)> parseLineCallback;
198-
std::function<std::shared_ptr<BlockParser>(const std::string& line)> getBlockParserForLineCallback;
186+
std::function<std::shared_ptr<BlockParser>(const std::string& line)>
187+
getBlockParserForLineCallback;
199188
}; // class BlockParser
200189

201190
// -----------------------------------------------------------------------------

include/maddy/breaklineparser.h

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

77
// -----------------------------------------------------------------------------
88

9-
#include <string>
109
#include <regex>
10+
#include <string>
1111

1212
#include "maddy/lineparser.h"
1313

@@ -36,8 +36,7 @@ class BreakLineParser : public LineParser
3636
* @param {std::string&} line The line to interpret
3737
* @return {void}
3838
*/
39-
void
40-
Parse(std::string& line) override
39+
void Parse(std::string& line) override
4140
{
4241
static std::regex re(R"((\r\n|\r))");
4342
static std::string replacement = "<br>";

include/maddy/checklistparser.h

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ class ChecklistParser : public BlockParser
3131
*
3232
* @method
3333
* @param {std::function<void(std::string&)>} parseLineCallback
34-
* @param {std::function<std::shared_ptr<BlockParser>(const std::string& line)>} getBlockParserForLineCallback
34+
* @param {std::function<std::shared_ptr<BlockParser>(const std::string&
35+
* line)>} getBlockParserForLineCallback
3536
*/
36-
ChecklistParser(
37+
ChecklistParser(
3738
std::function<void(std::string&)> parseLineCallback,
38-
std::function<std::shared_ptr<BlockParser>(const std::string& line)> getBlockParserForLineCallback
39+
std::function<std::shared_ptr<BlockParser>(const std::string& line)>
40+
getBlockParserForLineCallback
3941
)
4042
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
4143
, isStarted(false)
@@ -51,8 +53,7 @@ class ChecklistParser : public BlockParser
5153
* @param {const std::string&} line
5254
* @return {bool}
5355
*/
54-
static bool
55-
IsStartingLine(const std::string& line)
56+
static bool IsStartingLine(const std::string& line)
5657
{
5758
static std::regex re(R"(^- \[[x| ]\] .*)");
5859
return std::regex_match(line, re);
@@ -64,27 +65,14 @@ class ChecklistParser : public BlockParser
6465
* @method
6566
* @return {bool}
6667
*/
67-
bool
68-
IsFinished() const override
69-
{
70-
return this->isFinished;
71-
}
68+
bool IsFinished() const override { return this->isFinished; }
7269

7370
protected:
74-
bool
75-
isInlineBlockAllowed() const override
76-
{
77-
return true;
78-
}
71+
bool isInlineBlockAllowed() const override { return true; }
7972

80-
bool
81-
isLineParserAllowed() const override
82-
{
83-
return true;
84-
}
73+
bool isLineParserAllowed() const override { return true; }
8574

86-
void
87-
parseBlock(std::string& line) override
75+
void parseBlock(std::string& line) override
8876
{
8977
bool isStartOfNewListItem = IsStartingLine(line);
9078
uint32_t indentation = getIndentationWidth(line);
@@ -97,7 +85,8 @@ class ChecklistParser : public BlockParser
9785
line = std::regex_replace(line, emptyBoxRegex, emptyBoxReplacement);
9886

9987
static std::regex boxRegex(R"(^\[x\])");
100-
static std::string boxReplacement = "<input type=\"checkbox\" checked=\"checked\"/>";
88+
static std::string boxReplacement =
89+
"<input type=\"checkbox\" checked=\"checked\"/>";
10190
line = std::regex_replace(line, boxRegex, boxReplacement);
10291

10392
if (!this->isStarted)
@@ -113,11 +102,9 @@ class ChecklistParser : public BlockParser
113102
return;
114103
}
115104

116-
if (
117-
line.empty() ||
118-
line.find("</label></li><li><label>") != std::string::npos ||
119-
line.find("</label></li></ul>") != std::string::npos
120-
)
105+
if (line.empty() ||
106+
line.find("</label></li><li><label>") != std::string::npos ||
107+
line.find("</label></li></ul>") != std::string::npos)
121108
{
122109
line = "</label></li></ul>" + line;
123110
this->isFinished = true;

0 commit comments

Comments
 (0)