From 19746e177a1bbc30f9000f6ee7ea32311de7e28b Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Fri, 8 Mar 2024 22:18:39 +0800 Subject: [PATCH] [1_7] clang-format --- .clang-format | 14 ++++++++++++ .github/workflows/clang-format-linter.yml | 26 +++++++++++++++++++++++ Data/Drd/drd_info.hpp | 2 +- bin/format | 21 ++++++++++++++++++ bin/format.bat | 1 + tests/Data/Scheme/block_test.cpp | 2 +- tests/Kernel/Types/modification_test.cpp | 2 +- 7 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 .clang-format create mode 100644 .github/workflows/clang-format-linter.yml create mode 100644 bin/format create mode 100644 bin/format.bat diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..6258d86 --- /dev/null +++ b/.clang-format @@ -0,0 +1,14 @@ +Standard: Cpp11 +SpaceBeforeAssignmentOperators: false +SpaceBeforeParens: Always +AlwaysBreakAfterReturnType: TopLevelDefinitions +AllowShortIfStatementsOnASingleLine: AllIfsAndElse +AlignConsecutiveAssignments: Consecutive +AlignConsecutiveDeclarations: Consecutive +SpaceAfterCStyleCast: true +AllowShortFunctionsOnASingleLine: All +BreakBeforeBraces: Custom +BraceWrapping: + BeforeElse: true +PointerAlignment: Left +CommentPragmas: '^\\.+' diff --git a/.github/workflows/clang-format-linter.yml b/.github/workflows/clang-format-linter.yml new file mode 100644 index 0000000..45c689c --- /dev/null +++ b/.github/workflows/clang-format-linter.yml @@ -0,0 +1,26 @@ +name: Lint + +on: + pull_request: + branches: [ main ] + paths: + - 'Data/**' + - 'Kernel/**' + - 'tests/**' + - '.github/workflows/clang-format-linter.yml' + - 'xmake.lua' + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: DoozyX/clang-format-lint-action@v0.16.2 + with: + source: '.' + exclude: './build ./xmake ./workflow ./github' + extensions: 'hpp,cpp' + clangFormatVersion: 16 + style: file \ No newline at end of file diff --git a/Data/Drd/drd_info.hpp b/Data/Drd/drd_info.hpp index 1263693..88f37e9 100644 --- a/Data/Drd/drd_info.hpp +++ b/Data/Drd/drd_info.hpp @@ -12,11 +12,11 @@ #ifndef DRD_INFO_H #define DRD_INFO_H +#include "path.hpp" #include "rel_hashmap.hpp" #include "tag_info.hpp" #include "tree.hpp" #include "tree_label.hpp" -#include "path.hpp" class drd_info; class drd_info_rep : concrete_struct { diff --git a/bin/format b/bin/format new file mode 100644 index 0000000..4003524 --- /dev/null +++ b/bin/format @@ -0,0 +1,21 @@ +#!/usr/bin/env elvish + +use platform + +if (eq $platform:os windows) { + set paths = [ + ~/scoop/shims/ + ~/scoop/apps/llvm/current/bin + ] +} elif (eq $platform:os linux) { + set paths = [ + /usr/lib/llvm-16/bin + $E:HOME/bin + ] +} else { +} + +# pin clang-format to 16.0.x +clang-format --version +clang-format -i **/*cpp +clang-format -i **/*hpp diff --git a/bin/format.bat b/bin/format.bat new file mode 100644 index 0000000..ee04f96 --- /dev/null +++ b/bin/format.bat @@ -0,0 +1 @@ +elvish bin\format diff --git a/tests/Data/Scheme/block_test.cpp b/tests/Data/Scheme/block_test.cpp index 6c477a9..08c6504 100644 --- a/tests/Data/Scheme/block_test.cpp +++ b/tests/Data/Scheme/block_test.cpp @@ -5,9 +5,9 @@ * \date 2024 */ -#include "moe_doctests.hpp" #include "block.hpp" #include "file.hpp" +#include "moe_doctests.hpp" #include "string.hpp" #include "tm_ostream.hpp" diff --git a/tests/Kernel/Types/modification_test.cpp b/tests/Kernel/Types/modification_test.cpp index d9127c0..b923de0 100644 --- a/tests/Kernel/Types/modification_test.cpp +++ b/tests/Kernel/Types/modification_test.cpp @@ -1,5 +1,5 @@ -#include "moe_doctests.hpp" #include "modification.hpp" +#include "moe_doctests.hpp" TEST_CASE ("test construct func") { modification m1 (MOD_ASSIGN, path (), tree ());