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

Method lintCode

internal/lint/code.go:31–76  ·  view source on GitHub ↗
(f *core.File)

Source from the content-addressed store, hash-verified

29}
30
31func (l *Linter) lintCode(f *core.File) error {
32 lang, err := code.GetLanguageFromExt(f.RealExt)
33 if err != nil {
34 // No tree-sitter grammar available for this file type.
35 return l.lintCodeOld(f)
36 }
37 ignored := l.Manager.Config.IgnoredScopes
38
39 found, err := updateQueries(f, l.Manager.Config.Views)
40 if err != nil {
41 return err
42 } else if len(found) > 0 {
43 lang.Queries = found
44 }
45
46 comments, err := code.GetComments([]byte(f.Content), lang)
47 if err != nil {
48 return err
49 }
50 wholeFile := f.Content
51
52 last := 0
53 for _, comment := range comments {
54 l.SetMetaScope(comment.Scope)
55 if core.StringInSlice("comment", ignored) {
56 continue
57 } else if core.StringInSlice(comment.Scope, ignored) {
58 continue
59 }
60 f.SetText(comment.Text)
61
62 err = l.lintLines(f)
63 if err != nil {
64 return err
65 }
66
67 size := len(f.Alerts)
68 if size != last {
69 f.Alerts = adjustAlerts(f.Alerts, last, comment, lang)
70 }
71 last = size
72 }
73
74 f.SetText(wholeFile)
75 return nil
76}
77
78// lintCodeOld lints source code by analyzing its comments.
79//

Callers 1

lintFileMethod · 0.95

Calls 9

lintCodeOldMethod · 0.95
SetMetaScopeMethod · 0.95
lintLinesMethod · 0.95
GetLanguageFromExtFunction · 0.92
GetCommentsFunction · 0.92
StringInSliceFunction · 0.92
updateQueriesFunction · 0.85
adjustAlertsFunction · 0.85
SetTextMethod · 0.80

Tested by

no test coverage detected