From e9c230446a67b9681415e6de85bda9eee56c362e Mon Sep 17 00:00:00 2001 From: Bart Date: Fri, 22 Aug 2025 13:37:11 -0400 Subject: [PATCH] chore: Update clang-format and prettier with pre-commit (#5709) The change updates how clang-format is called in CI and locally, and adds prettier to the pre-commit hook. Proto files are now also formatted, while external files are excluded. --- .clang-format | 36 +++++++++++------------ .git-blame-ignore-revs | 4 +++ .pre-commit-config.yaml | 64 +++++++++++++++++++++++++++++++++++++++-- .prettierignore | 1 + 4 files changed, 82 insertions(+), 23 deletions(-) create mode 100644 .prettierignore diff --git a/.clang-format b/.clang-format index 9c3820a6b..bd446022d 100644 --- a/.clang-format +++ b/.clang-format @@ -1,4 +1,20 @@ --- +BreakBeforeBraces: Custom +BraceWrapping: + AfterClass: true + AfterControlStatement: true + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true + IndentBraces: false +KeepEmptyLinesAtTheStartOfBlocks: false +MaxEmptyLinesToKeep: 1 +--- Language: Cpp AccessModifierOffset: -4 AlignAfterOpenBracket: AlwaysBreak @@ -18,20 +34,7 @@ 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 BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: true ColumnLimit: 80 @@ -66,8 +69,6 @@ IndentFunctionDeclarationAfterType: false IndentRequiresClause: true IndentWidth: 4 IndentWrappedFunctionNames: false -KeepEmptyLinesAtTheStartOfBlocks: false -MaxEmptyLinesToKeep: 1 NamespaceIndentation: None ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: false @@ -96,11 +97,6 @@ TabWidth: 8 UseTab: Never QualifierAlignment: Right --- -Language: JavaScript ---- -Language: Json -IndentWidth: 2 ---- Language: Proto BasedOnStyle: Google ColumnLimit: 0 diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 6a9ad4822..8a3ecbc26 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -25,3 +25,7 @@ d25b5dcd568bb96c18e347d55fac10fe901a1bfb 02749feea88ce61c1f7eeb2d61a57d8ecf07ab11 # chore: Run prettier on all files (#5657) (rippled) 97f0747e103f13e26e45b731731059b32f7679ac +# chore: Reverts formatting changes to external files, adds formatting changes to proto files (#5711) (rippled) +b13370ac0d207217354f1fc1c29aef87769fb8a1 +# chore: Fix file formatting (#5718) (rippled) +896b8c3b54a22b0497cb0d1ce95e1095f9a227ce diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7daecdb5e..48ed82043 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,64 @@ -# .pre-commit-config.yaml +# To run pre-commit hooks, first install pre-commit: +# - `pip install pre-commit==${PRE_COMMIT_VERSION}` +# - `pip install pre-commit-hooks==${PRE_COMMIT_HOOKS_VERSION}` +# +# Depending on your system, you can use `brew install` or `apt install` as well +# for installing the pre-commit package, but `pip` is needed to install the +# hooks; you can also use `pipx` if you prefer. +# Next, install the required formatters: +# - `pip install clang-format==${CLANG_VERSION}` +# - `npm install prettier@${PRETTIER_VERSION}` +# +# See https://github.com/XRPLF/ci/blob/main/.github/workflows/tools-rippled.yml +# for the versions used in the CI pipeline. You will need to have the exact same +# versions of the tools installed on your system to produce the same results as +# the pipeline. +# +# Then, run the following command to install the git hook scripts: +# - `pre-commit install` +# You can run all configured hooks against all files with: +# - `pre-commit run --all-files` +# To manually run a specific hook, use: +# - `pre-commit run --all-files` +# To run the hooks against only the files changed in the current commit, use: +# - `pre-commit run` repos: - - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v18.1.8 + - repo: local hooks: - id: clang-format + name: clang-format + language: system + entry: clang-format -i + files: '\.(cpp|hpp|h|ipp|proto)$' + - id: trailing-whitespace + name: trailing-whitespace + entry: trailing-whitespace-fixer + language: system + types: [text] + - id: end-of-file + name: end-of-file + entry: end-of-file-fixer + language: system + types: [text] + - id: mixed-line-ending + name: mixed-line-ending + entry: mixed-line-ending + language: system + types: [text] + - id: check-merge-conflict + name: check-merge-conflict + entry: check-merge-conflict --assume-in-merge + language: system + types: [text] + - repo: local + hooks: + - id: prettier + name: prettier + language: system + entry: prettier --ignore-unknown --write + +exclude: | + (?x)^( + external/.*| + Builds/scripts/levelization/results/.*\.txt + )$ diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..5446323fa --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +external