source: frontend/node_modules/eslint-plugin-jsx-a11y/lib/rules/autocomplete-valid.js

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

Fix frontend appearance

  • Property mode set to 100644
File size: 2.5 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports["default"] = void 0;
7var _axeCore = require("axe-core");
8var _jsxAstUtils = require("jsx-ast-utils");
9var _schemas = require("../util/schemas");
10var _getElementType = _interopRequireDefault(require("../util/getElementType"));
11function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
12/**
13 * @fileoverview Ensure autocomplete attribute is correct.
14 * @author Wilco Fiers
15 */
16
17// ----------------------------------------------------------------------------
18// Rule Definition
19// ----------------------------------------------------------------------------
20
21var schema = (0, _schemas.generateObjSchema)({
22 inputComponents: _schemas.arraySchema
23});
24var _default = exports["default"] = {
25 meta: {
26 docs: {
27 url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/autocomplete-valid.md',
28 description: 'Enforce that autocomplete attributes are used correctly.'
29 },
30 schema: [schema]
31 },
32 create: function create(context) {
33 var elementType = (0, _getElementType["default"])(context);
34 return {
35 JSXOpeningElement: function JSXOpeningElement(node) {
36 var options = context.options[0] || {};
37 var _options$inputCompone = options.inputComponents,
38 inputComponents = _options$inputCompone === void 0 ? [] : _options$inputCompone;
39 var inputTypes = ['input'].concat(inputComponents);
40 var elType = elementType(node);
41 var autocomplete = (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(node.attributes, 'autocomplete'));
42 if (typeof autocomplete !== 'string' || !inputTypes.includes(elType)) {
43 return;
44 }
45 var type = (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(node.attributes, 'type'));
46 var _runVirtualRule = (0, _axeCore.runVirtualRule)('autocomplete-valid', {
47 nodeName: 'input',
48 attributes: {
49 autocomplete,
50 // Which autocomplete is valid depends on the input type
51 type: type === null ? undefined : type
52 }
53 }),
54 violations = _runVirtualRule.violations;
55 if (violations.length === 0) {
56 return;
57 }
58 // Since we only test one rule, with one node, return the message from first (and only) instance of each
59 context.report({
60 node,
61 message: violations[0].nodes[0].all[0].message
62 });
63 }
64 };
65 }
66};
67module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.