| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports["default"] = void 0;
|
|---|
| 7 | var _ariaQuery = require("aria-query");
|
|---|
| 8 | var _jsxAstUtils = require("jsx-ast-utils");
|
|---|
| 9 | var _schemas = require("../util/schemas");
|
|---|
| 10 | var _getSuggestion = _interopRequireDefault(require("../util/getSuggestion"));
|
|---|
| 11 | function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|---|
| 12 | /**
|
|---|
| 13 | * @fileoverview Enforce all aria-* properties are valid.
|
|---|
| 14 | * @author Ethan Cohen
|
|---|
| 15 | */
|
|---|
| 16 |
|
|---|
| 17 | // ----------------------------------------------------------------------------
|
|---|
| 18 | // Rule Definition
|
|---|
| 19 | // ----------------------------------------------------------------------------
|
|---|
| 20 |
|
|---|
| 21 | var ariaAttributes = _ariaQuery.aria.keys();
|
|---|
| 22 | var errorMessage = function errorMessage(name) {
|
|---|
| 23 | var suggestions = (0, _getSuggestion["default"])(name, ariaAttributes);
|
|---|
| 24 | var message = "".concat(name, ": This attribute is an invalid ARIA attribute.");
|
|---|
| 25 | if (suggestions.length > 0) {
|
|---|
| 26 | return "".concat(message, " Did you mean to use ").concat(suggestions, "?");
|
|---|
| 27 | }
|
|---|
| 28 | return message;
|
|---|
| 29 | };
|
|---|
| 30 | var schema = (0, _schemas.generateObjSchema)();
|
|---|
| 31 | var _default = exports["default"] = {
|
|---|
| 32 | meta: {
|
|---|
| 33 | docs: {
|
|---|
| 34 | url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/aria-props.md',
|
|---|
| 35 | description: 'Enforce all `aria-*` props are valid.'
|
|---|
| 36 | },
|
|---|
| 37 | schema: [schema]
|
|---|
| 38 | },
|
|---|
| 39 | create: function create(context) {
|
|---|
| 40 | return {
|
|---|
| 41 | JSXAttribute: function JSXAttribute(attribute) {
|
|---|
| 42 | var name = (0, _jsxAstUtils.propName)(attribute);
|
|---|
| 43 |
|
|---|
| 44 | // `aria` needs to be prefix of property.
|
|---|
| 45 | if (name.indexOf('aria-') !== 0) {
|
|---|
| 46 | return;
|
|---|
| 47 | }
|
|---|
| 48 | var isValid = _ariaQuery.aria.has(name);
|
|---|
| 49 | if (isValid === false) {
|
|---|
| 50 | context.report({
|
|---|
| 51 | node: attribute,
|
|---|
| 52 | message: errorMessage(name)
|
|---|
| 53 | });
|
|---|
| 54 | }
|
|---|
| 55 | }
|
|---|
| 56 | };
|
|---|
| 57 | }
|
|---|
| 58 | };
|
|---|
| 59 | module.exports = exports.default; |
|---|