馃殌 Grammar-Aware Code Formatter: Structure through separation (supports Go, JavaScript, TypeScript, JSX, and TSX)
go formatter code-formatter javascript typescript jsx tsx
at main 44 lines 937 B view raw
1package main 2 3import ( 4 "encoding/json" 5 "fmt" 6 "os" 7 "strings" 8) 9 10type Configuration struct { 11 GroupSingleLineFunctions bool `json:"group_single_line_functions"` 12 CommentMode string `json:"comment_mode"` 13} 14 15func (configuration Configuration) commentMode() (CommentMode, error) { 16 switch strings.ToLower(configuration.CommentMode) { 17 case "", "follow": 18 return CommentsFollow, nil 19 case "precede": 20 return CommentsPrecede, nil 21 case "standalone": 22 return CommentsStandalone, nil 23 default: 24 return 0, fmt.Errorf("invalid comment_mode: %q (use follow, precede, or standalone)", configuration.CommentMode) 25 } 26} 27 28func loadConfiguration() Configuration { 29 var configuration Configuration 30 31 for _, fileName := range []string{".iku.json", "iku.json"} { 32 fileData, readError := os.ReadFile(fileName) 33 34 if readError != nil { 35 continue 36 } 37 38 _ = json.Unmarshal(fileData, &configuration) 39 40 break 41 } 42 43 return configuration 44}