Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

69 wiersze
2.6 KiB

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