Scony / godot-gdscript-toolkit

Independent set of GDScript tools - parser, linter, formatter, and more
MIT License
944 stars 65 forks source link

`gdlint`: missing support for functions on `class-definitions-order:` #277

Open MikeSchulze opened 7 months ago

MikeSchulze commented 7 months ago

Hi, I love the tool, but I miss the option to sort by function types.

Please add options to check the sort order, for static, public and private functions

class-definitions-order:
  - static_func
  - public_func
  - private_func
Scony commented 7 months ago

I think I was going to add it at some point, but there is an ambiguity regarding some core functions inherited e.g. from Node etc.

Consider the code:

func _ready():
    pass
func public_foo():
    pass
func _private_foo():
    pass

To me, the above order is ok - first we got essential, inherited functions , then public ones ,then private ones. The problem is, however, that the gdtoolkit is unable to tell if _ready() is implicitly inherited and therefore it cannot differentiate between _ready() and _private_foo(). Thus having

class-definitions-order:
  - static_func
  - public_func
  - private_func

would require the code to be:

func public_foo():
    pass
func _ready():
    pass
func _private_foo():
    pass

How would you resolve that?

MikeSchulze commented 7 months ago

Hello, thank you for the answer. I would not make a distinction between core and user private functions. But if you can read the original class definition, it would be possible. Unfortunately, I don't see an example of static functions in your example.

class-definitions-order:
  - static_func
  - public_func
  - private_func

Should be result in

static func bar():
    pass
static func _bar():
    pass
func foo():
    pass
func _ready():
    pass
func _foo():
    pass
Scony commented 7 months ago

Okay, I'll experiment with that.