source: frontend/node_modules/eslint-plugin-jsx-a11y/lib/rules/anchor-ambiguous-text.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.3 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports["default"] = void 0;
7var _schemas = require("../util/schemas");
8var _getAccessibleChildText = _interopRequireDefault(require("../util/getAccessibleChildText"));
9var _getElementType = _interopRequireDefault(require("../util/getElementType"));
10function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
11/**
12 * @fileoverview Enforce anchor text to not exactly match 'click here', 'here', 'link', 'learn more', and user-specified words.
13 * @author Matt Wang
14 *
15 */
16
17// ----------------------------------------------------------------------------
18// Rule Definition
19// ----------------------------------------------------------------------------
20
21var DEFAULT_AMBIGUOUS_WORDS = ['click here', 'here', 'link', 'a link', 'learn more'];
22var schema = (0, _schemas.generateObjSchema)({
23 words: _schemas.arraySchema
24});
25var _default = exports["default"] = {
26 meta: {
27 docs: {
28 url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/anchor-ambiguous-text.md',
29 description: 'Enforce `<a>` text to not exactly match "click here", "here", "link", or "a link".'
30 },
31 schema: [schema]
32 },
33 create: function create(context) {
34 var elementType = (0, _getElementType["default"])(context);
35 var typesToValidate = ['a'];
36 var options = context.options[0] || {};
37 var _options$words = options.words,
38 words = _options$words === void 0 ? DEFAULT_AMBIGUOUS_WORDS : _options$words;
39 var ambiguousWords = new Set(words);
40 return {
41 JSXOpeningElement: function JSXOpeningElement(node) {
42 var nodeType = elementType(node);
43
44 // Only check anchor elements and custom types.
45 if (typesToValidate.indexOf(nodeType) === -1) {
46 return;
47 }
48 var nodeText = (0, _getAccessibleChildText["default"])(node.parent, elementType);
49 if (!ambiguousWords.has(nodeText)) {
50 // check the value
51 return;
52 }
53 context.report({
54 node,
55 message: 'Ambiguous text within anchor. Screen reader users rely on link text for context; the words "{{wordsList}}" are ambiguous and do not provide enough context.',
56 data: {
57 wordsList: words.join('", "')
58 }
59 });
60 }
61 };
62 }
63};
64module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.