iframe-has-title.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. var _jsxAstUtils = require("jsx-ast-utils");
  3. var _schemas = require("../util/schemas");
  4. /**
  5. * @fileoverview Enforce iframe elements have a title attribute.
  6. * @author Ethan Cohen
  7. */
  8. // ----------------------------------------------------------------------------
  9. // Rule Definition
  10. // ----------------------------------------------------------------------------
  11. var errorMessage = '<iframe> elements must have a unique title property.';
  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/iframe-has-title.md'
  17. },
  18. schema: [schema]
  19. },
  20. create: function create(context) {
  21. return {
  22. JSXOpeningElement: function JSXOpeningElement(node) {
  23. var type = (0, _jsxAstUtils.elementType)(node);
  24. if (type && type !== 'iframe') {
  25. return;
  26. }
  27. var title = (0, _jsxAstUtils.getPropValue)((0, _jsxAstUtils.getProp)(node.attributes, 'title'));
  28. if (title && typeof title === 'string') {
  29. return;
  30. }
  31. context.report({
  32. node,
  33. message: errorMessage
  34. });
  35. }
  36. };
  37. }
  38. };