-
-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/shfmt: add initial EditorConfig support
Using the editorconfig module we've written over the past weeks. See the README for a bit of docs on how it works. In particular, one can entirely disable the feature by formatting stdin or using any formatting flag. We don't do any merging of flags from EditorConfig and the command line right now; this keeps the implementation simple, and allows formatting entire directories while skipping EditorConfig files with no-op flags like "shfmt -ln=bash src/". It's not clear that the ability to merge options from both sides would be desirable; we might reconsider in the future. We've also added an undocumented SHFMT_NO_EDITORCONFIG environment variable, which can be set to "true" to completely disable the feature in case it breaks badly when first released. This flag will be removed once the feature has been released and stable for a few months. Fixes #393.
- Loading branch information
Showing
6 changed files
with
226 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
cp input.sh input.sh.orig | ||
|
||
# Using stdin should ignore the EditorConfig file. | ||
stdin input.sh | ||
shfmt | ||
cmp stdout input.sh.orig | ||
! stderr . | ||
|
||
# Using a file path should use EditorConfig, including with the use of flags | ||
# like -l. | ||
shfmt input.sh | ||
cmp stdout input.sh.golden | ||
! stderr . | ||
|
||
shfmt -l input.sh | ||
stdout 'input\.sh' | ||
! stderr . | ||
|
||
# Using any formatting option should skip all EditorConfig usage. | ||
shfmt -p input.sh | ||
cmp stdout input.sh.orig | ||
! stderr . | ||
|
||
shfmt -l -p input.sh | ||
! stdout . | ||
! stderr . | ||
|
||
shfmt -sr input.sh | ||
cmp stdout input.sh.orig | ||
! stderr . | ||
|
||
# Check that EditorConfig files merge properly. | ||
shfmt morespaces/input.sh | ||
cmp stdout morespaces/input.sh.golden | ||
! stderr . | ||
|
||
# Check a folder with all other knobs. | ||
shfmt -l otherknobs | ||
! stdout . | ||
! stderr . | ||
|
||
-- .editorconfig -- | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 3 | ||
-- input.sh -- | ||
{ | ||
indented | ||
} | ||
-- input.sh.golden -- | ||
{ | ||
indented | ||
} | ||
-- morespaces/.editorconfig -- | ||
[*.sh] | ||
indent_size = 6 | ||
-- morespaces/input.sh -- | ||
{ | ||
indented | ||
} | ||
-- morespaces/input.sh.golden -- | ||
{ | ||
indented | ||
} | ||
-- otherknobs/.editorconfig -- | ||
root = true | ||
|
||
[shell_variant_posix.sh] | ||
shell_variant = posix | ||
|
||
[shell_variant_mksh.sh] | ||
shell_variant = mksh | ||
|
||
[indent.sh] | ||
# check its default; we tested "space" above. | ||
|
||
[binary_next_line.sh] | ||
binary_next_line = true | ||
|
||
[switch_case_indent.sh] | ||
switch_case_indent = true | ||
|
||
[space_redirects.sh] | ||
space_redirects = true | ||
|
||
[keep_padding.sh] | ||
keep_padding = true | ||
|
||
-- otherknobs/shell_variant_posix.sh -- | ||
let badsyntax+ | ||
-- otherknobs/shell_variant_mksh.sh -- | ||
coproess |& | ||
-- otherknobs/indent.sh -- | ||
{ | ||
indented | ||
} | ||
-- otherknobs/binary_next_line.sh -- | ||
foo \ | ||
| bar | ||
-- otherknobs/switch_case_indent.sh -- | ||
case "$1" in | ||
A) echo foo ;; | ||
esac | ||
-- otherknobs/space_redirects.sh -- | ||
echo foo > bar | ||
-- otherknobs/keep_padding.sh -- | ||
echo foo bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters