(f *core.File)
| 13 | ) |
| 14 | |
| 15 | func (l Linter) lintMetadata(f *core.File) error { |
| 16 | metadata := make(map[string]any) |
| 17 | |
| 18 | body, err := frontmatter.Parse(strings.NewReader(f.Content), &metadata) |
| 19 | if errors.Is(err, frontmatter.ErrNotFound) { |
| 20 | return nil |
| 21 | } else if err != nil { |
| 22 | return core.NewE201FromPosition(err.Error(), f.Path, 1) |
| 23 | } |
| 24 | |
| 25 | fm, fmErr := extractFrontMatter(f.Content, string(body)) |
| 26 | if fmErr != nil { |
| 27 | return core.NewE201FromPosition(fmErr.Error(), f.Path, 1) |
| 28 | } |
| 29 | |
| 30 | ignored := check.NewScope(l.Manager.Config.IgnoredScopes) |
| 31 | for key, value := range metadata { |
| 32 | if s, ok := value.(string); ok { |
| 33 | i, _ := findBestLineBySubstring(fm, s) |
| 34 | if i < 0 { |
| 35 | continue |
| 36 | } |
| 37 | scope := "text.frontmatter." + key + f.RealExt |
| 38 | |
| 39 | block := nlp.NewLinedBlock(f.Content, s, scope, i-1) |
| 40 | if ignored.Matches(block) { |
| 41 | continue |
| 42 | } |
| 43 | |
| 44 | lErr := l.lintBlock(f, block, len(f.Lines), 0, false) |
| 45 | if lErr != nil { |
| 46 | return lErr |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | return nil |
| 52 | } |
| 53 | |
| 54 | func extractFrontMatter(file, body string) (string, error) { |
| 55 | startIndex := strings.Index(file, body) |
no test coverage detected