aria-props.js 1.9 KB

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