Closed hbarcelos closed 2 years ago
From the ALEInfo I see ALE uses this command:
shfmt -i 2 < /path/to/script.sh
That is different from what you use stand alone:
shfmt -w /path/to/script.sh
Not familiar with shfmt but maybe the .editorconfig won't work if the linter is invoked using stdin as input? or if the -w option is not used?
If we can figure out what command ALE needs to execute to get the functionality you need then it should be easy to modify the fixer to use that command.
So it looks like shfmt
will ignore .editorconfig
if any command line arguments are used.
Can we drop the -i 2
flag from the fixer invocation? If we do so, then if there's no .editorconfig
, it will simply use whatever the default is for shfmt
. Users willing to customize it can simply create the file.
Should be fairly easy to do modifying the fixer itself: autoload/ale/fixers/shfmt.vim
. Feel free to submit an MR with the modifications.
Apparently there is an incompatibility between ALE and shfmt
.
AFAIK, ALE copies the buffer contents to a temp file, formats it and replace the current buffer with the result.
If ALE is running the following command:
shfmt < /tmp/vZ4cRfE/78/script.sh
It won't work well with .editorconfig
because shfmt
is not aware of $PWD
, they use the path of the file passed as parameter to recursively look for the config file.
This gives us 2 problems:
stdin
, there's no file path to inspect to look for the config.stdin
, the file path would be in /tmp/<some_dir>/...
and there wouldn't be any config files there.From this we have 2 options:
.editorconfig
to the same temp directory as the file being formatted.Option 1 seems pretty clunky, but I'm not sure option 2 is feasible with the current design.
I'd appreciate any guidance here.
You can try adding %s
to the fixer command. ALE will replace that placeholder with the full path of the file being fixed (see :h ale-command-format-strings
).
Another option is if shfmt supports some command line argument to explicitly set the configuration (e.g. -w .editorconfig) then you can try using ale#path#FindNearestFile()
function to find the nearest .editorconfig file to the current buffer and build the fixer command so it explicitly sets it.
For better results do both, set explictly the config file if found and use %s to set full path of the file being fixed.
Check rubocop.vim for example using %s
and astyle.vim for an example of finding configuration file.
You can try adding %s to the fixer command. ALE will replace that placeholder with the full path of the file being fixed (see :h ale-command-format-strings).
From what I hear from shfmt
author, that's the only viable option.
Will work on a MR. Thanks for the pointers.
Information
VIM version
Operating System:
Linux - Manjaro
What went wrong
shfmt
added support for configuration through.editorconfig
a while ago. The problem is that if I run:ALEFix shfmt
in any supported file type, it apparently ignores any config set in.editorconfig
and simply sticks with the default.Reproducing the bug
Create an
.editorconfig
file like:Starting with the following file:
If I run
shfmt
standalone (shfmt -w script.sh
), I get:If I run
:ALEFix shfmt
, I get::ALEInfo