From ec2d0b7f082baafebe71c8368398edadeb53d360 Mon Sep 17 00:00:00 2001 From: NicholasBolen Date: Mon, 10 Aug 2026 10:08:25 -0600 Subject: [PATCH] fix(addon): write the temporary file next to the script being formatted The addon formats a temporary copy of the script instead of the file itself, to avoid Godot's "file changed outside of Godot" pop-up. That copy was written to the system's temporary folder, but the formatter discovers `.editorconfig` by walking up the folders above the file it formats. From `/tmp` it never reaches the project, so every editorconfig-only setting was silently dropped when formatting from the Godot editor, while the same file formatted correctly from the CLI. Writing the temporary copy next to the original script puts it back under the project's `.editorconfig`. The file name starts with a dot so Godot's filesystem scanner skips it while it briefly exists. Fixes #315 --- CHANGELOG.md | 1 + addons/GDQuest_GDScript_formatter/plugin.gd | 29 ++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5df9be7..9765747 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ This file documents the changes made to the formatter with each release. - fixed certain export annotations being moved out of their respective groups (#308) - Preserve up to one blank line used to group elements in "containers" like enums - Fixed losing blank line between statements in a body if the previous statement has an inline comment (#320, thanks @Buitragox for the fix) +- Fixed the Godot addon ignoring the project's `.editorconfig` when formatting. The addon formats a temporary copy of the script, and that copy now sits next to the original file so the formatter finds the project's `.editorconfig` (#315, #316) ## Release 0.24.0 (2026-07-25) diff --git a/addons/GDQuest_GDScript_formatter/plugin.gd b/addons/GDQuest_GDScript_formatter/plugin.gd index 965e272..9507a9a 100644 --- a/addons/GDQuest_GDScript_formatter/plugin.gd +++ b/addons/GDQuest_GDScript_formatter/plugin.gd @@ -766,10 +766,31 @@ func format_code( source_content = source_file.get_as_text() source_file.close() - var path_temporary_file := OS.get_temp_dir().path_join( - "gdscript_formatter_%d.gd" % Time.get_ticks_msec() - ) - var temporary_file := FileAccess.open(path_temporary_file, FileAccess.WRITE) + # The formatter looks for `.editorconfig` files by walking up the folders + # above the file it formats, so the temporary file has to sit next to the + # script it stands in for. Put it anywhere else, like the system's temporary + # folder, and the project's `.editorconfig` is never found. + # + # The leading dot in the file name keeps Godot's filesystem scanner from + # picking the temporary file up while it briefly exists. + var temporary_file_name := ".gdscript_formatter_%d.gd" % Time.get_ticks_msec() + var script_directory := "" + if not script_path.is_empty(): + script_directory = ProjectSettings.globalize_path(script_path).get_base_dir() + + var path_temporary_file := "" + var temporary_file: FileAccess = null + if not script_directory.is_empty(): + path_temporary_file = script_directory.path_join(temporary_file_name) + temporary_file = FileAccess.open(path_temporary_file, FileAccess.WRITE) + + # Unsaved scripts have no folder to sit next to, and a project folder can be + # read-only. Both fall back to the system's temporary folder, where + # `.editorconfig` lookup can't work, rather than failing to format at all. + if temporary_file == null: + path_temporary_file = OS.get_temp_dir().path_join(temporary_file_name) + temporary_file = FileAccess.open(path_temporary_file, FileAccess.WRITE) + if temporary_file == null: push_error("GDScript Formatter Error: Cannot create temporary file: " + path_temporary_file) return ""