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

Method lintCodeOld

internal/lint/code.go:81–153  ·  view source on GitHub ↗

lintCodeOld lints source code by analyzing its comments. Deprecated: we now use tree-sitter to parse code and collect comments.

(f *core.File)

Source from the content-addressed store, hash-verified

79//
80// Deprecated: we now use tree-sitter to parse code and collect comments.
81func (l *Linter) lintCodeOld(f *core.File) error {
82 var line, match, txt string
83 var lnLength, padding int
84 var block bytes.Buffer
85
86 lines := 0
87 comments := core.CommentsByNormedExt[f.NormedExt]
88 if len(comments) == 0 {
89 return nil
90 }
91
92 scanner := bufio.NewScanner(strings.NewReader(f.Content))
93 ignored := l.Manager.Config.IgnoredScopes
94
95 skipAll := core.StringInSlice("comment", ignored)
96 skipInline := core.StringInSlice("comment.line", ignored)
97 skipBlock := core.StringInSlice("comment.block", ignored)
98
99 scope := "%s" + f.RealExt
100 inline := regexp.MustCompile(comments["inline"])
101 blockStart := regexp.MustCompile(comments["blockStart"])
102 blockEnd := regexp.MustCompile(comments["blockEnd"])
103 ignore := false
104 inBlock := false
105
106 scanner.Split(core.SplitLines)
107 for scanner.Scan() {
108 line = core.Sanitize(scanner.Text() + "\n")
109 lnLength = len(line)
110 lines++
111 if inBlock {
112 // We're in a block comment.
113 if match = blockEnd.FindString(line); len(match) > 0 {
114 // We've found the end of the block.
115 block.WriteString(line)
116 txt = block.String()
117
118 b := nlp.NewBlock(
119 txt, txt, fmt.Sprintf(scope, "text.comment.block"))
120 if !(skipAll || skipBlock) {
121 if err := l.lintBlock(f, b, lines+1, 0, true); err != nil {
122 return err
123 }
124 }
125
126 block.Reset()
127 inBlock = false
128 } else {
129 block.WriteString(line)
130 }
131 } else if match = inline.FindString(line); len(match) > 0 {
132 // We've found an inline comment. We need padding here in order to
133 // calculate the column span because, for example, a line like
134 // 'print("foo") # ...' will be condensed to '# ...'.
135 padding = lnLength - len(match)
136
137 b := nlp.NewBlock(
138 match, match, fmt.Sprintf(scope, "text.comment.line"))

Callers 1

lintCodeMethod · 0.95

Calls 5

lintBlockMethod · 0.95
StringInSliceFunction · 0.92
SanitizeFunction · 0.92
NewBlockFunction · 0.92
StringMethod · 0.80

Tested by

no test coverage detected