From c808a69ab24c84e20fc592e679fc814d4b1b0048 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Wed, 6 Mar 2024 19:12:52 +0100 Subject: [PATCH] Add pre-commit hooks to replace the `file_format.sh` script The new pre-commit hooks catch common file formatting issues, along with new checks such as JSON and YAML validity. There is also a check that prevents adding submodules by accident, as the main Godot repository doesn't use submodules. --- .clang-tidy | 1 - .github/actions/godot-api-dump/action.yml | 1 - .github/workflows/static_checks.yml | 4 - .pre-commit-config.yaml | 37 ++++++-- doc/classes/GDExtensionManager.xml | 2 +- doc/classes/Node.xml | 2 +- doc/classes/Time.xml | 2 +- editor/icons/FolderCreate.svg | 2 +- editor/icons/Parallax2D.svg | 2 +- editor/icons/TileMapLayer.svg | 2 +- gles3_builders.py | 2 +- .../godot_ios/en.lproj/InfoPlist.strings | 1 - misc/error_suppressions/tsan.txt | 1 - misc/msvs/props.template | 2 +- misc/msvs/vcxproj.filters.template | 2 +- misc/msvs/vcxproj.template | 2 +- misc/scripts/file_format.sh | 89 ------------------- modules/enet/doc_classes/ENetConnection.xml | 2 +- modules/gdscript/README.md | 2 +- .../Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props | 2 +- .../Godot.NET.Sdk/Sdk/iOSNativeAOT.targets | 10 +-- .../ClassPartialModifier.GD0001.fixed.cs | 2 +- .../Sources/ClassPartialModifier.GD0001.cs | 2 +- .../TestData/Sources/GlobalClass.GD0401.cs | 2 +- .../TestData/Sources/GlobalClass.GD0402.cs | 2 +- .../TestData/Sources/MustBeVariant.GD0301.cs | 4 +- .../godotengine/editor/GodotProjectManager.kt | 1 - .../godotengine/godot/gl/GLSurfaceView.java | 1 - .../android/java/scripts/publish-root.gradle | 1 - platform/windows/godot.natvis | 8 +- scene/theme/icons/folder_create.svg | 2 +- .../renderer_rd/shaders/samplers_inc.glsl | 2 +- .../gles3/vertex_fragment_expected_full.glsl | 1 - 33 files changed, 60 insertions(+), 138 deletions(-) delete mode 100755 misc/scripts/file_format.sh diff --git a/.clang-tidy b/.clang-tidy index 659b91013d47..890ffb5d9901 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -44,4 +44,3 @@ CheckOptions: - key: readability-braces-around-statements.ShortStatementLines value: '0' ... - diff --git a/.github/actions/godot-api-dump/action.yml b/.github/actions/godot-api-dump/action.yml index 47b675ae99fc..773068866170 100644 --- a/.github/actions/godot-api-dump/action.yml +++ b/.github/actions/godot-api-dump/action.yml @@ -21,4 +21,3 @@ runs: with: name: 'godot-api-dump' path: './godot-api/*' - diff --git a/.github/workflows/static_checks.yml b/.github/workflows/static_checks.yml index 0d5c1906b50d..5545da91ca76 100644 --- a/.github/workflows/static_checks.yml +++ b/.github/workflows/static_checks.yml @@ -49,10 +49,6 @@ jobs: - name: Style checks via pre-commit uses: pre-commit/action@v3.0.1 - - name: File formatting checks (file_format.sh) - run: | - bash ./misc/scripts/file_format.sh changed.txt - - name: Header guards formatting checks (header_guards.sh) run: | bash ./misc/scripts/header_guards.sh changed.txt diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9e9da655cc9d..4ad045d6cdf5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,34 @@ +# Globally exclude files which shouldn't be modified by any pre-commit hooks. +exclude: | + (?x)^( + .*\.patch| # Expected to contain trailing whitespace + modules/gdscript/tests/scripts/.*| # Expected to contain trailing whitespace + .*\.pot| + .*\.po| + thirdparty/.*| # Third-party files + platform/android/java/lib/src/com/google.*| # Third-party files + .*-so_wrap\..* # Generated code + ) + repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-json + + - id: check-yaml + exclude: .clang-format + + - id: check-executables-have-shebangs + - id: check-symlinks + - id: end-of-file-fixer + - id: fix-byte-order-marker + - id: forbid-submodules + - id: mixed-line-ending + + - id: trailing-whitespace + exclude: tests/data/line_endings_cr.test.txt + - repo: https://github.com/pre-commit/mirrors-clang-format rev: v17.0.6 hooks: @@ -8,9 +38,6 @@ repos: exclude: | (?x)^( tests/python_build.*| - .*thirdparty.*| - .*platform/android/java/lib/src/com.*| - .*-so_wrap.* ) - repo: https://github.com/psf/black-pre-commit-mirror @@ -19,7 +46,6 @@ repos: - id: black files: (\.py$|SConstruct|SCsub) types_or: [text] - exclude: .*thirdparty.* args: - --line-length=120 @@ -40,9 +66,6 @@ repos: exclude: | (?x)^( tests/python_build.*| - .*thirdparty.*| - .*platform/android/java/lib/src/com.*| - .*-so_wrap.*| platform/android/java/lib/src/org/godotengine/godot/gl/GLSurfaceView.*| platform/android/java/lib/src/org/godotengine/godot/gl/EGLLogWrapper.*| platform/android/java/lib/src/org/godotengine/godot/utils/ProcessPhoenix.* diff --git a/doc/classes/GDExtensionManager.xml b/doc/classes/GDExtensionManager.xml index 1ecb23a03bfe..211bc023c0e3 100644 --- a/doc/classes/GDExtensionManager.xml +++ b/doc/classes/GDExtensionManager.xml @@ -43,7 +43,7 @@ - Reloads the extension at the given file path. The [param path] needs to point to a valid [GDExtension], otherwise this method may return either [constant LOAD_STATUS_NOT_LOADED] or [constant LOAD_STATUS_FAILED]. + Reloads the extension at the given file path. The [param path] needs to point to a valid [GDExtension], otherwise this method may return either [constant LOAD_STATUS_NOT_LOADED] or [constant LOAD_STATUS_FAILED]. [b]Note:[/b] You can only reload extensions in the editor. In release builds, this method always fails and returns [constant LOAD_STATUS_FAILED]. diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml index b786b679331d..9370f16ccf68 100644 --- a/doc/classes/Node.xml +++ b/doc/classes/Node.xml @@ -961,7 +961,7 @@ [b]Note:[/b] When changing the name, the following characters will be replaced with an underscore: ([code].[/code] [code]:[/code] [code]@[/code] [code]/[/code] [code]"[/code] [code]%[/code]). In particular, the [code]@[/code] character is reserved for auto-generated names. See also [method String.validate_node_name]. - The owner of this node. The owner must be an ancestor of this node. When packing the owner node in a [PackedScene], all the nodes it owns are also saved with it. + The owner of this node. The owner must be an ancestor of this node. When packing the owner node in a [PackedScene], all the nodes it owns are also saved with it. [b]Note:[/b] In the editor, nodes not owned by the scene root are usually not displayed in the Scene dock, and will [b]not[/b] be saved. To prevent this, remember to set the owner after calling [method add_child]. See also (see [member unique_name_in_owner]) diff --git a/doc/classes/Time.xml b/doc/classes/Time.xml index 79c332327f56..5214b2509041 100644 --- a/doc/classes/Time.xml +++ b/doc/classes/Time.xml @@ -152,7 +152,7 @@ - Returns the current time zone as a dictionary of keys: [code]bias[/code] and [code]name[/code]. + Returns the current time zone as a dictionary of keys: [code]bias[/code] and [code]name[/code]. - [code]bias[/code] is the offset from UTC in minutes, since not all time zones are multiples of an hour from UTC. - [code]name[/code] is the localized name of the time zone, according to the OS locale settings of the current user. diff --git a/editor/icons/FolderCreate.svg b/editor/icons/FolderCreate.svg index 80a3f90e2aa0..ff224d011147 100644 --- a/editor/icons/FolderCreate.svg +++ b/editor/icons/FolderCreate.svg @@ -1 +1 @@ - \ No newline at end of file + diff --git a/editor/icons/Parallax2D.svg b/editor/icons/Parallax2D.svg index 8d41102a862c..eb7f1fcbbc92 100644 --- a/editor/icons/Parallax2D.svg +++ b/editor/icons/Parallax2D.svg @@ -1 +1 @@ - \ No newline at end of file + diff --git a/editor/icons/TileMapLayer.svg b/editor/icons/TileMapLayer.svg index 1903a87e3b3d..d9f949ebe32c 100644 --- a/editor/icons/TileMapLayer.svg +++ b/editor/icons/TileMapLayer.svg @@ -1 +1 @@ - \ No newline at end of file + diff --git a/gles3_builders.py b/gles3_builders.py index f1cdf7ac8c29..1b3bd14d3dad 100644 --- a/gles3_builders.py +++ b/gles3_builders.py @@ -596,7 +596,7 @@ def build_gles3_header( fd.write("\t}\n\n") fd.write("};\n\n") - fd.write("#endif\n\n") + fd.write("#endif\n") fd.close() diff --git a/misc/dist/ios_xcode/godot_ios/en.lproj/InfoPlist.strings b/misc/dist/ios_xcode/godot_ios/en.lproj/InfoPlist.strings index 477b28ff8f86..b92732c79e00 100644 --- a/misc/dist/ios_xcode/godot_ios/en.lproj/InfoPlist.strings +++ b/misc/dist/ios_xcode/godot_ios/en.lproj/InfoPlist.strings @@ -1,2 +1 @@ /* Localized versions of Info.plist keys */ - diff --git a/misc/error_suppressions/tsan.txt b/misc/error_suppressions/tsan.txt index 7c3d836f6c8f..ac46371f8b8a 100644 --- a/misc/error_suppressions/tsan.txt +++ b/misc/error_suppressions/tsan.txt @@ -5,4 +5,3 @@ deadlock:tests/core/templates/test_command_queue.h deadlock:modules/text_server_adv/text_server_adv.cpp deadlock:modules/text_server_fb/text_server_fb.cpp race:modules/navigation/nav_map.cpp - diff --git a/misc/msvs/props.template b/misc/msvs/props.template index 8facaf7f36e2..9169dfb73745 100644 --- a/misc/msvs/props.template +++ b/misc/msvs/props.template @@ -18,4 +18,4 @@ %%EXTRA_ITEMS%% - \ No newline at end of file + diff --git a/misc/msvs/vcxproj.filters.template b/misc/msvs/vcxproj.filters.template index d57eeee811cf..11d331d15da2 100644 --- a/misc/msvs/vcxproj.filters.template +++ b/misc/msvs/vcxproj.filters.template @@ -27,4 +27,4 @@ \ No newline at end of file +--> diff --git a/misc/msvs/vcxproj.template b/misc/msvs/vcxproj.template index 30f29a55f876..92a55e15594e 100644 --- a/misc/msvs/vcxproj.template +++ b/misc/msvs/vcxproj.template @@ -37,4 +37,4 @@ - \ No newline at end of file + diff --git a/misc/scripts/file_format.sh b/misc/scripts/file_format.sh deleted file mode 100755 index ad586578836e..000000000000 --- a/misc/scripts/file_format.sh +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env bash - -# This script ensures proper POSIX text file formatting and a few other things. -# This is supplementary to clang_format.sh and black_format.sh, but should be -# run before them. - -# We need dos2unix and isutf8. -if [ ! -x "$(command -v dos2unix)" -o ! -x "$(command -v isutf8)" ]; then - printf "Install 'dos2unix' and 'isutf8' (moreutils package) to use this script.\n" - exit 1 -fi - -set -uo pipefail - -if [ $# -eq 0 ]; then - # Loop through all code files tracked by Git. - mapfile -d '' files < <(git grep -zIl '') -else - # $1 should be a file listing file paths to process. Used in CI. - mapfile -d ' ' < <(cat "$1") -fi - -for f in "${files[@]}"; do - # Exclude some types of files. - if [[ "$f" == *"csproj" ]]; then - continue - elif [[ "$f" == *"sln" ]]; then - continue - elif [[ "$f" == *".bat" ]]; then - continue - elif [[ "$f" == *".out" ]]; then - # GDScript integration testing files. - continue - elif [[ "$f" == *"patch" ]]; then - continue - elif [[ "$f" == *"pot" ]]; then - continue - elif [[ "$f" == *"po" ]]; then - continue - elif [[ "$f" == "thirdparty/"* ]]; then - continue - elif [[ "$f" == *"/thirdparty/"* ]]; then - continue - elif [[ "$f" == "platform/android/java/lib/src/com/google"* ]]; then - continue - elif [[ "$f" == *"-so_wrap."* ]]; then - continue - elif [[ "$f" == *".test.txt" ]]; then - continue - fi - # Ensure that files are UTF-8 formatted. - isutf8 "$f" >> utf8-validation.txt 2>&1 - # Ensure that files have LF line endings and do not contain a BOM. - dos2unix "$f" 2> /dev/null - # Remove trailing space characters and ensures that files end - # with newline characters. -l option handles newlines conveniently. - perl -i -ple 's/\s*$//g' "$f" -done - -diff=$(git diff --color) - -if [ ! -s utf8-validation.txt ] && [ -z "$diff" ] ; then - # If no UTF-8 violations were collected (the file is empty) and - # no diff has been generated all is OK, clean up, and exit. - printf "\e[1;32m*** Files in this commit comply with the file formatting rules.\e[0m\n" - rm -f utf8-validation.txt - exit 0 -fi - -if [ -s utf8-validation.txt ] -then - # If the file has content and is not empty, violations - # detected, notify the user, clean up, and exit. - printf "\n\e[1;33m*** The following files contain invalid UTF-8 character sequences:\e[0m\n\n" - cat utf8-validation.txt -fi - -rm -f utf8-validation.txt - -if [ ! -z "$diff" ] -then - # A diff has been created, notify the user, clean up, and exit. - printf "\n\e[1;33m*** The following changes must be made to comply with the formatting rules:\e[0m\n\n" - # Perl commands replace trailing spaces with `·` and tabs with ``. - printf "%s\n" "$diff" | perl -pe 's/(.*[^ ])( +)(\e\[m)$/my $spaces="·" x length($2); sprintf("$1$spaces$3")/ge' | perl -pe 's/(.*[^\t])(\t+)(\e\[m)$/my $tabs="" x length($2); sprintf("$1$tabs$3")/ge' -fi - -printf "\n\e[1;91m*** Please fix your commit(s) with 'git commit --amend' or 'git rebase -i '\e[0m\n" -exit 1 diff --git a/modules/enet/doc_classes/ENetConnection.xml b/modules/enet/doc_classes/ENetConnection.xml index 5ca1ec222818..5795dd8976c3 100644 --- a/modules/enet/doc_classes/ENetConnection.xml +++ b/modules/enet/doc_classes/ENetConnection.xml @@ -151,7 +151,7 @@ - Sends a [param packet] toward a destination from the address and port currently bound by this ENetConnection instance. + Sends a [param packet] toward a destination from the address and port currently bound by this ENetConnection instance. This is useful as it serves to establish entries in NAT routing tables on all devices between this bound instance and the public facing internet, allowing a prospective client's connection packets to be routed backward through the NAT device(s) between the public internet and this host. This requires forward knowledge of a prospective client's address and communication port as seen by the public internet - after any NAT devices have handled their connection request. This information can be obtained by a [url=https://en.wikipedia.org/wiki/STUN]STUN[/url] service, and must be handed off to your host by an entity that is not the prospective client. This will never work for a client behind a Symmetric NAT due to the nature of the Symmetric NAT routing algorithm, as their IP and Port cannot be known beforehand. diff --git a/modules/gdscript/README.md b/modules/gdscript/README.md index 865475d37dce..a4367b39ff04 100644 --- a/modules/gdscript/README.md +++ b/modules/gdscript/README.md @@ -136,4 +136,4 @@ There are many other classes in the GDScript module. Here is a brief overview of - The [virtual machine](gdscript_vm.cpp) is essentially defined as calling `GDScriptFunction::call()`. - Editor-related functions can be found in parts of `GDScriptLanguage`, originally declared in [`gdscript.h`](gdscript.h) but defined in [`gdscript_editor.cpp`](gdscript_editor.cpp). Code highlighting can be found in [`GDScriptSyntaxHighlighter`](editor/gdscript_highlighter.h). - GDScript decompilation is found in [`gdscript_disassembler.cpp`](gdscript_disassembler.h), defined as `GDScriptFunction::disassemble()`. -- Documentation generation from GDScript comments in [`GDScriptDocGen`](editor/gdscript_docgen.h) \ No newline at end of file +- Documentation generation from GDScript comments in [`GDScriptDocGen`](editor/gdscript_docgen.h) diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props index b6c72bce9dfb..24946f76f117 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props @@ -69,7 +69,7 @@ macos windows - + linuxbsd diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/iOSNativeAOT.targets b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/iOSNativeAOT.targets index b51ce5cb8c51..0391e9f8298b 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/iOSNativeAOT.targets +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/iOSNativeAOT.targets @@ -11,10 +11,10 @@ /Applications/Xcode.app/Contents/Developer $([MSBuild]::EnsureTrailingSlash('$(XCodePath)')) - + - +