From 6096d0d10dffcb4575c46de6ab5cf5ce32601d1b Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Sat, 4 May 2024 13:50:04 -0400 Subject: [PATCH] add style --- .github/workflows/style.yml | 22 +++++++++++ .github/workflows/style/check_tabs.sh | 36 ++++++++++++++++++ .../style/check_trailing_whitespaces.sh | 38 +++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 .github/workflows/style.yml create mode 100755 .github/workflows/style/check_tabs.sh create mode 100755 .github/workflows/style/check_trailing_whitespaces.sh diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml new file mode 100644 index 0000000..5b5af5e --- /dev/null +++ b/.github/workflows/style.yml @@ -0,0 +1,22 @@ +name: Style + +on: [push, pull_request] + +concurrency: + group: ${{ github.ref }}-${{ github.head_ref }}-style + cancel-in-progress: true + +jobs: + tabs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Tabs + run: .github/workflows/style/check_tabs.sh + + trailing_whitespaces: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Trailing Whitespaces + run: .github/workflows/style/check_trailing_whitespaces.sh diff --git a/.github/workflows/style/check_tabs.sh b/.github/workflows/style/check_tabs.sh new file mode 100755 index 0000000..f441864 --- /dev/null +++ b/.github/workflows/style/check_tabs.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -eu -o pipefail + +find . -type d \( -name .git \ + -o -path ./paper \ + -o -name build -o -name install \ + -o -name tmp_build_dir -o -name tmp_install_dir \ + \) -prune -o \ + -type f \( \( -name "*.H" -o -name "*.h" -o -name "*.hh" -o -name "*.hpp" \ + -o -name "*.c" -o -name "*.cc" -o -name "*.cpp" -o -name "*.cxx" \ + -o -name "*.f" -o -name "*.F" -o -name "*.f90" -o -name "*.F90" \ + -o -name "*.py" \ + -o -name "*.md" -o -name "*.rst" \ + -o -name "*.sh" \ + -o -name "*.tex" \ + -o -name "*.txt" \ + -o -name "*.yml" \) \ + -a \( ! -name "*.tab.h" -a ! -name "*.tab.nolint.H" \ + -a ! -name "*.lex.h" -a ! -name "*.lex.nolint.H" \) \ + \) \ + -exec grep -Iq . {} \; \ + -exec sed -i 's/\t/\ \ \ \ /g' {} + + +gitdiff=`git diff` + +if [ -z "$gitdiff" ] +then + exit 0 +else + echo -e "\nTabs are not allowed. Changes suggested by" + echo -e " ${0}\n" + git --no-pager diff + echo "" + exit 1 +fi diff --git a/.github/workflows/style/check_trailing_whitespaces.sh b/.github/workflows/style/check_trailing_whitespaces.sh new file mode 100755 index 0000000..b33b62c --- /dev/null +++ b/.github/workflows/style/check_trailing_whitespaces.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +set -eu -o pipefail + +find . -type d \( -name .git \ + -o -path ./paper \ + -o -name build -o -name install \ + -o -name tmp_build_dir -o -name tmp_install_dir \ + -o -path ./util/gcem \ + \) -prune -o \ + -type f \( \( -name "*.H" -o -name "*.h" -o -name "*.hh" -o -name "*.hpp" \ + -o -name "*.c" -o -name "*.cc" -o -name "*.cpp" -o -name "*.cxx" \ + -o -name "*.f" -o -name "*.F" -o -name "*.f90" -o -name "*.F90" \ + -o -name "*.py" \ + -o -name "*.rst" \ + -o -name "*.sh" \ + -o -name "*.tex" \ + -o -name "*.txt" \ + -o -name "*.yml" \) \ + -a \( ! -name "*.tab.h" -a ! -name "*.tab.nolint.H" \ + -a ! -name "*.lex.h" -a ! -name "*.lex.nolint.H" \ + -a ! -path "./networks/*/reaclib_rates.H" \) \ + \) \ + -exec grep -Iq . {} \; \ + -exec sed -i 's/[[:blank:]]\+$//g' {} + + +gitdiff=`git diff` + +if [ -z "$gitdiff" ] +then + exit 0 +else + echo -e "\nTrailing whitespaces at the end of a line are not allowed. Changes suggested by" + echo -e " ${0}\n" + git --no-pager diff + echo "" + exit 1 +fi