no-access-key.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. var _jsxAstUtils = require("jsx-ast-utils");
  3. var _schemas = require("../util/schemas");
  4. /**
  5. * @fileoverview Enforce no accesskey attribute on element.
  6. * @author Ethan Cohen
  7. */
  8. // ----------------------------------------------------------------------------
  9. // Rule Definition
  10. // ----------------------------------------------------------------------------
  11. var errorMessage = 'No access key attribute allowed. Inconsistencies between keyboard shortcuts and keyboard comments used by screenreader and keyboard only users create a11y complications.';
  12. var schema = (0, _schemas.generateObjSchema)();
  13. module.exports = {
  14. meta: {
  15. docs: {
  16. url: 'https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules/no-access-key.md'
  17. },
  18. schema: [schema]
  19. },
  20. create: function create(context) {
  21. return {
  22. JSXOpeningElement: function JSXOpeningElement(node) {
  23. var accessKey = (0, _jsxAstUtils.getProp)(node.attributes, 'accesskey');
  24. var accessKeyValue = (0, _jsxAstUtils.getPropValue)(accessKey);
  25. if (accessKey && accessKeyValue) {
  26. context.report({
  27. node,
  28. message: errorMessage
  29. });
  30. }
  31. }
  32. };
  33. }
  34. };