| 1 | /**
|
|---|
| 2 | * @fileoverview Enforce html element has lang prop.
|
|---|
| 3 | * @author Ethan Cohen
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | // -----------------------------------------------------------------------------
|
|---|
| 7 | // Requirements
|
|---|
| 8 | // -----------------------------------------------------------------------------
|
|---|
| 9 |
|
|---|
| 10 | import { RuleTester } from 'eslint';
|
|---|
| 11 | import parserOptionsMapper from '../../__util__/parserOptionsMapper';
|
|---|
| 12 | import parsers from '../../__util__/helpers/parsers';
|
|---|
| 13 | import rule from '../../../src/rules/html-has-lang';
|
|---|
| 14 |
|
|---|
| 15 | // -----------------------------------------------------------------------------
|
|---|
| 16 | // Tests
|
|---|
| 17 | // -----------------------------------------------------------------------------
|
|---|
| 18 |
|
|---|
| 19 | const ruleTester = new RuleTester();
|
|---|
| 20 |
|
|---|
| 21 | const expectedError = {
|
|---|
| 22 | message: '<html> elements must have the lang prop.',
|
|---|
| 23 | type: 'JSXOpeningElement',
|
|---|
| 24 | };
|
|---|
| 25 |
|
|---|
| 26 | ruleTester.run('html-has-lang', rule, {
|
|---|
| 27 | valid: parsers.all([].concat(
|
|---|
| 28 | { code: '<div />;' },
|
|---|
| 29 | { code: '<html lang="en" />' },
|
|---|
| 30 | { code: '<html lang="en-US" />' },
|
|---|
| 31 | { code: '<html lang={foo} />' },
|
|---|
| 32 | { code: '<html lang />' },
|
|---|
| 33 | { code: '<HTML />' },
|
|---|
| 34 | { code: '<HTMLTop lang="en" />', errors: [expectedError], settings: { 'jsx-a11y': { components: { HTMLTop: 'html' } } } },
|
|---|
| 35 | )).map(parserOptionsMapper),
|
|---|
| 36 | invalid: parsers.all([].concat(
|
|---|
| 37 | { code: '<html />', errors: [expectedError] },
|
|---|
| 38 | { code: '<html {...props} />', errors: [expectedError] },
|
|---|
| 39 | { code: '<html lang={undefined} />', errors: [expectedError] },
|
|---|
| 40 | { code: '<HTMLTop />', errors: [expectedError], settings: { 'jsx-a11y': { components: { HTMLTop: 'html' } } } },
|
|---|
| 41 | )).map(parserOptionsMapper),
|
|---|
| 42 | });
|
|---|