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' 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'
WarningsAsErrors: '' HeaderFilterRegex: '(src|include)\/.*\.h'
HeaderFilterRegex: '(src|include)\/.*\.h$'
FormatStyle: 'file'
CheckOptions:

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, "editor.insertSpaces": true,
"files.eol": "\n", "files.eol": "\n",
"files.insertFinalNewline": true, "files.insertFinalNewline": true,
"editor.rulers": [120],
} }

View File

@ -1,26 +1,34 @@
FORMAT_OPTS="-i -style=file" COMPILER_OPTS="-fno-builtin -std=gnu89 -Iinclude -Isrc -D_LANGUAGE_C"
TIDY_OPTS="-p . --fix --fix-errors"
COMPILER_OPTS="-fno-builtin -std=gnu90 -Iinclude -Isrc -D_LANGUAGE_C -DNON_MATCHING"
shopt -s globstar shopt -s globstar
FILES="src/**/*.c include/*.h"
if (( $# > 0 )); then if (( $# > 0 )); then
echo "Formatting file(s) $*" # only process .c and .h files
echo "Running clang-format..." FILES=$(echo "$@" | sed 's/ /\n/g' | grep '.[ch]$')
clang-format ${FORMAT_OPTS} "$@" fi
echo "Running clang-tidy..."
clang-tidy ${TIDY_OPTS} "$@" -- ${COMPILER_OPTS} &> /dev/null if [[ -z $FILES ]]; then
echo "Adding missing final new lines..." echo "no .c or .h files specified"
sed -i -e '$a\' "$@"
echo "Done formatting file(s) $*"
exit exit
fi fi
echo "Formatting C files. This will take a bit" # format
echo "Running clang-format..." astyle ${FILES} \
clang-format ${FORMAT_OPTS} src/**/*.c --formatted --suffix=none \
echo "Running clang-tidy..." --lineend=linux \
clang-tidy ${TIDY_OPTS} src/**/*.c -- ${COMPILER_OPTS} &> /dev/null --convert-tabs \
echo "Adding missing final new lines..." --max-code-length=120 \
find src/ -type f -name "*.c" -exec sed -i -e '$a\' {} \; --min-conditional-indent=1 \
echo "Done formatting all files." --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

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