mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-04 19:25:51 +00:00
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.
This commit is contained in:
@@ -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
|
Language: Cpp
|
||||||
AccessModifierOffset: -4
|
AccessModifierOffset: -4
|
||||||
AlignAfterOpenBracket: AlwaysBreak
|
AlignAfterOpenBracket: AlwaysBreak
|
||||||
@@ -18,20 +34,7 @@ AlwaysBreakBeforeMultilineStrings: true
|
|||||||
AlwaysBreakTemplateDeclarations: true
|
AlwaysBreakTemplateDeclarations: true
|
||||||
BinPackArguments: false
|
BinPackArguments: false
|
||||||
BinPackParameters: 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
|
BreakBeforeBinaryOperators: false
|
||||||
BreakBeforeBraces: Custom
|
|
||||||
BreakBeforeTernaryOperators: true
|
BreakBeforeTernaryOperators: true
|
||||||
BreakConstructorInitializersBeforeComma: true
|
BreakConstructorInitializersBeforeComma: true
|
||||||
ColumnLimit: 80
|
ColumnLimit: 80
|
||||||
@@ -66,8 +69,6 @@ IndentFunctionDeclarationAfterType: false
|
|||||||
IndentRequiresClause: true
|
IndentRequiresClause: true
|
||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
IndentWrappedFunctionNames: false
|
IndentWrappedFunctionNames: false
|
||||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
|
||||||
MaxEmptyLinesToKeep: 1
|
|
||||||
NamespaceIndentation: None
|
NamespaceIndentation: None
|
||||||
ObjCSpaceAfterProperty: false
|
ObjCSpaceAfterProperty: false
|
||||||
ObjCSpaceBeforeProtocolList: false
|
ObjCSpaceBeforeProtocolList: false
|
||||||
@@ -96,11 +97,6 @@ TabWidth: 8
|
|||||||
UseTab: Never
|
UseTab: Never
|
||||||
QualifierAlignment: Right
|
QualifierAlignment: Right
|
||||||
---
|
---
|
||||||
Language: JavaScript
|
|
||||||
---
|
|
||||||
Language: Json
|
|
||||||
IndentWidth: 2
|
|
||||||
---
|
|
||||||
Language: Proto
|
Language: Proto
|
||||||
BasedOnStyle: Google
|
BasedOnStyle: Google
|
||||||
ColumnLimit: 0
|
ColumnLimit: 0
|
||||||
|
|||||||
@@ -12,3 +12,5 @@ fe9a5365b8a52d4acc42eb27369247e6f238a4f9
|
|||||||
9a93577314e6a8d4b4a8368cc9d2b15a5d8303e8
|
9a93577314e6a8d4b4a8368cc9d2b15a5d8303e8
|
||||||
552377c76f55b403a1c876df873a23d780fcc81c
|
552377c76f55b403a1c876df873a23d780fcc81c
|
||||||
97f0747e103f13e26e45b731731059b32f7679ac
|
97f0747e103f13e26e45b731731059b32f7679ac
|
||||||
|
b13370ac0d207217354f1fc1c29aef87769fb8a1
|
||||||
|
896b8c3b54a22b0497cb0d1ce95e1095f9a227ce
|
||||||
|
|||||||
24
.github/scripts/strategy-matrix/linux.json
vendored
24
.github/scripts/strategy-matrix/linux.json
vendored
@@ -2,21 +2,11 @@
|
|||||||
"architecture": [
|
"architecture": [
|
||||||
{
|
{
|
||||||
"platform": "linux/amd64",
|
"platform": "linux/amd64",
|
||||||
"runner": [
|
"runner": ["self-hosted", "Linux", "X64", "heavy"]
|
||||||
"self-hosted",
|
|
||||||
"Linux",
|
|
||||||
"X64",
|
|
||||||
"heavy"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"platform": "linux/arm64",
|
"platform": "linux/arm64",
|
||||||
"runner": [
|
"runner": ["self-hosted", "Linux", "ARM64", "heavy-arm64"]
|
||||||
"self-hosted",
|
|
||||||
"Linux",
|
|
||||||
"ARM64",
|
|
||||||
"heavy-arm64"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"os": [
|
"os": [
|
||||||
@@ -159,12 +149,6 @@
|
|||||||
"compiler_version": "19"
|
"compiler_version": "19"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"build_type": [
|
"build_type": ["Debug", "Release"],
|
||||||
"Debug",
|
"cmake_args": ["-Dunity=OFF", "-Dunity=ON"]
|
||||||
"Release"
|
|
||||||
],
|
|
||||||
"cmake_args": [
|
|
||||||
"-Dunity=OFF",
|
|
||||||
"-Dunity=ON"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|||||||
12
.github/scripts/strategy-matrix/macos.json
vendored
12
.github/scripts/strategy-matrix/macos.json
vendored
@@ -2,12 +2,7 @@
|
|||||||
"architecture": [
|
"architecture": [
|
||||||
{
|
{
|
||||||
"platform": "macos/arm64",
|
"platform": "macos/arm64",
|
||||||
"runner": [
|
"runner": ["self-hosted", "macOS", "ARM64", "mac-runner-m1"]
|
||||||
"self-hosted",
|
|
||||||
"macOS",
|
|
||||||
"ARM64",
|
|
||||||
"mac-runner-m1"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"os": [
|
"os": [
|
||||||
@@ -18,10 +13,7 @@
|
|||||||
"compiler_version": ""
|
"compiler_version": ""
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"build_type": [
|
"build_type": ["Debug", "Release"],
|
||||||
"Debug",
|
|
||||||
"Release"
|
|
||||||
],
|
|
||||||
"cmake_args": [
|
"cmake_args": [
|
||||||
"-Dunity=OFF -DCMAKE_POLICY_VERSION_MINIMUM=3.5",
|
"-Dunity=OFF -DCMAKE_POLICY_VERSION_MINIMUM=3.5",
|
||||||
"-Dunity=ON -DCMAKE_POLICY_VERSION_MINIMUM=3.5"
|
"-Dunity=ON -DCMAKE_POLICY_VERSION_MINIMUM=3.5"
|
||||||
|
|||||||
14
.github/scripts/strategy-matrix/windows.json
vendored
14
.github/scripts/strategy-matrix/windows.json
vendored
@@ -2,9 +2,7 @@
|
|||||||
"architecture": [
|
"architecture": [
|
||||||
{
|
{
|
||||||
"platform": "windows/amd64",
|
"platform": "windows/amd64",
|
||||||
"runner": [
|
"runner": ["windows-latest"]
|
||||||
"windows-latest"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"os": [
|
"os": [
|
||||||
@@ -15,12 +13,6 @@
|
|||||||
"compiler_version": ""
|
"compiler_version": ""
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"build_type": [
|
"build_type": ["Debug", "Release"],
|
||||||
"Debug",
|
"cmake_args": ["-Dunity=OFF", "-Dunity=ON"]
|
||||||
"Release"
|
|
||||||
],
|
|
||||||
"cmake_args": [
|
|
||||||
"-Dunity=OFF",
|
|
||||||
"-Dunity=ON"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|||||||
63
.github/workflows/check-format.yml
vendored
63
.github/workflows/check-format.yml
vendored
@@ -13,9 +13,9 @@ defaults:
|
|||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
clang-format:
|
pre-commit:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: ghcr.io/xrplf/ci/tools-rippled-clang-format
|
container: ghcr.io/xrplf/ci/tools-rippled-pre-commit
|
||||||
steps:
|
steps:
|
||||||
# The $GITHUB_WORKSPACE and ${{ github.workspace }} might not point to the
|
# The $GITHUB_WORKSPACE and ${{ github.workspace }} might not point to the
|
||||||
# same directory for jobs running in containers. The actions/checkout step
|
# same directory for jobs running in containers. The actions/checkout step
|
||||||
@@ -38,48 +38,11 @@ jobs:
|
|||||||
echo 'Checking environment variables.'
|
echo 'Checking environment variables.'
|
||||||
env | sort
|
env | sort
|
||||||
|
|
||||||
|
echo 'Checking pre-commit version.'
|
||||||
|
pre-commit --version
|
||||||
|
|
||||||
echo 'Checking clang-format version.'
|
echo 'Checking clang-format version.'
|
||||||
clang-format --version
|
clang-format --version
|
||||||
- name: Format code
|
|
||||||
run: find include src tests -type f \( -name '*.cpp' -o -name '*.hpp' -o -name '*.h' -o -name '*.ipp' \) -exec clang-format -i {} +
|
|
||||||
- name: Check for differences
|
|
||||||
env:
|
|
||||||
MESSAGE: |
|
|
||||||
One or more files did not conform to the formatting specified in
|
|
||||||
.clang-format. Maybe you did not run 'git-clang-format' or
|
|
||||||
'clang-format' before committing, or your version of clang-format
|
|
||||||
has an incompatibility with the one used here (see the "Check
|
|
||||||
configuration" step above).
|
|
||||||
|
|
||||||
Run 'git-clang-format --extensions cpp,h,hpp,ipp develop' in your
|
|
||||||
repo, and then commit and push the changes.
|
|
||||||
run: |
|
|
||||||
DIFF=$(git status --porcelain)
|
|
||||||
if [ -n "${DIFF}" ]; then
|
|
||||||
# Print the files that changed to give the contributor a hint about
|
|
||||||
# what to expect when running git-clang-format on their own machine.
|
|
||||||
git status
|
|
||||||
echo "${MESSAGE}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
prettier:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container: ghcr.io/xrplf/ci/tools-rippled-prettier
|
|
||||||
steps:
|
|
||||||
- name: Configure git safe.directory
|
|
||||||
run: |
|
|
||||||
git config --global --add safe.directory $GITHUB_WORKSPACE
|
|
||||||
git config --global --add safe.directory ${{ github.workspace }}
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
|
|
||||||
- name: Check configuration
|
|
||||||
run: |
|
|
||||||
echo 'Checking path.'
|
|
||||||
echo ${PATH} | tr ':' '\n'
|
|
||||||
|
|
||||||
echo 'Checking environment variables.'
|
|
||||||
env | sort
|
|
||||||
|
|
||||||
echo 'Checking NPM version.'
|
echo 'Checking NPM version.'
|
||||||
npm --version
|
npm --version
|
||||||
@@ -90,22 +53,22 @@ jobs:
|
|||||||
echo 'Checking prettier version.'
|
echo 'Checking prettier version.'
|
||||||
prettier --version
|
prettier --version
|
||||||
- name: Format code
|
- name: Format code
|
||||||
run: prettier --check .
|
run: pre-commit run --show-diff-on-failure --color=always --all-files
|
||||||
- name: Check for differences
|
- name: Check for differences
|
||||||
env:
|
env:
|
||||||
MESSAGE: |
|
MESSAGE: |
|
||||||
One or more files did not conform to the formatting rules specified
|
One or more files did not conform to the formatting. Maybe you did
|
||||||
by Prettier. Maybe you did not run 'prettier' before committing, or
|
not run 'pre-commit' before committing, or your version of
|
||||||
your version of prettier has an incompatibility with the one used
|
'clang-format' or 'prettier' has an incompatibility with the ones
|
||||||
here (see the "Check configuration" step above).
|
used here (see the "Check configuration" step above).
|
||||||
|
|
||||||
Run 'prettier --check .' in your repo, and then commit and push the
|
Run 'pre-commit run --all-files' in your repo, and then commit and
|
||||||
changes.
|
push the changes.
|
||||||
run: |
|
run: |
|
||||||
DIFF=$(git status --porcelain)
|
DIFF=$(git status --porcelain)
|
||||||
if [ -n "${DIFF}" ]; then
|
if [ -n "${DIFF}" ]; then
|
||||||
# Print the files that changed to give the contributor a hint about
|
# Print the files that changed to give the contributor a hint about
|
||||||
# what to expect when running prettier on their own machine.
|
# what to expect when running pre-commit on their own machine.
|
||||||
git status
|
git status
|
||||||
echo "${MESSAGE}"
|
echo "${MESSAGE}"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
4
.github/workflows/on-pr.yml
vendored
4
.github/workflows/on-pr.yml
vendored
@@ -69,7 +69,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: No-op
|
- name: No-op
|
||||||
run: echo ''
|
run: true
|
||||||
|
|
||||||
check-format:
|
check-format:
|
||||||
needs: should-run
|
needs: should-run
|
||||||
@@ -86,7 +86,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: No-op
|
- name: No-op
|
||||||
run: echo ''
|
run: true
|
||||||
outputs:
|
outputs:
|
||||||
conan_remote_name: ${{ env.CONAN_REMOTE_NAME }}
|
conan_remote_name: ${{ env.CONAN_REMOTE_NAME }}
|
||||||
conan_remote_url: ${{ env.CONAN_REMOTE_URL }}
|
conan_remote_url: ${{ env.CONAN_REMOTE_URL }}
|
||||||
|
|||||||
@@ -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 <hook_id> --all-files`
|
||||||
|
# To run the hooks against only the files changed in the current commit, use:
|
||||||
|
# - `pre-commit run`
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/pre-commit/mirrors-clang-format
|
- repo: local
|
||||||
rev: v18.1.8
|
|
||||||
hooks:
|
hooks:
|
||||||
- id: clang-format
|
- 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/.*|
|
||||||
|
.github/scripts/levelization/results/.*\.txt
|
||||||
|
)$
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
external
|
external
|
||||||
.*
|
|
||||||
|
|||||||
Reference in New Issue
Block a user