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

refactor: add gdscript linter and async-function-name linter #102

Merged
merged 7 commits into from
Nov 23, 2023
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
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.71
toolchain: 1.72
override: true
components: clippy, rustfmt
- run: rustup component add rustfmt
- name: Set up Python
uses: actions/setup-python@v4
- name: Install gdtoolkit 4
run: pip3 install git+https://github.com/Scony/godot-gdscript-toolkit.git
run: pip3 install git+https://github.com/kuruk-mm/godot-gdscript-toolkit.git
- name: Check format GDScript
run: gdformat -d godot/

- name: GDScript Linter
run: gdlint godot/
# Depedencies section
# => Linux
- name: Install alsa and udev
Expand Down
99 changes: 99 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# CONTRIBUTING

## 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

Installation:
```bash
pip3 uninstall "gdtoolkit==4.*"
pip3 install git+https://github.com/kuruk-mm/godot-gdscript-toolkit.git
```

You can autoformat all files running:
```bash
gdformat godot/
```

You can run the linter with:
```bash
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`

! Remember to add executable permissions

```bash
chmod +x .git/hooks/pre-commit
```

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

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

# 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
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

## FORMAT RUST

# Change to the specific Rust directory
cd rust/decentraland-godot-lib

# 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
```
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
- With adding `-r` it builds the library in release mode. Note: the Godot executable is an editor, so it's a `release_debug` build, see the Target section [here](https://docs.godotengine.org/en/stable/contributing/development/compiling/introduction_to_the_buildsystem.html) for more infromation.
- With adding `-e` it also builds the library, but the project edition is executed instead of the client.

## GDScript formatting
## Contributing

When GD files are modified, they must be well-formated. You can autoformat all files running `gdformat godot/` (it requires [godot-gdscript-toolkit](https://github.com/Scony/godot-gdscript-toolkit) installed)
More details on [CONTRIBUTING.md](CONTRIBUTING.md)

## Debugging the library
This repos is set up to be opened with Visual Studio Code. In the section `Run and Debug` in the Activity bar, you can find the configuration for your platform.
Expand Down
48 changes: 48 additions & 0 deletions gdlintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class-definitions-order:
- tools
- classnames
- extends
- docstrings
- signals
- enums
- consts
- exports
- pubvars
- prvvars
- onreadypubvars
- onreadyprvvars
- staticvars
- others
class-load-variable-name: (([A-Z][a-z0-9]*)+|_?[a-z][a-z0-9]*(_[a-z0-9]+)*)
class-name: ([A-Z][a-z0-9]*)+
class-variable-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)*
comparison-with-itself: null
constant-name: _?[A-Z][A-Z0-9]*(_[A-Z0-9]+)*
disable: []
duplicated-load: null
enum-element-name: '[A-Z][A-Z0-9]*(_[A-Z0-9]+)*'
enum-name: ([A-Z][a-z0-9]*)+
excluded_directories: !!set
.git: null
expression-not-assigned: null
function-argument-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)*
function-arguments-number: 10
function-name: (_on_([A-Z][a-z0-9]*)+(_[a-z0-9]+)*|_?[a-z][a-z0-9]*(_[a-z0-9]+)*)
function-preload-variable-name: ([A-Z][a-z0-9]*)+
function-variable-name: '[a-z][a-z0-9]*(_[a-z0-9]+)*'
load-constant-name: (([A-Z][a-z0-9]*)+|_?[A-Z][A-Z0-9]*(_[A-Z0-9]+)*)
loop-variable-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)*
max-file-lines: 1000
max-line-length: 9999
max-public-methods: 20
max-returns: 6
mixed-tabs-and-spaces: null
no-elif-return: null
no-else-return: null
private-method-call: null
signal-name: '[a-z][a-z0-9]*(_[a-z0-9]+)*'
sub-class-name: _?([A-Z][a-z0-9]*)+
tab-characters: 1
trailing-whitespace: null
unnecessary-pass: null
unused-argument: null
66 changes: 33 additions & 33 deletions godot/src/config/config_data.gd
Original file line number Diff line number Diff line change
@@ -1,96 +1,99 @@
class_name ConfigData extends RefCounted
class_name ConfigData
extends RefCounted

signal param_changed(param: ConfigParams, new_value)

enum ConfigParams {
ContentDirectory,
Resolution,
WindowSize,
UiScale,
Gravity,
JumpVelocity,
WalkVelocity,
RunVelocity,
ProcessTickQuotaMs,
SceneRadius,
ShowFps,
LimitFps,
SkyBox,
AvatarProfile
CONTENT_DIRECTORY,
RESOLUTION,
WINDOW_SIZE,
UI_SCALE,
GRAVITY,
JUMP_VELOCITY,
WALK_VELOCITY,
RUN_VELOCITY,
PROCESS_TICK_QUOTA_MS,
SCENE_RADIUS,
SHOW_FPS,
LIMIT_FPS,
SKY_BOX,
AVATAR_PROFILE
}

signal param_changed(param: ConfigParams, new_value)
const SETTINGS_FILE = "user://settings.cfg"

var local_content_dir: String = OS.get_user_data_dir() + "/content":
set(value):
if DirAccess.dir_exists_absolute(value):
local_content_dir = value
param_changed.emit(ConfigParams.ContentDirectory)
param_changed.emit(ConfigParams.CONTENT_DIRECTORY)

var gravity: float = 55.0:
set(value):
gravity = value
param_changed.emit(ConfigParams.Gravity)
param_changed.emit(ConfigParams.GRAVITY)

var resolution: String = "1280 x 720":
set(value):
resolution = value
param_changed.emit(ConfigParams.Resolution)
param_changed.emit(ConfigParams.RESOLUTION)

var window_size: String = "1280 x 720":
set(value):
window_size = value
param_changed.emit(ConfigParams.WindowSize)
param_changed.emit(ConfigParams.WINDOW_SIZE)

var ui_scale: float:
set(value):
ui_scale = value
param_changed.emit(ConfigParams.UiScale)
param_changed.emit(ConfigParams.UI_SCALE)

var jump_velocity: float = 12.0:
set(value):
jump_velocity = value
param_changed.emit(ConfigParams.JumpVelocity)
param_changed.emit(ConfigParams.JUMP_VELOCITY)

var walk_velocity: float = 2.0:
set(value):
walk_velocity = value
param_changed.emit(ConfigParams.WalkVelocity)
param_changed.emit(ConfigParams.WALK_VELOCITY)

var run_velocity: float = 6.0:
set(value):
run_velocity = value
param_changed.emit(ConfigParams.RunVelocity)
param_changed.emit(ConfigParams.RUN_VELOCITY)

var process_tick_quota_ms: int = 10:
set(value):
process_tick_quota_ms = value
param_changed.emit(ConfigParams.ProcessTickQuotaMs)
param_changed.emit(ConfigParams.PROCESS_TICK_QUOTA_MS)

var scene_radius: int = 4:
set(value):
scene_radius = value
param_changed.emit(ConfigParams.SceneRadius)
param_changed.emit(ConfigParams.SCENE_RADIUS)

var show_fps: bool = true:
set(value):
show_fps = value
param_changed.emit(ConfigParams.ShowFps)
param_changed.emit(ConfigParams.SHOW_FPS)

# 0 - Vsync, 1 - No limit, Other-> Limit limit_fps that amount
var limit_fps: int = 0:
set(value):
limit_fps = value
param_changed.emit(ConfigParams.Gravity)
param_changed.emit(ConfigParams.GRAVITY)

# 0- without, 1 - pretty, skybox -default env
var skybox: int = 1:
set(value):
skybox = value
param_changed.emit(ConfigParams.SkyBox)
param_changed.emit(ConfigParams.SKY_BOX)

var avatar_profile: Dictionary = {}:
set(value):
avatar_profile = value
param_changed.emit(ConfigParams.AvatarProfile)
param_changed.emit(ConfigParams.AVATAR_PROFILE)

var last_realm_joined: String = "":
set(value):
Expand Down Expand Up @@ -147,9 +150,6 @@ func load_from_default():
self.last_parcel_position = Vector2i(72, -10)


const SETTINGS_FILE = "user://settings.cfg"


func load_from_settings_file():
var data_default = ConfigData.new()
data_default.load_from_default()
Expand Down
4 changes: 2 additions & 2 deletions godot/src/decentraland_components/audio_source.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func apply_audio_props(action_on_playing: bool):
self.play()


func _refresh_data():
func _async_refresh_data():
dcl_audio_clip_url = dcl_audio_clip_url.to_lower()

if last_loaded_audio_clip == dcl_audio_clip_url:
Expand All @@ -45,7 +45,7 @@ func _refresh_data():
var promise: Promise = Global.content_manager.fetch_audio(
last_loaded_audio_clip, content_mapping
)
var res = await promise.co_awaiter()
var res = await promise.async_awaiter()
if res is Promise.Error:
self.stop()
self.stream = null
Expand Down
Loading
Loading