add astyle, update clang-tidy config

This commit is contained in:
Alex Bates 2020-08-17 23:07:13 +01:00
parent 7498c2dc1c
commit b5256e31ee
No known key found for this signature in database
GPG Key ID: 5E11C2DB78877706
7 changed files with 73 additions and 51 deletions

View File

@ -1,23 +0,0 @@
IndentWidth: 4
Language: Cpp
UseTab: Never
ColumnLimit: 120
PointerAlignment: Left
BreakBeforeBraces: Attach
SpaceAfterCStyleCast: false
Cpp11BracedListStyle: false
IndentCaseLabels: true
BinPackArguments: true
BinPackParameters: true
AlignAfterOpenBracket: Align
AlignOperands: true
BreakBeforeTernaryOperators: true
BreakBeforeBinaryOperators: None
AllowShortBlocksOnASingleLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AlignEscapedNewlines: Left
AlignTrailingComments: true
SortIncludes: false

View File

@ -1,5 +1,2 @@
Checks: '-*,readability-braces-around-statements'
WarningsAsErrors: ''
HeaderFilterRegex: '(src|include)\/.*\.h$'
FormatStyle: 'file'
CheckOptions:
Checks: '-*,clang-analyzer-core.*,clang-analyzer-deadcode.*,readability-*,-readability-magic-numbers,-readability-else-after-return,-readability-named-parameter,-readability-braces-around-statements,-clang-diagnostic-error'
HeaderFilterRegex: '(src|include)\/.*\.h'

39
.github/workflows/lint.yaml vendored Normal file
View File

@ -0,0 +1,39 @@
name: Lint
on:
push:
paths:
- 'src/*'
- 'include/*'
pull_request:
paths:
- 'src/*'
- 'include/*'
jobs:
build:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: ./install.sh
# lint files changed by the push/pr
- id: files
uses: trilom/file-changes-action@v1.2.4
with:
output: ' '
continue-on-error: true # see jitterbit/get-changed-files#7
- run: ./format.sh ${{ steps.files.outputs.files}}
# fail if any files were changed by ./format.sh
- id: files_formatted
uses: jackton1/find-changed-files@v1.1
with:
files: src, include
- name: Fail if any files reformatted
if: steps.files_formatted.outputs.files_changed == 'true'
run: |
git diff
exit 1

View File

@ -3,4 +3,5 @@
"editor.insertSpaces": true,
"files.eol": "\n",
"files.insertFinalNewline": true,
"editor.rulers": [120],
}

View File

@ -1,26 +1,34 @@
FORMAT_OPTS="-i -style=file"
TIDY_OPTS="-p . --fix --fix-errors"
COMPILER_OPTS="-fno-builtin -std=gnu90 -Iinclude -Isrc -D_LANGUAGE_C -DNON_MATCHING"
COMPILER_OPTS="-fno-builtin -std=gnu89 -Iinclude -Isrc -D_LANGUAGE_C"
shopt -s globstar
FILES="src/**/*.c include/*.h"
if (( $# > 0 )); then
echo "Formatting file(s) $*"
echo "Running clang-format..."
clang-format ${FORMAT_OPTS} "$@"
echo "Running clang-tidy..."
clang-tidy ${TIDY_OPTS} "$@" -- ${COMPILER_OPTS} &> /dev/null
echo "Adding missing final new lines..."
sed -i -e '$a\' "$@"
echo "Done formatting file(s) $*"
# 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
echo "Formatting C files. This will take a bit"
echo "Running clang-format..."
clang-format ${FORMAT_OPTS} src/**/*.c
echo "Running clang-tidy..."
clang-tidy ${TIDY_OPTS} src/**/*.c -- ${COMPILER_OPTS} &> /dev/null
echo "Adding missing final new lines..."
find src/ -type f -name "*.c" -exec sed -i -e '$a\' {} \;
echo "Done formatting all files."
# format
astyle ${FILES} \
--formatted --suffix=none \
--lineend=linux \
--convert-tabs \
--max-code-length=120 \
--min-conditional-indent=1 \
--style=attach \
--align-pointer=type --align-reference=name \
--indent-switches \
--indent-labels \
--pad-oper --pad-comma --pad-header --unpad-paren \
--attach-return-type \
# add newline at eof
find ${FILES} -exec sed -i -e '$a\' {} \;
# lint
clang-tidy -p . ${FILES} -- ${COMPILER_OPTS}

View File

@ -48,7 +48,7 @@ extern s16 D_8010CD10;
extern s16 D_8010CD12;
extern s32 D_801595A0;
extern char gCloudyFlowerFieldsBg[]; // "fla_bg"
extern char gSunnyFlowerFieldsBg[]; // "flb_bg"
extern char gSunnyFlowerFieldsBg[]; // "flb_bg"
extern BackgroundHeader gBackgroundImage;
extern s8 D_8014F12F;

View File

@ -8,8 +8,8 @@ if command -v apt-install &> /dev/null; then
if [[ $1 == "--extra" ]]; then
echo "Installing extra"
sudo apt install -y python3 python3-pip clang-tidy clang-format
python3 -m pip install stringcase
sudo apt install -y python3 python3-pip clang-tidy astyle || exit 1
python3 -m pip install stringcase || exit 1
fi
echo "Done"
@ -48,7 +48,7 @@ if command -v pacman &> /dev/null; then
if [[ $1 == "--extra" ]]; then
echo "Installing extra"
sudo pacman -S --noconfirm --needed python python-pip clang || exit 1
sudo pacman -S --noconfirm --needed python python-pip clang astyle || exit 1
python3 -m pip install stringcase || exit 1
fi