| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports["default"] = void 0;
|
|---|
| 7 | var _axeCore = require("axe-core");
|
|---|
| 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 Ensure autocomplete attribute is correct.
|
|---|
| 14 | * @author Wilco Fiers
|
|---|
| 15 | */
|
|---|
| 16 |
|
|---|
| 17 | // ----------------------------------------------------------------------------
|
|---|
| 18 | // Rule Definition
|
|---|
| 19 | // ----------------------------------------------------------------------------
|
|---|
| 20 |
|
|---|
| 21 | var schema = (0, _schemas.generateObjSchema)({
|
|---|
| 22 | inputComponents: _schemas.arraySchema
|
|---|
| 23 | });
|
|---|
| 24 | var _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 | };
|
|---|
| 67 | module.exports = exports.default; |
|---|