(parser, reporter)
| 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 |
nothing calls this directly
no test coverage detected