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

Function init

src/core/rules/alt-require.ts:7–38  ·  view source on GitHub ↗
(parser, reporter)

Source from the content-addressed store, hash-verified

5 description:
6 'The alt attribute of an <img> element must be present and alt attribute of area[href] and input[type=image] must have a value.',
7 init(parser, reporter) {
8 parser.addListener('tagstart', (event) => {
9 const tagName = event.tagName.toLowerCase()
10 const mapAttrs = parser.getMapAttrs(event.attrs)
11 const col = event.col + tagName.length + 1
12 let selector
13
14 if (tagName === 'img' && !('alt' in mapAttrs)) {
15 reporter.warn(
16 'An alt attribute must be present on <img> elements.',
17 event.line,
18 col,
19 this,
20 event.raw
21 )
22 } else if (
23 (tagName === 'area' && 'href' in mapAttrs) ||
24 (tagName === 'input' && mapAttrs['type'] === 'image')
25 ) {
26 if (!('alt' in mapAttrs) || mapAttrs['alt'] === '') {
27 selector = tagName === 'area' ? 'area[href]' : 'input[type=image]'
28 reporter.warn(
29 `The alt attribute of ${selector} must have a value.`,
30 event.line,
31 col,
32 this,
33 event.raw
34 )
35 }
36 }
37 })
38 },
39} as Rule

Callers

nothing calls this directly

Calls 3

addListenerMethod · 0.80
getMapAttrsMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected