MCPcopy Create free account
hub / github.com/vale-cli/vale / FormatFromExt

Function FormatFromExt

internal/core/format.go:99–126  ·  view source on GitHub ↗

FormatFromExt takes a file extension and returns its [normExt, format] list, if supported.

(path string, mapping map[string]string)

Source from the content-addressed store, hash-verified

97// FormatFromExt takes a file extension and returns its [normExt, format]
98// list, if supported.
99func FormatFromExt(path string, mapping map[string]string) (string, string) {
100 base := strings.Trim(filepath.Ext(path), ".")
101 kind := getFormat("." + base)
102
103 if format, found := mapping[base]; found {
104 if kind == "code" && getFormat("."+format) == "markup" {
105 // NOTE: This is a special case of embedded markup within code.
106 return "." + format, "fragment"
107 } else if kind == "data" && getFormat("."+format) == "markup" {
108 // NOTE: This is a special case of embedded markup within data.
109 //
110 // Unlike code, data formats are *always* linted as a fragment with
111 // the default format as plain text.
112 return "." + format, "data"
113 }
114 base = format
115 }
116
117 base = "." + base
118 for r, f := range FormatByExtension {
119 m, _ := regexp.MatchString(r, base)
120 if m {
121 return f[0], f[1]
122 }
123 }
124
125 return "unknown", "unknown"
126}
127
128func getFormat(ext string) string {
129 for r, f := range FormatByExtension {

Callers 2

TestFormatFromExtFunction · 0.85
NewFileFunction · 0.85

Calls 1

getFormatFunction · 0.85

Tested by 1

TestFormatFromExtFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…