MCPcopy
hub / github.com/htmlhint/HTMLHint / init

Function init

src/core/rules/html-lang-require.ts:30–67  ·  view source on GitHub ↗
(parser, reporter)

Source from the content-addressed store, hash-verified

28 description:
29 'The lang attribute of an <html> element must be present and should be valid.',
30 init(parser, reporter) {
31 parser.addListener('tagstart', (event) => {
32 const tagName = event.tagName.toLowerCase()
33 const mapAttrs = parser.getMapAttrs(event.attrs)
34 const col = event.col + tagName.length + 1
35 const langValidityPattern = new RegExp(languageTag, 'g')
36
37 if (tagName === 'html') {
38 if ('lang' in mapAttrs) {
39 if (!mapAttrs['lang']) {
40 reporter.warn(
41 'The lang attribute of <html> element must have a value.',
42 event.line,
43 col,
44 this,
45 event.raw
46 )
47 } else if (!langValidityPattern.test(mapAttrs['lang'])) {
48 reporter.warn(
49 'The lang attribute value of <html> element must be a valid BCP47.',
50 event.line,
51 col,
52 this,
53 event.raw
54 )
55 }
56 } else {
57 reporter.warn(
58 'An lang attribute must be present on <html> elements.',
59 event.line,
60 col,
61 this,
62 event.raw
63 )
64 }
65 }
66 })
67 },
68} as Rule

Callers

nothing calls this directly

Calls 3

addListenerMethod · 0.80
getMapAttrsMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected