@html-eslint/eslint-plugin
Version:
ESLint plugin for html
54 lines (47 loc) • 997 B
JavaScript
/**
* @typedef { import("../types").RuleModule<[]> } RuleModule
*/
const { RULE_CATEGORY } = require("../constants");
const MESSAGE_IDS = {
MISSING: "missing",
};
/**
* @type {RuleModule}
*/
module.exports = {
meta: {
type: "code",
docs: {
description: "Require `` in html,",
category: RULE_CATEGORY.BEST_PRACTICE,
recommended: true,
},
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");
},
});
}
},
};
},
};