Have dumbindent no longer treat labels specially

This commit is contained in:
Nigel Tao committed 2020-06-06 22:38:29 +10:00
1 parent 6424bae087
commit 0ad5f9b617
2 files changed
+1 -26

No files matched your search

-25
View File
@@ -138,9 +138,6 @@ func FormatBytes(dst []byte, src []byte) []byte {
if (nParens > 0) || hanging { if (nParens > 0) || hanging {
indent += 4 indent += 4
} }
if (indent >= 2) && isLabel(line) {
indent -= 2
}
for indent > 0 { for indent > 0 {
n := indent n := indent
if n > len(spaces) { if n > len(spaces) {
@@ -234,28 +231,6 @@ func trimTrailingWhiteSpace(s []byte) []byte {
return s return s
} }
// isLabel returns whether s looks like "foo:" or "bar_baz:;".
func isLabel(s []byte) bool {
for (len(s) > 0) && (s[len(s)-1] == ';') {
s = s[:len(s)-1]
}
if (len(s) < 2) || (s[len(s)-1] != ':') {
return false
}
s = s[:len(s)-1]
for _, c := range s {
switch {
case ('0' <= c) && (c <= '9'):
case ('A' <= c) && (c <= 'Z'):
case ('a' <= c) && (c <= 'z'):
case c == '_':
default:
return false
}
}
return true
}
// lastNonWhiteSpace returns the 'z' in "abc xyz ". It returns '\x00' if s // lastNonWhiteSpace returns the 'z' in "abc xyz ". It returns '\x00' if s
// consists entirely of spaces or tabs. // consists entirely of spaces or tabs.
func lastNonWhiteSpace(s []byte) byte { func lastNonWhiteSpace(s []byte) byte {
+1 -1
View File
@@ -63,7 +63,7 @@ func TestFormatBytes(tt *testing.T) {
src: " a['key'] = /*{\n\n\nX*/ ; \nb = {\nc = 0\n", src: " a['key'] = /*{\n\n\nX*/ ; \nb = {\nc = 0\n",
want: "a['key'] = /*{\n\n\nX*/ ;\nb = {\n c = 0\n", want: "a['key'] = /*{\n\n\nX*/ ;\nb = {\n c = 0\n",
}, { }, {
// Label. // Nested blocks with label.
src: "if (b) {\nlabel:\nswitch (i) {\ncase 0:\nj = k\nbreak;\n}\n}\n", src: "if (b) {\nlabel:\nswitch (i) {\ncase 0:\nj = k\nbreak;\n}\n}\n",
want: "if (b) {\n label:\n switch (i) {\n case 0:\n j = k\n break;\n }\n}\n", want: "if (b) {\n label:\n switch (i) {\n case 0:\n j = k\n break;\n }\n}\n",
}} }}