๐Ÿš€ Grammar-Aware Code Formatter: Structure through separation (supports Go, JavaScript, TypeScript, JSX, and TSX)
go formatter code-formatter javascript typescript jsx tsx
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf: Precompile regular expressions

Fuwn 6c44f3e6 be6ea488

+8 -7
+8 -7
formatter.go
··· 10 10 "strings" 11 11 ) 12 12 13 + var ( 14 + closingBracePattern = regexp.MustCompile(`^\s*[\}\)]`) 15 + openingBracePattern = regexp.MustCompile(`[\{\(]\s*$`) 16 + caseLabelPattern = regexp.MustCompile(`^\s*(case\s+.*|default\s*):\s*$`) 17 + commentOnlyPattern = regexp.MustCompile(`^\s*//`) 18 + packageLinePattern = regexp.MustCompile(`^package\s+`) 19 + ) 20 + 13 21 type CommentMode int 14 22 15 23 const ( ··· 176 184 177 185 var result []string 178 186 179 - closingBracePattern := regexp.MustCompile(`^\s*[\}\)]`) 180 - openingBracePattern := regexp.MustCompile(`[\{\(]\s*$`) 181 - caseLabelPattern := regexp.MustCompile(`^\s*(case\s+.*|default\s*):\s*$`) 182 - commentOnlyPattern := regexp.MustCompile(`^\s*//`) 183 - packageLinePattern := regexp.MustCompile(`^package\s+`) 184 187 previousWasOpenBrace := false 185 188 previousType := "" 186 189 previousWasComment := false ··· 295 298 } 296 299 297 300 func (f *Formatter) findNextNonCommentLine(lines []string, startIndex int) int { 298 - commentOnlyPattern := regexp.MustCompile(`^\s*//`) 299 - 300 301 for index := startIndex; index < len(lines); index++ { 301 302 trimmed := strings.TrimSpace(lines[index]) 302 303