-
-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/shfmt: document how --filename relates to EditorConfig support #1055
Comments
Not sure I understand; the entire point of editorconfig files is that they apply to the files relative to their location. When would you want to use this flag? |
@mvdan There seems to be some potentially unexpected behavior with how Take the following root = true
[*]
charset = utf-8
[*.sh]
indent_style = space
indent_size = 2
space_redirects = true
switch_case_indent = true When I have a file named #!/usr/bin/env bash
function foo()
{
if [ -x $file ]
then
myArray=(item1 item2 item3)
elif [ $file1 -nt $file2 ]
then
unset myArray
else
echo "Usage: $0 file ..."
fi
}
for (( i = 0; i < 5; i++ ))
do
read -p r
print -n $r
wait $!
done I can successfully format this file, with shfmt foo.sh However, if I instead add the contents of shfmt < foo.sh Given this, what I have noticed is if I provide a shfmt < foo.sh --filename foo.sh I'm not sure if this is a known feature/issue/limitation? If it is, I think that an update to the man page that mentions that this flag is required when providing content to stdin in order for the nearest So this is where my original request came from for having an |
That is all working as intended. When you pass in a file via stdin, the filename is not known. We added the filename flag precisely for this purpose (and for related others such as error positions). |
@mvdan Thanks for confirming! Would documentation in the man page regarding this requirement be worth adding? |
Oops, this was indeed an undocumented fact. Opening a PR. |
EditorConfig files are found based on a script's absolute path, and the EditorConfig patterns are usually filename-based as well. When formatting standard input, there is no known filename or path. Sometimes there's a need to format a stream of bytes in memory without having to place them on a file, which is why we support stdin. We added the --filename flag for this purpose a long time ago, and the tests already verified this fact - we just hadn't documented it. While here, also add a test case for absolute paths. Fixes #1055.
@mvdan perfect! Thank you! |
EditorConfig files are found based on a script's absolute path, and the EditorConfig patterns are usually filename-based as well. When formatting standard input, there is no known filename or path. Sometimes there's a need to format a stream of bytes in memory without having to place them on a file, which is why we support stdin. We added the --filename flag for this purpose a long time ago, and the tests already verified this fact - we just hadn't documented it. While here, also add a test case for absolute paths. Fixes #1055.
EditorConfig files are found based on a script's absolute path, and the EditorConfig patterns are usually filename-based as well. When formatting standard input, there is no known filename or path. Sometimes there's a need to format a stream of bytes in memory without having to place them on a file, which is why we support stdin. We added the --filename flag for this purpose a long time ago, and the tests already verified this fact - we just hadn't documented it. While here, also add a test case for absolute paths, and make the man page flags consistently use double dashes. Fixes #1055.
EditorConfig files are found based on a script's absolute path, and the EditorConfig patterns are usually filename-based as well. When formatting standard input, there is no known filename or path. Sometimes there's a need to format a stream of bytes in memory without having to place them on a file, which is why we support stdin. We added the --filename flag for this purpose a long time ago, and the tests already verified this fact - we just hadn't documented it. While here, also add a test case for absolute paths, and make the man page flags consistently use double dashes. Fixes #1055.
I'm imagining something like the following:
This becomes useful when integrating shfmt into other applications/plugins. Please see the following PR, if interested, for Gradle plugin integration: diffplug/spotless#2031.
A different flag name can be used than what I provided, but this at least gives the gist of what I'm looking for.
The text was updated successfully, but these errors were encountered: