summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Seitz <stephan.seitz@fau.de>2022-08-05 21:04:21 +0200
committerStephan Seitz <stephan.seitz@fau.de>2022-08-05 12:32:20 -0700
commit27424a2040efac021d6d86e14588c3998af99ccd (patch)
treea570fc86cd8ae9c3d025f23780fcea04e965cd66
parent3832fde3ee0a022924f8b1ace1b91f7c0b216b60 (diff)
indents(go): improve `@branch` rules
- Don't branch at `case` - Let `import_spec_list`/`var_declaration` behave like `const_declaration` Fixes #2166
-rw-r--r--queries/go/indents.scm3
-rw-r--r--tests/indent/go/multiple-vars.go19
-rw-r--r--tests/indent/go/switch.go14
3 files changed, 35 insertions, 1 deletions
diff --git a/queries/go/indents.scm b/queries/go/indents.scm
index a6fbf082..d88329c9 100644
--- a/queries/go/indents.scm
+++ b/queries/go/indents.scm
@@ -14,11 +14,12 @@
] @indent
[
- "case"
"}"
] @branch
(const_declaration ")" @branch)
+(import_spec_list ")" @branch)
+(var_declaration ")" @branch)
[
"}"
diff --git a/tests/indent/go/multiple-vars.go b/tests/indent/go/multiple-vars.go
new file mode 100644
index 00000000..f89a82e9
--- /dev/null
+++ b/tests/indent/go/multiple-vars.go
@@ -0,0 +1,19 @@
+package main
+
+var (
+ thing = 1
+ thingTwo = 2
+) // <-- This paren should be at 0 instead of indented
+
+var (
+ thing = 1
+ thingTwo = 2
+)
+
+func main() {
+ // It should be
+ var (
+ thing = 1
+ thingTwo = 2
+ )
+}
diff --git a/tests/indent/go/switch.go b/tests/indent/go/switch.go
new file mode 100644
index 00000000..8ccacd56
--- /dev/null
+++ b/tests/indent/go/switch.go
@@ -0,0 +1,14 @@
+// issue #2166
+package main
+
+import (
+ "fmt"
+)
+
+func test(ch byte) {
+ fmt.Println("hey!")
+ switch ch {
+ case 'l':
+ return
+ }
+}