(f *core.File)
| 29 | } |
| 30 | |
| 31 | func (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 | // |
no test coverage detected