From db0b4baf4f9fcc5103cab543e7e6965ae6f46c39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Tue, 13 Feb 2024 22:10:58 +0000 Subject: [PATCH] cmd/shfmt: document when --filename is needed for EditorConfig support 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. --- cmd/shfmt/shfmt.1.scd | 3 +++ cmd/shfmt/testdata/script/editorconfig.txtar | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/cmd/shfmt/shfmt.1.scd b/cmd/shfmt/shfmt.1.scd index 84dd2dec..20553ff3 100644 --- a/cmd/shfmt/shfmt.1.scd +++ b/cmd/shfmt/shfmt.1.scd @@ -73,6 +73,9 @@ predictable. Some aspects of the format can be configured via printer flags. *-filename* str Provide a name for the standard input file. + Use of this flag is necessary for EditorConfig support to work, + since EditorConfig files are found relative to the location of a script. + ## Printer flags *-i*, *--indent* diff --git a/cmd/shfmt/testdata/script/editorconfig.txtar b/cmd/shfmt/testdata/script/editorconfig.txtar index 99037c13..34af5234 100644 --- a/cmd/shfmt/testdata/script/editorconfig.txtar +++ b/cmd/shfmt/testdata/script/editorconfig.txtar @@ -14,6 +14,10 @@ stdin stdin-filename-bash ! exec shfmt -filename=foo_posix.sh stderr '^foo_posix.sh:.* arrays are a bash' +stdin stdin-filename-bash +! exec shfmt -filename=${WORK}/foo_posix.sh +stderr ^${WORK@R}/'foo_posix.sh:.* arrays are a bash' + # Using a file path should use EditorConfig, including with the use of flags # like -l. exec shfmt input.sh