| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports["default"] = void 0;
|
|---|
| 7 | var _jsxAstUtils = require("jsx-ast-utils");
|
|---|
| 8 | var _languageTags = _interopRequireDefault(require("language-tags"));
|
|---|
| 9 | var _schemas = require("../util/schemas");
|
|---|
| 10 | var _getElementType = _interopRequireDefault(require("../util/getElementType"));
|
|---|
| 11 | function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|---|
| 12 | /**
|
|---|
| 13 | * @fileoverview Enforce lang attribute has a valid value.
|
|---|
| 14 | * @author Ethan Cohen
|
|---|
| 15 | */
|
|---|
| 16 |
|
|---|
| 17 | // ----------------------------------------------------------------------------
|
|---|
| 18 | // Rule Definition
|
|---|
| 19 | // ----------------------------------------------------------------------------
|
|---|
| 20 |
|
|---|
| 21 | var errorMessage = 'lang attribute must have a valid value.';
|
|---|
| 22 | var schema = (0, _schemas.generateObjSchema)();
|
|---|
| 23 | var _default = exports["default"] = {
|
|---|
| 24 | meta: {
|
|---|
| 25 | docs: {
|
|---|
| 26 | url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/lang.md',
|
|---|
| 27 | description: 'Enforce lang attribute has a valid value.'
|
|---|
| 28 | },
|
|---|
| 29 | schema: [schema]
|
|---|
| 30 | },
|
|---|
| 31 | create: function create(context) {
|
|---|
| 32 | var elementType = (0, _getElementType["default"])(context);
|
|---|
| 33 | return {
|
|---|
| 34 | JSXAttribute: function JSXAttribute(node) {
|
|---|
| 35 | var name = (0, _jsxAstUtils.propName)(node);
|
|---|
| 36 | if (name && name.toUpperCase() !== 'LANG') {
|
|---|
| 37 | return;
|
|---|
| 38 | }
|
|---|
| 39 | var parent = node.parent;
|
|---|
| 40 | var type = elementType(parent);
|
|---|
| 41 | if (type && type !== 'html') {
|
|---|
| 42 | return;
|
|---|
| 43 | }
|
|---|
| 44 | var value = (0, _jsxAstUtils.getLiteralPropValue)(node);
|
|---|
| 45 |
|
|---|
| 46 | // Don't check identifiers
|
|---|
| 47 | if (value === null) {
|
|---|
| 48 | return;
|
|---|
| 49 | }
|
|---|
| 50 | if (value === undefined) {
|
|---|
| 51 | context.report({
|
|---|
| 52 | node,
|
|---|
| 53 | message: errorMessage
|
|---|
| 54 | });
|
|---|
| 55 | return;
|
|---|
| 56 | }
|
|---|
| 57 | if (_languageTags["default"].check(value)) {
|
|---|
| 58 | return;
|
|---|
| 59 | }
|
|---|
| 60 | context.report({
|
|---|
| 61 | node,
|
|---|
| 62 | message: errorMessage
|
|---|
| 63 | });
|
|---|
| 64 | }
|
|---|
| 65 | };
|
|---|
| 66 | }
|
|---|
| 67 | };
|
|---|
| 68 | module.exports = exports.default; |
|---|