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 <Hail2Santa@gmail.com>

* fold doc 1 (#1009)

* minor fold cleanup

* fold doc I

* enough

* rename

* last

---------

Co-authored-by: HailSanta <Hail2Santa@gmail.com>

* 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 <serge_zorkin@mail.ru>

* tiny fix

---------

Co-authored-by: Unnunu <serge_zorkin@mail.ru>

* 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 <rainmachus@gmail.com>
Co-authored-by: Unnunu <serge_zorkin@mail.ru>

* 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 <Hail2Santa@gmail.com>

* 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 <Hail2Santa@gmail.com>

* btl cam modes (#1035)

* some btl cam

* couple things

---------

Co-authored-by: HailSanta <Hail2Santa@gmail.com>

* Add version option to diff.py (#1037)

* Clean trailing whitespace (#1038)

* Add missing newlines

* Remove trailing whitepace

* split em (#1040)

Co-authored-by: HailSanta <Hail2Santa@gmail.com>

* Update .git-blame-ignore-revs (#1039)

* standardized battle script names (#1043)

* damage intensity

* standardized battle script names

* few more

---------

Co-authored-by: HailSanta <Hail2Santa@gmail.com>

* Dump PAL filemenu section (#1036)

* Dump PAL filemenu section

Co-authored-by: Unnunu <serge_zorkin@mail.ru>

* 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 <serge_zorkin@mail.ru>
Co-authored-by: Ethan Roseman <ethteck@gmail.com>

* revert test change

* update clang-format config

* indent case labels

---------

Co-authored-by: Marijn van der Werf <marijn.vanderwerf@gmail.com>
Co-authored-by: CreateSource <72283721+abnormalhare@users.noreply.github.com>
Co-authored-by: HailSanta <53960937+HailSanta@users.noreply.github.com>
Co-authored-by: HailSanta <Hail2Santa@gmail.com>
Co-authored-by: Ethan Roseman <ethteck@gmail.com>
Co-authored-by: Unnunu <serge_zorkin@mail.ru>
Co-authored-by: Mr-Wiseguy <68165316+Mr-Wiseguy@users.noreply.github.com>
Co-authored-by: Rainchus <rainmachus@gmail.com>
Co-authored-by: Julian <hi@notnite.com>
Co-authored-by: Devon R <Gorialis@users.noreply.github.com>
This commit is contained in:
Alex Bates 2023-05-01 21:07:31 +01:00 committed by GitHub
parent 31c98cc94c
commit 4680a74e0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 93 additions and 60 deletions

63
.clang-format Normal file
View File

@ -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
---
...

View File

@ -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

View File

@ -4,6 +4,7 @@
"nanaian.vscode-star-rod",
"notskm.clang-tidy",
"EditorConfig.EditorConfig",
"xaver.clang-format"
],
"unwantedRecommendations": [
"llvm-vs-code-extensions.vscode-clangd",

View File

@ -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",

View File

@ -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