MCPcopy
hub / github.com/zegl/kube-score / detectFileLocation

Function detectFileLocation

parser/parse.go:235–251  ·  view source on GitHub ↗
(fileName string, fileOffset int, fileContents []byte)

Source from the content-addressed store, hash-verified

233}
234
235func detectFileLocation(fileName string, fileOffset int, fileContents []byte) ks.FileLocation {
236 // If the object YAML begins with a Helm style "# Source: " comment
237 // Use the information in there as the file name
238 firstRow := string(bytes.Split(fileContents, []byte("\n"))[0])
239 helmTemplatePrefix := "# Source: "
240 if strings.HasPrefix(firstRow, helmTemplatePrefix) {
241 return ks.FileLocation{
242 Name: firstRow[len(helmTemplatePrefix):],
243 Line: 1, // Set line to 1 as the line definition gets lost in Helm
244 }
245 }
246
247 return ks.FileLocation{
248 Name: fileName,
249 Line: fileOffset,
250 }
251}
252
253func (p *Parser) decodeItem(s *parsedObjects, detectedVersion schema.GroupVersionKind, fileName string, fileOffset int, fileContents []byte) error {
254 addPodSpeccer := func(ps ks.PodSpecer) {

Callers 3

TestFileLocationHelmFunction · 0.85
TestFileLocationFunction · 0.85
decodeItemMethod · 0.85

Calls

no outgoing calls

Tested by 2

TestFileLocationHelmFunction · 0.68
TestFileLocationFunction · 0.68