@html-eslint/eslint-plugin
Version:
ESLint plugin for HTML
52 lines (45 loc) • 1.06 kB
JavaScript
/** @import {RuleModule} from "../types" */
const { RULE_CATEGORY } = require("../constants");
const { getRuleUrl } = require("./utils/rule");
const MESSAGE_IDS = {
MISSING: "missing",
};
/** @type {RuleModule<[]>} */
module.exports = {
meta: {
type: "code",
docs: {
description: "Require `` in HTML",
category: RULE_CATEGORY.BEST_PRACTICE,
recommended: true,
url: getRuleUrl("require-doctype"),
},
fixable: true,
schema: [],
messages: {
[MESSAGE_IDS.MISSING]: "Missing ``",
},
},
create(context) {
let hasDocType = false;
return {
Doctype() {
hasDocType = true;
},
Tag(node) {
if (node.name !== "html") {
return;
}
if (!hasDocType) {
context.report({
node,
messageId: MESSAGE_IDS.MISSING,
fix(fixer) {
return fixer.insertTextBeforeRange([0, 0], "\n");
},
});
}
},
};
},
};