Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
29 changes: 25 additions & 4 deletions addons/GDQuest_GDScript_formatter/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down