| [9af201e] | 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports["default"] = void 0;
|
|---|
| 7 | var _ariaQuery = require("aria-query");
|
|---|
| 8 | var _jsxAstUtils = require("jsx-ast-utils");
|
|---|
| 9 | var _schemas = require("../util/schemas");
|
|---|
| 10 | var _getElementType = _interopRequireDefault(require("../util/getElementType"));
|
|---|
| 11 | function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|---|
| 12 | /**
|
|---|
| 13 | * @fileoverview Enforce scope prop is only used on <th> elements.
|
|---|
| 14 | * @author Ethan Cohen
|
|---|
| 15 | */
|
|---|
| 16 |
|
|---|
| 17 | // ----------------------------------------------------------------------------
|
|---|
| 18 | // Rule Definition
|
|---|
| 19 | // ----------------------------------------------------------------------------
|
|---|
| 20 |
|
|---|
| 21 | var errorMessage = 'The scope prop can only be used on <th> elements.';
|
|---|
| 22 | var schema = (0, _schemas.generateObjSchema)();
|
|---|
| 23 | var _default = exports["default"] = {
|
|---|
| 24 | meta: {
|
|---|
| 25 | docs: {
|
|---|
| 26 | url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/scope.md',
|
|---|
| 27 | description: 'Enforce `scope` prop is only used on `<th>` elements.'
|
|---|
| 28 | },
|
|---|
| 29 | schema: [schema]
|
|---|
| 30 | },
|
|---|
| 31 | create: function create(context) {
|
|---|
| 32 | var elementType = (0, _getElementType["default"])(context);
|
|---|
| 33 | return {
|
|---|
| 34 | JSXAttribute: function JSXAttribute(node) {
|
|---|
| 35 | var name = (0, _jsxAstUtils.propName)(node);
|
|---|
| 36 | if (name && name.toUpperCase() !== 'SCOPE') {
|
|---|
| 37 | return;
|
|---|
| 38 | }
|
|---|
| 39 | var parent = node.parent;
|
|---|
| 40 | var tagName = elementType(parent);
|
|---|
| 41 |
|
|---|
| 42 | // Do not test higher level JSX components, as we do not know what
|
|---|
| 43 | // low-level DOM element this maps to.
|
|---|
| 44 | if (!_ariaQuery.dom.has(tagName)) {
|
|---|
| 45 | return;
|
|---|
| 46 | }
|
|---|
| 47 | if (tagName && tagName.toUpperCase() === 'TH') {
|
|---|
| 48 | return;
|
|---|
| 49 | }
|
|---|
| 50 | context.report({
|
|---|
| 51 | node,
|
|---|
| 52 | message: errorMessage
|
|---|
| 53 | });
|
|---|
| 54 | }
|
|---|
| 55 | };
|
|---|
| 56 | }
|
|---|
| 57 | };
|
|---|
| 58 | module.exports = exports.default; |
|---|