diff options
author | Florian Fischer <florian.fischer@muhq.space> | 2022-09-05 10:25:10 +0200 |
---|---|---|
committer | Florian Fischer <florian.fischer@muhq.space> | 2022-09-05 10:28:47 +0200 |
commit | 5856eb36475eadd12398d1189f0fa0035f8a4d90 (patch) | |
tree | 4b7ddb9087660db5a411513a5e010f09e401ea65 | |
parent | a7f6b2ffd830063a0e88c5e228b7c4bbe8e3894c (diff) | |
download | vis-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.lua | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -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 |