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

Method lintHTMLTokens

internal/lint/ast.go:34–146  ·  view source on GitHub ↗
(f *core.File, raw []byte, offset int)

Source from the content-addressed store, hash-verified

32}
33
34func (l *Linter) lintHTMLTokens(f *core.File, raw []byte, offset int) error { //nolint:unparam
35 var class, parentClass, attr string
36 var inBlock, inline, skip, skipClass bool
37
38 buf := bytes.NewBufferString("")
39
40 // The user has specified a custom list of tags/classes to ignore.
41 if len(l.Manager.Config.SkippedScopes) > 0 {
42 skipTags = l.Manager.Config.SkippedScopes
43 }
44 if len(l.Manager.Config.IgnoredClasses) > 0 {
45 skipClasses = append(skipClasses, l.Manager.Config.IgnoredClasses...)
46 }
47
48 skipped := []string{"tt", "code", "kbd"}
49 if len(l.Manager.Config.IgnoredScopes) > 0 {
50 skipped = l.Manager.Config.IgnoredScopes
51 }
52
53 walker := newWalker(f, raw, offset)
54 for {
55 tokt, tok, txt := walker.walk()
56
57 walker.addCls(txt, tokt == html.StartTagToken)
58 closed := walker.canClose()
59
60 class = getAttribute(tok, "class")
61 skipClass = checkClasses(class, skipClasses)
62
63 blockSkip := skipClass && !core.StringInSlice(txt, inlineTags)
64 if tokt == html.ErrorToken { //nolint:gocritic
65 break
66 } else if tokt == html.StartTagToken && (core.StringInSlice(txt, skipTags) || blockSkip) {
67 walker.setCls(txt, blockSkip)
68 inBlock = true
69 f.Metrics[txt]++
70 } else if inBlock && (core.StringInSlice(txt, skipTags) || closed) {
71 inBlock = false
72 if closed {
73 walker.close()
74 }
75 } else if tokt == html.StartTagToken {
76 if (txt == "em" || txt == "b") && walker.lastTag() == "code" {
77 // FIXME: See https://github.com/errata-ai/vale/issues/421
78 txt = "code"
79 }
80 inline = core.StringInSlice(txt, inlineTags)
81 skip = core.StringInSlice(txt, skipped)
82 walker.addTag(txt)
83 } else if tokt == html.EndTagToken && core.StringInSlice(txt, inlineTags) {
84 walker.activeTag = ""
85 } else if tokt == html.CommentToken {
86 f.UpdateComments(txt)
87 walker.update(txt, tokt)
88 } else if tokt == html.TextToken {
89 skip = skip || shouldBeSkipped(walker.tagHistory, f.NormedExt)
90 // NOTE: We used to create a "temporary" context here to support
91 // nested scopes, such as 'link', that are linted twice: once as

Callers 9

lintMarkdownMethod · 0.95
lintOrgMethod · 0.95
lintRSTMethod · 0.95
lintMDXMethod · 0.95
lintHTMLMethod · 0.95
lintTxtToHTMLMethod · 0.95
lintDITAMethod · 0.95
lintXMLMethod · 0.95
lintADocMethod · 0.95

Calls 15

lintScopeMethod · 0.95
lintTagsMethod · 0.95
lintSizedScopesMethod · 0.95
StringInSliceFunction · 0.92
newWalkerFunction · 0.85
getAttributeFunction · 0.85
checkClassesFunction · 0.85
shouldBeSkippedFunction · 0.85
cleanFunction · 0.85
endsWithTightBoundaryFunction · 0.85
walkMethod · 0.80
addClsMethod · 0.80

Tested by

no test coverage detected