Skip to content
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

Feature/update clang format 16 #908

Merged
merged 12 commits into from
Oct 19, 2023
20 changes: 6 additions & 14 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignAfterOpenBracket: BlockIndent
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
Expand All @@ -18,20 +18,8 @@ AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
BreakBeforeBinaryOperators: false
BreakBeforeBraces: Custom
BreakBeforeBraces: WebKit
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
ColumnLimit: 120
Expand All @@ -43,6 +31,7 @@ Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros: [ Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^<(BeastConfig)'
Expand All @@ -58,6 +47,8 @@ IndentCaseLabels: true
IndentFunctionDeclarationAfterType: false
IndentWidth: 4
IndentWrappedFunctionNames: false
IndentRequiresClause: true
RequiresClausePosition: OwnLine
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
Expand All @@ -70,6 +61,7 @@ PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
QualifierAlignment: Right
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
Expand Down
16 changes: 15 additions & 1 deletion .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,21 @@ exec 1>&2

# paths to check and re-format
sources="src unittests"
formatter="clang-format-11 -i"
formatter="clang-format -i"
version=$($formatter --version | awk -F'[[:space:]]' '{print $4}')

if [[ "16.0.0" > "$version" ]]; then
cat <<\EOF

ERROR
-----------------------------------------------------------------------------
A minimum of version 16 of `clang-format` is required.
Please fix paths and run again.
-----------------------------------------------------------------------------

EOF
exit 2
fi

first=$(git diff $sources)
find $sources -type f \( -name '*.cpp' -o -name '*.h' -o -name '*.ipp' \) -print0 | xargs -0 $formatter
Expand Down
20 changes: 16 additions & 4 deletions .github/actions/clang_format/action.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
name: Check format
description: Check format using clang-format-11
description: Check format using clang-format-16
runs:
using: composite
steps:
# Github's ubuntu-20.04 image already has clang-format-11 installed
- run: |
find src unittests -type f \( -name '*.cpp' -o -name '*.h' -o -name '*.ipp' \) -print0 | xargs -0 clang-format-11 -i
- name: Add llvm repo
run: |
echo 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-16 main' | sudo tee -a /etc/apt/sources.list
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
shell: bash

- name: Install packages
run: |
sudo apt update -qq
sudo apt install -y jq clang-format-16
shell: bash

- name: Run formatter
run: |
find src unittests -type f \( -name '*.cpp' -o -name '*.h' -o -name '*.ipp' \) -print0 | xargs -0 clang-format-16 -i
shell: bash

- name: Check for differences
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ The button for that is near the bottom of the PR's page on GitHub.
This is a non-exhaustive list of recommended style guidelines. These are not always strictly enforced and serve as a way to keep the codebase coherent.

## Formatting
Code must conform to `clang-format` version 10, unless the result would be unreasonably difficult to read or maintain.
Code must conform to `clang-format` version 16, unless the result would be unreasonably difficult to read or maintain.
To change your code to conform use `clang-format -i <your changed files>`.

## Avoid
Expand Down
4 changes: 1 addition & 3 deletions src/data/BackendCounters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ namespace data {
BackendCounters::PtrType
BackendCounters::make()
{
struct EnableMakeShared : public BackendCounters
{
};
struct EnableMakeShared : public BackendCounters {};
return std::make_shared<EnableMakeShared>();
}

Expand Down
6 changes: 2 additions & 4 deletions src/data/BackendCounters.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ concept SomeBackendCounters = requires(T a) {
* @brief Holds statistics about the backend.
* @note This class is thread-safe.
*/
class BackendCounters
{
class BackendCounters {
public:
using PtrType = std::shared_ptr<BackendCounters>;

Expand Down Expand Up @@ -96,8 +95,7 @@ class BackendCounters
private:
BackendCounters() = default;

class AsyncOperationCounters
{
class AsyncOperationCounters {
public:
AsyncOperationCounters(std::string name);

Expand Down
6 changes: 2 additions & 4 deletions src/data/BackendFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ make_Backend(util::Config const& config)
std::shared_ptr<BackendInterface> backend = nullptr;

// TODO: retire `cassandra-new` by next release after 2.0
if (boost::iequals(type, "cassandra") or boost::iequals(type, "cassandra-new"))
{
if (boost::iequals(type, "cassandra") or boost::iequals(type, "cassandra-new")) {
auto cfg = config.section("database." + type);
backend = std::make_shared<data::cassandra::CassandraBackend>(data::cassandra::SettingsProvider{cfg}, readOnly);
}
Expand All @@ -56,8 +55,7 @@ make_Backend(util::Config const& config)
throw std::runtime_error("Invalid database type");

auto const rng = backend->hardFetchLedgerRangeNoThrow();
if (rng)
{
if (rng) {
backend->updateRange(rng->minSequence);
backend->updateRange(rng->maxSequence);
}
Expand Down
Loading