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