Skip to content
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: Add support for minify and simplify via EditorConfig #1062

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ColemanTom
Copy link

I've never used go before, so I this is a naive, but working approach to support simplify and minify in editorconfig files. I have not looked at adding tests yet, but will add tests if this code change approach is agreeable.

Manual testing below.

$ for opt in "" "simplify=true" "minify=true"; do echo $'[[shell]]\nindent=4\n'"$opt" > .editorconfig; echo "### $opt"; shfmt --diff f.sh; done
###
--- f.sh.orig
+++ f.sh
@@ -1,11 +1,11 @@
 #!/bin/bash

 ff() {
-local h=asdffdfd
+       local h=asdffdfd
 }
 g=a

-echo $(( 1 + 2 ));
+echo $((1 + 2))
 ff
 echo $h
 [[ "$HOME" == "$HELLO" ]]
### simplify=true
--- f.sh.orig
+++ f.sh
@@ -1,11 +1,11 @@
 #!/bin/bash

 ff() {
-local h=asdffdfd
+       local h=asdffdfd
 }
 g=a

-echo $(( 1 + 2 ));
+echo $((1 + 2))
 ff
 echo $h
-[[ "$HOME" == "$HELLO" ]]
+[[ $HOME == "$HELLO" ]]
### minify=true
--- f.sh.orig
+++ f.sh
@@ -1,11 +1,9 @@
 #!/bin/bash
-
-ff() {
+ff(){
 local h=asdffdfd
 }
 g=a
-
-echo $(( 1 + 2 ));
+echo $((1+2))
 ff
 echo $h
-[[ "$HOME" == "$HELLO" ]]
+[[ $HOME == "$HELLO" ]]

Adding, for e.g. -s or -mn to the shfmt call leads to consistent results (i.e. if -s is on, then for the opts=, opts="simplify=true", we get the second result above, but the opts="minify=true" option stays consistent with minify respected).

Closes #819.

@ColemanTom
Copy link
Author

I have added some tests following the structure of other editorconfig tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cmd/shfmt: support editorconfig properties for -s and -mn
1 participant