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

Add an editor setting to trim final newlines when saving a script #8867

Closed
bitwise-aiden opened this issue Jan 12, 2024 · 4 comments · Fixed by godotengine/godot#87099
Closed
Milestone

Comments

@bitwise-aiden
Copy link

bitwise-aiden commented Jan 12, 2024

Describe the project you are working on

The relevant aspect of the project is that the built-in script editor is the primary method of interacting with scripts.

Describe the problem or limitation you are having in your project

Often when working on complex code, stray newlines will make their way into a script at the end of the file. Sometimes these lines go uncaught and get committed into the repo.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

  • Adding trim_final_newlines_on_save setting will help to clean up any stray newlines.

This helps to ensure the code cleanliness while interacting with the built-in editor. This would help ensure parity with other editors like Visual Studio Code (trimFinalNewlines).

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

  • If trim_final_newlines_on_save is enabled and a user saves a script, it will remove any newlines after the final newline of the file.

If this enhancement will not be used often, can it be worked around with a few lines of script?

This can be worked around with an editor plugin, but it is a general quality of life improvement to the script editor.

Is there a reason why this should be core and not an add-on in the asset library?

It fits with the current trim_whitespace_on_save setting that is already present.

@bitwise-aiden bitwise-aiden changed the title Add trim_final_newlines_on_save and insert_final_newline_on_save settings Add trim_final_newlines_on_save settings Jan 12, 2024
@bitwise-aiden
Copy link
Author

While working on a PoC I noticed that insert_final_newline is called regardless making exposing the setting redundant (source).

The trimming of additional newlines is still relevant.

@Calinou
Copy link
Member

Calinou commented Jan 12, 2024

Sounds good. I suggest enabling this by default too, since it's rarely ever desired to have more than 1 blank line at the end of a file.

@Calinou Calinou changed the title Add trim_final_newlines_on_save settings Add an editor setting to trim final newlines when saving a script Jan 12, 2024
@bitwise-aiden
Copy link
Author

I suggest enabling this by default too, since it's rarely ever desired to have more than 1 blank line at the end of a file.

That's a good point. Thanks!

@bitwise-aiden
Copy link
Author

bitwise-aiden commented May 17, 2024

Now that this PR has been merged, the PR implementing this proposal has been updated as is ready for review. godotengine/godot#87099

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants