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

Method lintMetadata

internal/lint/metadata.go:15–52  ·  view source on GitHub ↗
(f *core.File)

Source from the content-addressed store, hash-verified

13)
14
15func (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
54func extractFrontMatter(file, body string) (string, error) {
55 startIndex := strings.Index(file, body)

Callers 5

lintMarkdownMethod · 0.95
lintOrgMethod · 0.95
lintRSTMethod · 0.95
lintMDXMethod · 0.95
lintADocMethod · 0.95

Calls 7

MatchesMethod · 0.95
lintBlockMethod · 0.95
NewE201FromPositionFunction · 0.92
NewScopeFunction · 0.92
NewLinedBlockFunction · 0.92
extractFrontMatterFunction · 0.85
findBestLineBySubstringFunction · 0.85

Tested by

no test coverage detected