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

Formatter adds extraneous newlines after annotations above functions #267

Closed
voithos opened this issue Jan 11, 2024 · 3 comments
Closed
Labels
bug Something isn't working formatter
Milestone

Comments

@voithos
Copy link

voithos commented Jan 11, 2024

Currently, when a function has an annotation such as @warning_ignore written above it, gdformat will add newlines in between the function and the annotation.

Example input (which I would expect to be largely unchanged):

func okfunc() -> void:
	pass


@warning_ignore("unused_parameter")
func testfunc(some_param: int) -> void:
	pass

Current output:

func okfunc() -> void:
	pass


@warning_ignore("unused_parameter")


func testfunc(some_param: int) -> void:
	pass

@Scony Scony added bug Something isn't working formatter labels Jan 11, 2024
@Scony
Copy link
Owner

Scony commented Jan 11, 2024

Well, looks like @warning_ignore works with function headers now... I knew this day would come :) In short, @warning_ignore is treated as a standalone annotation for now and therefore it's separated from function in your example. Looks like it will have to be context-aware now.
Thanks for reporting!

@brianrodri
Copy link
Contributor

brianrodri commented Jan 2, 2025

Hi I'm a GdUnit4 user and I'd like to fix this to declutter my parameterized tests. I'd appreciate some guidance in the right direction since it seems to have missed the 4.2 milestone from earlier this year.

Here's an example of what my tests are formatted to look like
class_name DialogueManagerSanityTest
extends GdUnitTestSuite

const SRC_DIALOGUE_GROUP = preload("res://test/addons/dialogue_manager/src_dialogue_group.tres")

@warning_ignore("unused_parameter")


func test_pause_keys_are_sorted(
	line: DialogueLine, test_parameters: Array = _get_all_dialogue_lines()
) -> void:
	assert_bool(Arrays.is_sorted(line.pauses.keys())).is_true()


@warning_ignore("unused_parameter")


func test_inline_mutations_are_sorted(
	line: DialogueLine, test_parameters: Array = _get_all_dialogue_lines()
) -> void:
	assert_bool(Arrays.is_sorted(line.inline_mutations)).is_true()


static func _get_all_dialogue_lines() -> Array:
	var result: Array = []
	for dialogue_resource in SRC_DIALOGUE_GROUP.load_all():
		for data in dialogue_resource.lines.values():
			result.push_back([DialogueLine.new(data)])
	return result

Looks like it will have to be context-aware now.

Does this mean the parser needs to be changed, not the formatter? Could you please explain this a little more so I can try my hand at a fix?

@Scony Scony closed this as completed in 90ebbd1 Jan 2, 2025
@github-project-automation github-project-automation bot moved this to Done in Roadmap Jan 2, 2025
@Scony
Copy link
Owner

Scony commented Jan 2, 2025

It's fixed in master now. In case you'd spot a problem with some other @warning_ignore annotation, this should be easy to fix now - just see the 90ebbd1 for reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working formatter
Projects
Status: Done
Development

No branches or pull requests

3 participants