From f70686cdbec9fcd5aad9ba93ae86373fefadb9ca Mon Sep 17 00:00:00 2001 From: Thaddeus Crews Date: Thu, 14 Nov 2024 13:54:08 -0600 Subject: [PATCH] CI: Integrate `pre-commit` for style checks --- .github/workflows/ci.yml | 16 ++----- .pre-commit-config.yaml | 18 ++++++++ _tools/format.sh | 42 ------------------- classes/index.rst | 1 - contributing/how_to_contribute.rst | 1 - .../introduction/first_look_at_the_editor.rst | 1 - pyproject.toml | 8 ++++ .../assets_pipeline/escn_exporter/index.rst | 1 - tutorials/editor/external_editor.rst | 1 - .../navigation_using_navigationmeshes.rst | 1 - .../gdextension/gdextension_file.rst | 1 - tutorials/xr/xr_action_map.rst | 1 - 12 files changed, 30 insertions(+), 62 deletions(-) create mode 100644 .pre-commit-config.yaml delete mode 100755 _tools/format.sh create mode 100644 pyproject.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8126cac37..ff08ec8cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,19 +15,11 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Style checks via pre-commit + uses: pre-commit/action@v3.0.1 + - name: Install dependencies - run: | - # Install tools used by `_tools/format.sh`. - sudo apt-get -qq update - sudo apt-get -qq install dos2unix recode - sudo pip3 install -r requirements.txt - sudo pip3 install codespell - - - name: Linter checks - run: | - bash _tools/format.sh - - codespell -D- -D _tools/codespell-dict.txt -I _tools/codespell-ignore.txt -x _tools/codespell-ignore-lines.txt -S tutorials/i18n/locales.rst {about,community,contributing,getting_started,tutorials}/{*.rst,**/*.rst,**/**/*.rst,**/**/**/*.rst} + run: sudo pip3 install -r requirements.txt # Use dummy builder to improve performance as we don't need the generated HTML in this workflow. - name: Sphinx build diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..2d6e79cd0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,18 @@ +default_language_version: + python: python3 + +repos: + - repo: https://github.com/codespell-project/codespell + rev: v2.3.0 + hooks: + - id: codespell + files: ^(about|community|contributing|getting_started|tutorials)/.*\.rst$ + additional_dependencies: [tomli] + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: end-of-file-fixer + - id: fix-byte-order-marker + - id: mixed-line-ending + args: ['--fix=lf'] diff --git a/_tools/format.sh b/_tools/format.sh deleted file mode 100755 index 1b0e22f0b..000000000 --- a/_tools/format.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env bash - -set -uo pipefail -IFS=$'\n\t' - -# 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 diff --git a/classes/index.rst b/classes/index.rst index b2e89e028..0a571ab32 100644 --- a/classes/index.rst +++ b/classes/index.rst @@ -1085,4 +1085,3 @@ Variant types class_vector3i class_vector4 class_vector4i - diff --git a/contributing/how_to_contribute.rst b/contributing/how_to_contribute.rst index 477339567..00328b9a9 100644 --- a/contributing/how_to_contribute.rst +++ b/contributing/how_to_contribute.rst @@ -108,4 +108,3 @@ Community support Chances are you looked for learning materials outside of what the documentation provides. Without content creators covering the game development process, there would not be this big of a community today. Therefore it seemed only right to mention them in a page about important contributions to the project. - diff --git a/getting_started/introduction/first_look_at_the_editor.rst b/getting_started/introduction/first_look_at_the_editor.rst index c74b81311..da08400a7 100644 --- a/getting_started/introduction/first_look_at_the_editor.rst +++ b/getting_started/introduction/first_look_at_the_editor.rst @@ -181,4 +181,3 @@ Alternatively, or built-in variable in the script editor. * Right-clicking on nodes and choosing **Open Documentation** or choosing **Lookup Symbol** for elements in script editor will directly open their documentation. - diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..0797f2a07 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,8 @@ +[tool.ruff] +line-length = 120 + +[tool.codespell] +dictionary = ["_tools/codespell-dict.txt", "-"] +ignore-words = "_tools/codespell-ignore.txt" +exclude-file = "_tools/codespell-ignore-lines.txt" +skip = "tutorials/i18n/locales.rst" diff --git a/tutorials/assets_pipeline/escn_exporter/index.rst b/tutorials/assets_pipeline/escn_exporter/index.rst index f607745ba..b9f8a0af7 100644 --- a/tutorials/assets_pipeline/escn_exporter/index.rst +++ b/tutorials/assets_pipeline/escn_exporter/index.rst @@ -11,4 +11,3 @@ is not maintained or supported in Godot 4.x. While not officially supported, the partially work for some Godot and Blender versions, particularly before Blender version 4.0. For complete docs on the Blender exporter, see the `previous version of this page `__. - diff --git a/tutorials/editor/external_editor.rst b/tutorials/editor/external_editor.rst index f9ed4300e..aa2cc4b48 100644 --- a/tutorials/editor/external_editor.rst +++ b/tutorials/editor/external_editor.rst @@ -119,4 +119,3 @@ Emacs ^^^^^ Check the official instructions to configure `LSP `_, and `DAP `_. - diff --git a/tutorials/navigation/navigation_using_navigationmeshes.rst b/tutorials/navigation/navigation_using_navigationmeshes.rst index 7a98cba9f..8964e80e8 100644 --- a/tutorials/navigation/navigation_using_navigationmeshes.rst +++ b/tutorials/navigation/navigation_using_navigationmeshes.rst @@ -694,4 +694,3 @@ The following script uses the NavigationServer to update a navigation region wit NavigationServer3D.RegionSetNavigationMesh(_regionRid, _navigationMesh); } } - diff --git a/tutorials/scripting/gdextension/gdextension_file.rst b/tutorials/scripting/gdextension/gdextension_file.rst index 68e05611b..0ccacfc29 100644 --- a/tutorials/scripting/gdextension/gdextension_file.rst +++ b/tutorials/scripting/gdextension/gdextension_file.rst @@ -182,4 +182,3 @@ If no path is supplied Godot will move the libraries into the same directory as "res://bin/libdependency.linux.template_release.arm64.so" : "", "res://bin/libdependency.linux.template_release.rv64.so" : "" } - diff --git a/tutorials/xr/xr_action_map.rst b/tutorials/xr/xr_action_map.rst index 47e7a6a4e..082046de2 100644 --- a/tutorials/xr/xr_action_map.rst +++ b/tutorials/xr/xr_action_map.rst @@ -385,4 +385,3 @@ This is why many XR runtimes only use it as a last resort and will attempt to us This is our advice as well: limit your action map to the interaction profiles for devices you have actually tested your game with. The Oculus Touch controller is widely used as a fallback controller by many runtimes. If you are able to test your game using a Meta Rift or Quest and add this profile there is a high probability your game will work with other headsets. -