html-has-lang.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. var _jsxAstUtils = require("jsx-ast-utils");
  3. var _schemas = require("../util/schemas");
  4. /**
  5. * @fileoverview Enforce html element has lang prop.
  6. * @author Ethan Cohen
  7. */
  8. // ----------------------------------------------------------------------------
  9. // Rule Definition
  10. // ----------------------------------------------------------------------------
  11. var errorMessage = '<html> elements must have the lang prop.';
  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/html-has-lang.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 !== 'html') {
  25. return;
  26. }
  27. var lang = (0, _jsxAstUtils.getPropValue)((0, _jsxAstUtils.getProp)(node.attributes, 'lang'));
  28. if (lang) {
  29. return;
  30. }
  31. context.report({
  32. node,
  33. message: errorMessage
  34. });
  35. }
  36. };
  37. }
  38. };