Skip to content

Commit

Permalink
add pre-commit hook script for cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
kuruk-mm committed Nov 22, 2023
1 parent 9a74a12 commit a96bef9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 25 deletions.
67 changes: 46 additions & 21 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CONTRIBUTING

## Format
## Format GDScript

When GD files are modified, they must be well-formated.
It requires [godot-gdscript-toolkit](https://github.com/kuruk-mm/godot-gdscript-toolkit) installed
Expand All @@ -21,6 +21,15 @@ You can run the linter with:
gdlint godot/
```

## Format Rust

Format rust
```bash
cd rust/decentraland-godot-lib
cargo fmt --all
cargo clippy -- -D warnings
```

## Git Hooks

You can add the following hooks at `.git/hooks/pre-commit`
Expand All @@ -35,40 +44,56 @@ Script:
```bash
#!/bin/bash

## FORMAT GDSCRIPT

# Get modified .gd files
MODIFIED_GD_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.gd$')

# Check if there are .gd files to lint
if [ -z "$MODIFIED_GD_FILES" ]; then
exit 0
fi
if [ ! -z "$MODIFIED_GD_FILES" ]; then

# Run gdlint on modified files
echo "Running gdlint on modified files..."
gdlint $MODIFIED_GD_FILES
# Run gdlint on modified files
echo "Running gdlint on modified files..."
gdlint $MODIFIED_GD_FILES

# Save the exit status of gdlint
GDLINT_EXIT=$?
# Save the exit status of gdlint
GDLINT_EXIT=$?

# If gdlint finds issues, cancel the commit
if [ $GDLINT_EXIT -ne 0 ]; then
echo "gdlint found issues, please fix them before committing."
exit 1
# If gdlint finds issues, cancel the commit
if [ $GDLINT_EXIT -ne 0 ]; then
echo "gdlint found issues, please fix them before committing."
exit 1
fi

# Run gdformat on modified files
echo "Running gdformat on modified files..."
gdformat -d $MODIFIED_GD_FILES

# Save the exit status of gdlint
GDFORMAT_EXIT=$?

# If gdlint finds issues, cancel the commit
if [ $GDFORMAT_EXIT -ne 0 ]; then
echo "gdformat found issues, please fix them before committing."
exit 1
fi
fi

# Run gdformat on modified files
echo "Running gdformat on modified files..."
gdformat -d $MODIFIED_GD_FILES
## FORMAT RUST

# Save the exit status of gdlint
GDFORMAT_EXIT=$?
# Change to the specific Rust directory
cd rust/decentraland-godot-lib

# If gdlint finds issues, cancel the commit
if [ $GDFORMAT_EXIT -ne 0 ]; then
echo "gdformat found issues, please fix them before committing."
# Check if cargo fmt would make changes
if ! cargo fmt -- --check
then
echo "Code formatting in 'rust/decentraland-godot-lib' differs from cargo fmt's style"
echo "Run 'cargo fmt --all' inside 'rust/decentraland-godot-lib' to format the code."
exit 1
fi

echo "Code formatted"

# If everything is okay, proceed with the commit
exit 0
```
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ pub fn update_video_player(
});

if !file_hash.is_empty() {
video_player_node
.call_deferred("async_request_video".into(), &[file_hash.to_variant()]);
video_player_node.call_deferred(
"async_request_video".into(),
&[file_hash.to_variant()],
);
}
}
VideoUpdateMode::FirstSpawnVideo => {
Expand Down Expand Up @@ -255,8 +257,10 @@ pub fn update_video_player(
.insert(*entity, video_player_node.clone());

if !file_hash.is_empty() {
video_player_node
.call_deferred("async_request_video".into(), &[file_hash.to_variant()]);
video_player_node.call_deferred(
"async_request_video".into(),
&[file_hash.to_variant()],
);
}
}
}
Expand Down

0 comments on commit a96bef9

Please sign in to comment.