diff --git a/.clang-tidy b/.clang-tidy index 59d0facb9677..36cbac18c866 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -41,4 +41,3 @@ CheckOptions: - key: readability-braces-around-statements.ShortStatementLines value: '0' ... - diff --git a/.github/workflows/static_checks.yml b/.github/workflows/static_checks.yml index 12270a848a0c..28d7d93a5c1b 100644 --- a/.github/workflows/static_checks.yml +++ b/.github/workflows/static_checks.yml @@ -21,26 +21,15 @@ jobs: sudo apt-get install -qq dos2unix recode clang-format-11 sudo update-alternatives --remove-all clang-format sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-11 100 - sudo pip3 install black==20.8b1 pygments + sudo pip3 install black==20.8b1 pygments pre-commit + pre-commit install - - name: File formatting checks (file_format.sh) + - name: Run pre-commit hooks on all files run: | - bash ./misc/scripts/file_format.sh - - - name: Style checks via clang-format (clang_format.sh) - run: | - bash ./misc/scripts/clang_format.sh - - - name: Python style checks via black (black_format.sh) - run: | - bash ./misc/scripts/black_format.sh + pre-commit run --all-files - name: JavaScript style checks via ESLint run: | cd platform/javascript npm ci npm run lint - - - name: Documentation checks - run: | - doc/tools/makerst.py --dry-run doc/classes modules diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000000..9cdc1eee0de1 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,43 @@ +# Exclude files which shouldn't be modified by pre-commit hooks. +exclude: | + (?x)^( + .*\.sln| # Expected to contain a BOM + .*\.csproj| # Expected to contain a BOM + .*\.patch| # Expected to contrain 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: v3.4.0 + hooks: + - id: fix-byte-order-marker + - id: end-of-file-fixer + - id: trailing-whitespace + + - id: mixed-line-ending + args: [--fix=lf] + + - repo: https://github.com/pocc/pre-commit-hooks + rev: v1.1.1 + hooks: + - id: clang-format + + - repo: https://github.com/psf/black + rev: 20.8b1 + hooks: + - id: black + args: [-l 120] + + - repo: local + hooks: + - id: makerst + name: Check XML class reference syntax and validity + language: system + pass_filenames: false + entry: python doc/tools/makerst.py doc/classes modules --dry-run + files: ^(modules/.*/doc_classes/*.xml|doc/classes/.*.xml)$ 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/scripts/black_format.sh b/misc/scripts/black_format.sh deleted file mode 100755 index f93e8cbc2a76..000000000000 --- a/misc/scripts/black_format.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash - -# This script runs black on all Python files in the repo. - -set -uo pipefail - -# Apply black. -echo -e "Formatting Python files..." -PY_FILES=$(find \( -path "./.git" \ - -o -path "./thirdparty" \ - \) -prune \ - -o \( -name "SConstruct" \ - -o -name "SCsub" \ - -o -name "*.py" \ - \) -print) -black -l 120 $PY_FILES - -git diff > patch.patch - -# If no patch has been generated all is OK, clean up, and exit. -if [ ! -s patch.patch ] ; then - printf "Files in this commit comply with the black style 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/misc/scripts/clang_format.sh b/misc/scripts/clang_format.sh deleted file mode 100755 index 63c66d41c320..000000000000 --- a/misc/scripts/clang_format.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env bash - -# This script runs clang-format and fixes copyright headers on all relevant files in the repo. -# This is the primary script responsible for fixing style violations. - -set -uo pipefail -IFS=$'\n\t' - -CLANG_FORMAT_FILE_EXTS=(".c" ".h" ".cpp" ".hpp" ".cc" ".hh" ".cxx" ".m" ".mm" ".inc" ".java" ".glsl") - -# Loops through all text files tracked by Git. -git grep -zIl '' | -while IFS= read -rd '' f; do - # Exclude some files. - if [[ "$f" == "thirdparty"* ]]; then - continue - elif [[ "$f" == "platform/android/java/lib/src/com/google"* ]]; then - continue - elif [[ "$f" == *"-so_wrap."* ]]; then - continue - fi - - for extension in ${CLANG_FORMAT_FILE_EXTS[@]}; do - if [[ "$f" == *"$extension" ]]; then - # Run clang-format. - clang-format -i "$f" - # Fix copyright headers, but not all files get them. - if [[ "$f" == *"inc" ]]; then - continue 2 - elif [[ "$f" == *"glsl" ]]; then - continue 2 - elif [[ "$f" == *"theme_data.h" ]]; then - continue 2 - elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/input/InputManager"* ]]; then - continue 2 - fi - python misc/scripts/copyright_headers.py "$f" - continue 2 - fi - done -done - -git diff > patch.patch - -# If no patch has been generated all is OK, clean up, and exit. -if [ ! -s patch.patch ] ; then - printf "Files in this commit comply with the clang-format style 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/misc/scripts/file_format.sh b/misc/scripts/file_format.sh deleted file mode 100755 index 795431cd28b5..000000000000 --- a/misc/scripts/file_format.sh +++ /dev/null @@ -1,60 +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 recode. -if [ ! -x "$(command -v dos2unix)" -o ! -x "$(command -v recode)" ]; then - printf "Install 'dos2unix' and 'recode' to use this script.\n" -fi - -set -uo pipefail -IFS=$'\n\t' - -# Loops through all text files tracked by Git. -git grep -zIl '' | -while IFS= read -rd '' f; do - # Exclude some types of files. - if [[ "$f" == *"csproj" ]]; then - continue - elif [[ "$f" == *"sln" ]]; then - continue - elif [[ "$f" == *"patch" ]]; then - continue - elif [[ "$f" == *"pot" ]]; then - continue - elif [[ "$f" == *"po" ]]; then - continue - elif [[ "$f" == "thirdparty"* ]]; then - continue - elif [[ "$f" == "platform/android/java/lib/src/com/google"* ]]; then - continue - elif [[ "$f" == *"-so_wrap."* ]]; then - continue - fi - # Ensure that files are UTF-8 formatted. - recode UTF-8 "$f" 2> /dev/null - # 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 - -git diff > patch.patch - -# If no patch has been generated all is OK, clean up, and exit. -if [ ! -s patch.patch ] ; 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/modules/fbx/fbx_parser/LICENSE b/modules/fbx/fbx_parser/LICENSE index b42fc6efe6db..9e5ab664ef67 100644 --- a/modules/fbx/fbx_parser/LICENSE +++ b/modules/fbx/fbx_parser/LICENSE @@ -36,4 +36,3 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - diff --git a/modules/mono/editor/GodotTools/.gitignore b/modules/mono/editor/GodotTools/.gitignore index 48e2f914d8cf..a41d1c89b5fd 100644 --- a/modules/mono/editor/GodotTools/.gitignore +++ b/modules/mono/editor/GodotTools/.gitignore @@ -353,4 +353,3 @@ healthchecksdb # Backup folder for Package Reference Convert tool in Visual Studio 2017 MigrationBackup/ -