Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve formatting stuff #872

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions .github/file_format.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#!/usr/bin/env bash

# This script ensures proper POSIX text file formatting and a few other things.

set -uo pipefail
IFS=$'\n\t'

# Function to process a single file.
process_file() {
local f="$1"
# Loops through all text files tracked by Git.
git grep -zIl '' |
while IFS= read -rd '' f; do
# Exclude some types of files.
if [[ "$f" == *"svg" ]]; then
return
continue
fi
# Ensure that files are UTF-8 formatted.
recode UTF-8 "$f" 2> /dev/null
Expand All @@ -20,31 +22,28 @@ process_file() {
# Remove the character sequence "== true" if it has a leading space.
perl -i -pe 's/\x20== true//g' "$f"
# We don't want to change lines around braces in godot/tscn files.
if [[ "$f" == *"godot" ]] || [[ "$f" == *"tscn" ]]; then
return
if [[ "$f" == *"godot" ]]; then
continue
elif [[ "$f" == *"tscn" ]]; then
continue
fi
# Disallow empty lines after the opening brace.
sed -z -i 's/\x7B\x0A\x0A/\x7B\x0A/g' "$f"
# Disallow some empty lines before the closing brace.
sed -z -i 's/\x0A\x0A\x7D/\x0A\x7D/g' "$f"
}

# Process all files passed as arguments.
for file in "$@"; do
if [ -f "$file" ]; then
process_file "$file"
fi
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"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/export-optimized.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ on:
workflow_dispatch:

env:
GODOT_VERSION: 4.2.2
GODOT_VERSION: 4.3
PROJECT_NAME: GodSVG
GODOT_REPO: https://github.com/godotengine/godot.git
GODOT_COMMIT_HASH: 15073af
GODOT_COMMIT_HASH: 77dcf97
BUILD_OPTIONS: target=template_release lto=full production=yes deprecated=no minizip=no brotli=no vulkan=no openxr=no use_volk=no disable_3d=yes modules_enabled_by_default=no module_freetype_enabled=yes module_gdscript_enabled=yes module_svg_enabled=yes module_jpg_enabled=yes module_text_server_adv_enabled=yes graphite=no module_webp_enabled=yes

jobs:
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/static-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Static Checks
on: [pull_request]

jobs:
format:
name: File formatting (file_format.sh)
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install dependencies
run: sudo apt-get update -qq && sudo apt-get install -yq --no-install-recommends dos2unix recode

- name: File formatting checks (file_format.sh)
run: bash ./.github/file_format.sh
29 changes: 0 additions & 29 deletions .github/workflows/static_checks.yml

This file was deleted.

2 changes: 1 addition & 1 deletion src/config_classes/Formatter.gd
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func _init(new_title := "") -> void:
title = new_title
# Connects to the _on_changed function once all initial file loading is done.
# This way the config is saved only once on launch.
changed.connect(changed.connect.bind(_on_changed), CONNECT_DEFERRED | CONNECT_ONE_SHOT)
changed.connect(func(): changed.connect(_on_changed), CONNECT_DEFERRED | CONNECT_ONE_SHOT)

func _on_changed() -> void:
if self == GlobalSettings.savedata.editor_formatter:
Expand Down