@html-eslint/eslint-plugin
Version:
ESLint plugin for html
62 lines (54 loc) • 1.41 kB
JavaScript
/**
* @typedef { import("../types").RuleModule<[]> } RuleModule
* @typedef { import("@html-eslint/types").Tag } Tag
* @typedef { import("@html-eslint/types").StyleTag } StyleTag
* @typedef { import("@html-eslint/types").ScriptTag } ScriptTag
*/
const { RULE_CATEGORY } = require("../constants");
const { findAttr } = require("./utils/node");
const { createVisitors } = require("./utils/visitors");
const MESSAGE_IDS = {
UNEXPECTED: "unexpected",
};
/**
* @type {RuleModule}
*/
module.exports = {
meta: {
type: "code",
docs: {
description: "Disallow use of positive `tabindex`.",
category: RULE_CATEGORY.ACCESSIBILITY,
recommended: false,
},
fixable: null,
schema: [],
messages: {
[MESSAGE_IDS.UNEXPECTED]: "Unexpected use of positive `tabindex`.",
},
},
create(context) {
/**
* @param {Tag | StyleTag | ScriptTag} node
*/
function check(node) {
const tabIndexAttr = findAttr(node, "tabindex");
if (
tabIndexAttr &&
tabIndexAttr.value &&
!tabIndexAttr.value.parts.length &&
parseInt(tabIndexAttr.value.value, 10) > 0
) {
context.report({
node: tabIndexAttr,
messageId: MESSAGE_IDS.UNEXPECTED,
});
}
}
return createVisitors(context, {
Tag: check,
StyleTag: check,
ScriptTag: check,
});
},
};