From 917ed35cbfc615e7080c07b1b681e8bc4fad9b57 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Tue, 12 May 2020 13:35:25 -0400 Subject: [PATCH 1/2] Add a formatting script for Travis CI --- .travis.yml | 18 ++++++++++++++++++ format.sh | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 .travis.yml create mode 100755 format.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..7106fe5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +dist: bionic + +stages: + - build + +matrix: + include: + - name: Static checks (format.sh) + stage: build + os: linux + addons: + apt: + packages: + - dos2unix + - recode + +script: + - bash ./format.sh diff --git a/format.sh b/format.sh new file mode 100755 index 0000000..f96caef --- /dev/null +++ b/format.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# Loops through all text files tracked by Git. +git grep -zIl '' | +while IFS= read -rd '' f; do + # Exclude csproj and hdr files. + if [[ $f == *"csproj" ]]; then + continue + elif [[ $f == *"hdr" ]]; then + continue + fi + # Ensures that files are UTF-8 formatted. + recode UTF-8 $f 2> /dev/null + # Ensures that files have LF line endings. + dos2unix $f 2> /dev/null + # Ensures that files do not contain a BOM. + sed -i '1s/^\xEF\xBB\xBF//' "$f" + # Ensures that files end with newline characters. + tail -c1 < "$f" | read -r _ || echo >> "$f"; +done + +git diff > patch.patch +FILESIZE=$(stat -c%s patch.patch) +MAXSIZE=5 + +# If no patch has been generated all is OK, clean up, and exit. +if (( FILESIZE < MAXSIZE )); then + printf "Files in this commit comply with the formatting rules.\n" + rm -f patch.patch + exit 0 +fi + +# A patch has been created, notify the user, clean up, and exit. +printf "\n*** The following differences were found between the code " +printf "and the formatting rules:\n\n" +cat patch.patch +printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i '\n" +rm -f patch.patch +exit 1 From 5eddfaaf23e2ec83da5ec2592ba22dd98a02c94d Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Tue, 12 May 2020 13:37:30 -0400 Subject: [PATCH 2/2] Commit files changed by the formatting script --- Button.gd | 2 +- Gift.gd | 2 +- addons/gift/util/cmd_data.gd | 1 - addons/gift/util/cmd_info.gd | 1 - addons/gift/util/sender_data.gd | 2 +- 5 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Button.gd b/Button.gd index b2aba84..a821142 100644 --- a/Button.gd +++ b/Button.gd @@ -2,4 +2,4 @@ extends Button func _pressed(): $"../Gift".chat($"../LineEdit".text) - $"../LineEdit".text = "" \ No newline at end of file + $"../LineEdit".text = "" diff --git a/Gift.gd b/Gift.gd index 3592dc8..3c882c8 100644 --- a/Gift.gd +++ b/Gift.gd @@ -83,4 +83,4 @@ func greet_me(cmd_info : CommandInfo) -> void: chat("Greetings, " + cmd_info.sender_data.tags["display-name"] + "!") func list(cmd_info : CommandInfo, arg_ary : PoolStringArray) -> void: - chat(arg_ary.join(", ")) \ No newline at end of file + chat(arg_ary.join(", ")) diff --git a/addons/gift/util/cmd_data.gd b/addons/gift/util/cmd_data.gd index 3fc9c20..e630595 100644 --- a/addons/gift/util/cmd_data.gd +++ b/addons/gift/util/cmd_data.gd @@ -13,4 +13,3 @@ func _init(f_ref : FuncRef, perm_lvl : int, mx_args : int, mn_args : int, whr : max_args = mx_args min_args = mn_args where = whr - \ No newline at end of file diff --git a/addons/gift/util/cmd_info.gd b/addons/gift/util/cmd_info.gd index 3134fd6..c74e650 100644 --- a/addons/gift/util/cmd_info.gd +++ b/addons/gift/util/cmd_info.gd @@ -9,4 +9,3 @@ func _init(sndr_dt, cmd, whspr): sender_data = sndr_dt command = cmd whisper = whspr - \ No newline at end of file diff --git a/addons/gift/util/sender_data.gd b/addons/gift/util/sender_data.gd index 8b98508..5f78185 100644 --- a/addons/gift/util/sender_data.gd +++ b/addons/gift/util/sender_data.gd @@ -8,4 +8,4 @@ var tags : Dictionary func _init(usr : String, ch : String, tag_dict : Dictionary): user = usr channel = ch - tags = tag_dict \ No newline at end of file + tags = tag_dict