From 4b0512f560246da5f816621eb1ed8a740a3cd514 Mon Sep 17 00:00:00 2001 From: Chris Sidebottom Date: Mon, 9 Jun 2025 22:23:17 +0100 Subject: [PATCH 1/2] Add cpp-linter action This uses the same .clang-format as numpy for consistency. --- .clang-format | 37 ++++++++++++++++++++++++++++++++ .github/workflows/cpp-linter.yml | 25 +++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 .clang-format create mode 100644 .github/workflows/cpp-linter.yml diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..034478a --- /dev/null +++ b/.clang-format @@ -0,0 +1,37 @@ +# A clang-format style that approximates Python's PEP 7 +# Useful for IDE integration +# +# Based on Paul Ganssle's version at +# https://gist.github.com/pganssle/0e3a5f828b4d07d79447f6ced8e7e4db +# and modified for NumPy +BasedOnStyle: Google +AlignAfterOpenBracket: Align +AllowShortEnumsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: false +AlwaysBreakAfterReturnType: TopLevel +BreakBeforeBraces: Stroustrup +ColumnLimit: 88 +ContinuationIndentWidth: 8 +DerivePointerAlignment: false +IndentWidth: 4 +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^[<"](Python|structmember|pymem)\.h' + Priority: -3 + CaseSensitive: true + - Regex: '^"numpy/' + Priority: -2 + - Regex: '^"(npy_pycompat|npy_config)' + Priority: -1 + - Regex: '^"[[:alnum:]_.]+"' + Priority: 1 + - Regex: '^<[[:alnum:]_.]+"' + Priority: 2 +Language: Cpp +PointerAlignment: Right +ReflowComments: true +SpaceBeforeParens: ControlStatements +SpacesInParentheses: false +StatementMacros: [PyObject_HEAD, PyObject_VAR_HEAD, PyObject_HEAD_EXTRA] +TabWidth: 4 +UseTab: Never diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml new file mode 100644 index 0000000..1a0a993 --- /dev/null +++ b/.github/workflows/cpp-linter.yml @@ -0,0 +1,25 @@ +name: cpp-linter + +on: + pull_request: + branches: + - main + paths: + - "npsr/*" + +jobs: + cpp-linter: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + - uses: cpp-linter/cpp-linter-action@f91c446a32ae3eb9f98fef8c9ed4c7cb613a4f8a + id: linter + continue-on-error: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + style: "file" + + - name: Linter Outputs + if: steps.linter.outputs.checks-failed != 0 + run: exit 1 From b7311619d8d180d056f7c8220255c47f0b8766f9 Mon Sep 17 00:00:00 2001 From: Chris Sidebottom Date: Tue, 10 Jun 2025 10:06:20 +0100 Subject: [PATCH 2/2] Move to just Google style for C++ --- .clang-format | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/.clang-format b/.clang-format index 034478a..f6cb8ad 100644 --- a/.clang-format +++ b/.clang-format @@ -1,37 +1 @@ -# A clang-format style that approximates Python's PEP 7 -# Useful for IDE integration -# -# Based on Paul Ganssle's version at -# https://gist.github.com/pganssle/0e3a5f828b4d07d79447f6ced8e7e4db -# and modified for NumPy BasedOnStyle: Google -AlignAfterOpenBracket: Align -AllowShortEnumsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AlwaysBreakAfterReturnType: TopLevel -BreakBeforeBraces: Stroustrup -ColumnLimit: 88 -ContinuationIndentWidth: 8 -DerivePointerAlignment: false -IndentWidth: 4 -IncludeBlocks: Regroup -IncludeCategories: - - Regex: '^[<"](Python|structmember|pymem)\.h' - Priority: -3 - CaseSensitive: true - - Regex: '^"numpy/' - Priority: -2 - - Regex: '^"(npy_pycompat|npy_config)' - Priority: -1 - - Regex: '^"[[:alnum:]_.]+"' - Priority: 1 - - Regex: '^<[[:alnum:]_.]+"' - Priority: 2 -Language: Cpp -PointerAlignment: Right -ReflowComments: true -SpaceBeforeParens: ControlStatements -SpacesInParentheses: false -StatementMacros: [PyObject_HEAD, PyObject_VAR_HEAD, PyObject_HEAD_EXTRA] -TabWidth: 4 -UseTab: Never