From f29aa383e0e209f4b24fe057c4ef4ff3c12d3aa3 Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Wed, 27 Oct 2021 17:21:17 -0400 Subject: [PATCH] Format script and options --- .clang-format | 23 +++++++++++++++++++++++ .clang-tidy | 5 +++++ format.sh | 28 ++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 .clang-format create mode 100644 .clang-tidy create mode 100755 format.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..5423bdcc --- /dev/null +++ b/.clang-format @@ -0,0 +1,23 @@ +IndentWidth: 4 +Language: Cpp +UseTab: Never +ColumnLimit: 132 +PointerAlignment: Right +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 \ No newline at end of file diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000..db861ad8 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,5 @@ +Checks: '-*,readability-braces-around-statements' +WarningsAsErrors: '' +HeaderFilterRegex: '(src|include)\/.*\.h$' +FormatStyle: 'file' +CheckOptions: \ No newline at end of file diff --git a/format.sh b/format.sh new file mode 100755 index 00000000..4d410481 --- /dev/null +++ b/format.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +FORMAT_OPTS="-i -style=file" +TIDY_OPTS="-p . --fix --fix-errors" +COMPILER_OPTS="-fno-builtin -std=gnu90 -Iinclude -Isrc -D_LANGUAGE_C -DNON_MATCHING" + +shopt -s globstar + +if (( $# > 0 )); then + echo "Formatting file(s) $*" + echo "Running clang-format..." + clang-format-11 ${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) $*" + 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." \ No newline at end of file