aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2022-09-05 10:25:10 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2022-09-05 10:28:47 +0200
commit5856eb36475eadd12398d1189f0fa0035f8a4d90 (patch)
tree4b7ddb9087660db5a411513a5e010f09e401ea65
parenta7f6b2ffd830063a0e88c5e228b7c4bbe8e3894c (diff)
downloadvis-editorconfig-5856eb36475eadd12398d1189f0fa0035f8a4d90.tar.gz
fix insert_final_newline for empty files
When saving an empty file in a directory containing an editorconfig using the insert_final_newline option the content lookup 'file.size-1' fails. Fix this by only adding a final newline if the file contains any data. Signed-off-by: Florian Fischer <florian.fischer@muhq.space>
-rw-r--r--edconf.lua2
1 files changed, 1 insertions, 1 deletions
diff --git a/edconf.lua b/edconf.lua
index 25edf6b..64b9387 100644
--- a/edconf.lua
+++ b/edconf.lua
@@ -36,7 +36,7 @@ function insert_final_newline(file, path)
-- therefore respect edconf_hooks_enabled. Since this function runs
-- blazingly fast and scales with a complexity of O(1), however,
-- there is no need to disable it.
- if file:content(file.size-1, 1) ~= '\n' then
+ if file.size > 0 and file:content(file.size-1, 1) ~= '\n' then
file:insert(file.size, '\n')
end
end