sh
sh copied to clipboard
`indent_style = space` in .editorconfig is not respected by shfmt
The file is:
#!/usr/bin/env bash
if [[ true ]]; then
echo 1 # leading with 4 spaces
fi
And shfmt will change the leading spaces to tab:
My ~/.editorconfig:
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
[*.sh]
indent_size = 4
indent_style = space
shell_variant = bash
binary_next_line = false
switch_case_indent = true
space_redirects = true
keep_padding = true
function_next_line = false
What shfmt version are you running? Did you double check this? Because we have code and tests for this feature, so this seems odd.
Sorry for the missing information. I'm using the latest version 3.9.0:
added
cat -Tto visualize the tabs
OS ENV:
> uname -a
Linux ringo 6.10.8-arch1-2.1-g14 #1 SMP PREEMPT_DYNAMIC Sat, 07 Sep 2024 06:01:43 +0000 x86_64 GNU/Linux
Does your shell script file have a .sh file extension? If not you might need to use [[shell]] instead of or in addition to [*.sh].
The file's name and content are given in my previous comment @wwuck
@Karmenzind apologies for missing that. I had image display turned off in my browser.
When you are in /tmp .editorconfig cannot be found.
I can recreate the issue if I create /tmp/a.sh and then run shfmt. If you then copy your .editorconfig to /tmp/.editorconfig and re-run shfmt, there is no issue.
I would guess that editorconfig searches for root configs traversing up the file tree, so if you have your config in ~/.editorconfig it is expected for it to not be found when in /tmp
@nord-erik is completely right. Per the EditorConfig spec, the config file must be in the same directory, or a parent directory, relative to the source file.