discord-rpc-godot icon indicating copy to clipboard operation
discord-rpc-godot copied to clipboard

Add static typing to all properties

Open HotNoggin opened this issue 9 months ago • 8 comments

What happened?

I've just enabled enforcing static typing in my project, because I do like to see errors when I miss typing my variables. However, most of the variables in this plugin are completely untyped, so I was left with tens of errors to "fix".

Screenshot 2024-04-24 172442 Screenshot 2024-04-24 183232

It is a bit tricky to track down the root of these errors since they do come from an addon, so they appear with gdscript:// with a strange ID instead of a traceable res:// path.

I added static typing to every single variable and changed all of the paths to use this format: @onready var name: Type = $Path/To/Node as Type . It was a bit tedious, and since I do plan to use this addon and future versions in future projects, I would love if the addon could have strict static typing enforced already. plugin.gd seemed to be the biggest culprit with all of its paths and variables. The things that should be typed are:

  • Variable and constant declarations, as var name: Type (and as Type if necessary)
  • Function return values and parameters, as func name(parameter: Type) -> Type:

Aside from static typing, unsafe property access should also be fixed (Like setting the position of a Node which might be a Node2D but you don't know if it is).

If you do plan to do this, you can check if it's been done correctly by enabling these settings: Screenshot 2024-04-24 135734

Thanks for reaching the bottom and please ease the suffering of us static typers. :)

Version

1.3.1

Godot Version

4.2.1

Exact steps to reproduce this error

Simply enable these settings and you'll get the same errors each time you reload the project:

Screenshot 2024-04-24 135734

GDScript

The whole repo

Godot output

PAIN

Additional information

cough cough

It's dusty down here.

Checks

  • [x] I tried reinstalling the addon or tried to fix it myself with other methods.
  • [X] I tried restarting Discord and Godot completely.
  • [X] I did read the documentation https://vaporvee.com/docs/discord-rpc-godot/

HotNoggin avatar Apr 25 '24 00:04 HotNoggin

Huh i thought i already did do that but will fix that soon! thanks for reporting :)

vaporvee avatar Apr 25 '24 11:04 vaporvee

"Soon" i said... Will make some time to fix all gh issues and some more next week. I promise

vaporvee avatar Jul 29 '24 20:07 vaporvee

No problemo!

HotNoggin avatar Aug 03 '24 16:08 HotNoggin

okay i think i fixed it but i didn't get by far as many errors as you. I made everything static i may send you the update early to test it. Also thank you for showing me these settings these are very helpful! I like to type static too but forget it often..

vaporvee avatar Aug 08 '24 19:08 vaporvee

ADDON-Discord-RPC-Godot.zip try it whenever you have time for it

vaporvee avatar Aug 08 '24 20:08 vaporvee

While the RPC is working 100%, the errors still seem to be there. It looks like there are only a few stray untyped variables left. image

HotNoggin avatar Aug 09 '24 15:08 HotNoggin

Checking the changes in github, and it looks to be a script in Debug.tscn: image The red is my version, which was static-typing-error-free.

HotNoggin avatar Aug 09 '24 15:08 HotNoggin

weird i dont get these errors somehow but will fix them

vaporvee avatar Aug 09 '24 15:08 vaporvee