From 4680a74e0b6bc9241d1e88e8dd8c622519cbb908 Mon Sep 17 00:00:00 2001 From: Alex Bates Date: Mon, 1 May 2023 21:07:31 +0100 Subject: [PATCH] Introduce clang-format (#1004) * add basic .clang-format * configure vscode clang-format modified lines on save * update clang-format to only run on C files * add ci action to print clang-format diff * use GITHUB_BASE_REF * --binary * clang-format-14 * move workflow to pr.yaml * oops * checkout fetch-depth 0 * use cpp-linter-action * test * fail if step fails * log depth * fetch main * set fetch-depth * limit diff and run clang-format * use versioned clang-format * untiy actual code * fix argument order * colorize output * Clean up #989 * move cpp lint job to lint.yaml * disable vscode autoformat * add git hook to make sure assets/$version has been gitignored (#1006) * add git hook to make sure assets/ hasn't been gitignored * echo to stderr * quiet git check-ignore * add .v64 and .n64 to gitignore * Changed some variable names in state_title_screen (#1003) * Changed some variable names in state_title_screen.c * resolving pull request items * changed TitleData to TitleScreenGfxData across sys * replace gbi names with understandable ones * accidentally switched logo and pressStart * changed GfxData to ImgList * Renaming and b32 * Doing this but more * pause menu cleanup (#1008) * minor pause cleanup * macro * comments * second macro * delete macros * hm * pause message names * unused tutorial messages * oops --------- Co-authored-by: HailSanta * fold doc 1 (#1009) * minor fold cleanup * fold doc I * enough * rename * last --------- Co-authored-by: HailSanta * appendGfx_shading_palette (#1010) * cleanup & warnings for modern gcc * clean * stuff * diff.py update * Fix offset problem in struct * Fix texture issue in chapter_change * appendGfx_shading_palette * Convert tabs to spaces (#1012) * Add .git-blame-ignore-revs (#1014) # 1213a4adf0aa515d0c7c7e37db396363914fda2egit-blame * func_E02000AC (#1013) * draw_image_with_clipping (#1016) * draw_image_with_clipping Co-authored-by: Unnunu * tiny fix --------- Co-authored-by: Unnunu * npc_do_player_collision (#1017) * appendGfx_animator_node (#1018) * appendGfx_animator_node Co-authored-by: Mr-Wiseguy <68165316+Mr-Wiseguy@users.noreply.github.com> * find_similar_areas improvements * oopz --------- Co-authored-by: Mr-Wiseguy <68165316+Mr-Wiseguy@users.noreply.github.com> * lol 100% (#1019) Co-authored-by: Rainchus Co-authored-by: Unnunu * image fx (#1015) * more fold * fold render modes * fold rename 1 * fold rename 2 * fold rename 3 * imgfx struct reorg * post merge * the rest * extras * forgot these * done * ImgFx * ImgFX * check * misc cam stuff * ws --------- Co-authored-by: HailSanta * Pal pause (#1011) * PAL pause segment * PAL pause_gfx_en segment * Apply name changes * Merge gPauseBadgesElements * Rename ITEM_TYPE_FLAG_ENTITY_COLLECTIBLE * Split PAL and monolingual arrays * Nix support (#1020) Very hacky Will be maintained by @NotNite * use ARRAY_COUNT(ExtraDoubleRecipes) (#1023) * Replace python-githooks with manual command (#1027) * ui_images (#1021) * ui_images * Move French assets to their own folder * imgfx data (#1029) * various cleanup (#1030) * more fold * fold render modes * fold rename 1 * fold rename 2 * fold rename 3 * imgfx struct reorg * post merge * the rest * extras * forgot these * done * ImgFx * ImgFX * check * misc cam stuff * ws * misc * btl msg * 3 combine modes * 3 more * many more * screen overlays * stencil types * all screen transitions * jp build fix * another jp fix * iq fix * mystery battle enum added oOoOoOoOooo * DMG_SRC * starting battle cam presets --------- Co-authored-by: HailSanta * btl cam modes (#1035) * some btl cam * couple things --------- Co-authored-by: HailSanta * Add version option to diff.py (#1037) * Clean trailing whitespace (#1038) * Add missing newlines * Remove trailing whitepace * split em (#1040) Co-authored-by: HailSanta * Update .git-blame-ignore-revs (#1039) * standardized battle script names (#1043) * damage intensity * standardized battle script names * few more --------- Co-authored-by: HailSanta * Dump PAL filemenu section (#1036) * Dump PAL filemenu section Co-authored-by: Unnunu * Clean up numbers * Use more constants * Find more constants * Clean up a bit * eth cleanup * Clean up * Fix brace style * rename new file & funcs --------- Co-authored-by: Unnunu Co-authored-by: Ethan Roseman * revert test change * update clang-format config * indent case labels --------- Co-authored-by: Marijn van der Werf Co-authored-by: CreateSource <72283721+abnormalhare@users.noreply.github.com> Co-authored-by: HailSanta <53960937+HailSanta@users.noreply.github.com> Co-authored-by: HailSanta Co-authored-by: Ethan Roseman Co-authored-by: Unnunu Co-authored-by: Mr-Wiseguy <68165316+Mr-Wiseguy@users.noreply.github.com> Co-authored-by: Rainchus Co-authored-by: Julian Co-authored-by: Devon R --- .clang-format | 63 +++++++++++++++++++++++++++++++++++++ .github/workflows/lint.yaml | 46 +++++++++++++++------------ .vscode/extensions.json | 1 + .vscode/settings.json | 3 ++ format.sh | 40 ----------------------- 5 files changed, 93 insertions(+), 60 deletions(-) create mode 100644 .clang-format delete mode 100755 format.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000..7e2b497f1a --- /dev/null +++ b/.clang-format @@ -0,0 +1,63 @@ +DisableFormat: true # clang-format supports many filetypes +--- +Language: Cpp +DisableFormat: false +BasedOnStyle: WebKit +IndentWidth: 4 +UseTab: Never +ColumnLimit: 120 + +AllowShortIfStatementsOnASingleLine: false +AllowShortBlocksOnASingleLine: false + +BreakBeforeBraces: Custom +BraceWrapping: + # Place opening brace on next line if the statement is multi-line + # e.g. + # if (very + # long + # condition) + # { + AfterControlStatement: MultiLine + +IndentCaseLabels: true + +BreakBeforeBinaryOperators: NonAssignment + +ExperimentalAutoDetectBinPacking: true +BinPackParameters: false +AlignAfterOpenBracket: BlockIndent + +AlignConsecutiveAssignments: + Enabled: true + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: true + PadOperators: true +AlignConsecutiveDeclarations: # structs etc + Enabled: true + AcrossEmptyLines: false + AcrossComments: false +AlignConsecutiveMacros: + Enabled: true + AcrossEmptyLines: false + AcrossComments: false +AlignTrailingComments: true + +WhitespaceSensitiveMacros: ['STRINGIFY'] + +# Our include order is WIP so disable it +SortIncludes: false +IncludeCategories: + # common.h always comes first + - Regex: '^"common\.h"$' + Priority: 10 + # everything else + - Regex: '.*' + Priority: 1 + SortPriority: 0 + +AllowShortFunctionsOnASingleLine: None +--- + +... diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 29a5706a47..b5595d180e 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -1,29 +1,35 @@ name: Lint on: pull_request: - paths: - - 'src/*' - - 'include/*' - - 'format.sh' - - '.clang-tidy' jobs: - build: - name: Lint + cpp_lint: + name: Format and lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - - run: sudo apt-get install -y astyle clang-tidy - - - run: ./format.sh - - # Detect any files changed by ./format.sh - - id: files_formatted - uses: jackton1/find-changed-files@v1.1 + - name: Checkout + uses: actions/checkout@v2 with: - files: src, include - - - name: Fail if any files reformatted - if: steps.files_formatted.outputs.files_changed == 'true' + fetch-depth: 0 + - name: Git + run: | + git log --oneline --graph --max-count=100 + git log --oneline --graph --max-count=100 HEAD origin/main + - name: clang-format + run: | + git config --global color.ui always + git clang-format-14 --diff origin/main HEAD + git config --global color.ui auto + - name: Lint + uses: cpp-linter/cpp-linter-action@v2 + id: linter + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + style: file + lines-changed-only: diff + tidy-checks: '' + version: '15' + - name: Fail if lint failed + if: steps.linter.outputs.checks-failed > 0 run: exit 1 diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 2f631c13a7..09fea3e1af 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -4,6 +4,7 @@ "nanaian.vscode-star-rod", "notskm.clang-tidy", "EditorConfig.EditorConfig", + "xaver.clang-format" ], "unwantedRecommendations": [ "llvm-vs-code-extensions.vscode-clangd", diff --git a/.vscode/settings.json b/.vscode/settings.json index 9f4c463565..09222479f4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -35,6 +35,9 @@ ], "[c]": { "editor.wordSeparators": "`~!@#%^&*()-=+[{]}\\|;:'\",.<>/?", // no $, for scripts + "editor.formatOnSave": false, // TODO: enable this once we solve EVTs, see #1004 + "editor.formatOnSaveMode": "modifications", + "editor.defaultFormatter": "xaver.clang-format", }, "files.associations": { "*.h": "c", diff --git a/format.sh b/format.sh deleted file mode 100755 index 18385b414a..0000000000 --- a/format.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash - -COMPILER_OPTS="-std=gnu89 -Iinclude -Isrc -D_LANGUAGE_C" - -shopt -s globstar - -FILES="src/**/*.c include/*.h" -if (( $# > 0 )); then - # only process .c and .h files - FILES=$(echo "$@" | sed 's/ /\n/g' | grep '\.[ch]$') -fi - -if [[ -z $FILES ]]; then - echo "no .c or .h files specified" - exit -fi - -# format -astyle ${FILES} \ - --formatted --suffix=none \ - --lineend=linux \ - --convert-tabs \ - --max-code-length=120 \ - --min-conditional-indent=0 \ - --style=attach \ - --align-pointer=type --align-reference=name \ - --indent-switches \ - --pad-oper --pad-comma --pad-header --unpad-paren \ - --attach-return-type \ - --keep-one-line-blocks \ - --keep-one-line-statements - -# add newline at eof -find ${FILES} -exec sed -i -e '$a\' {} \; - -# lint -C_FILES=$(echo "$FILES" | grep '\.c$') -if [[ ! -z $C_FILES ]]; then - clang-tidy -p . ${C_FILES} -- ${COMPILER_OPTS} -fi