eslint-plugin-htm
Version:
An incredible ESLint plugin for HTML based on HTMLHint
178 lines (166 loc) • 4.99 kB
JavaScript
var eslintPluginUtils = require('eslint-plugin-utils');
var path = require('node:path');
var node_url = require('node:url');
var core = require('@pkgr/core');
var htmlhint = require('htmlhint');
var __defProp$1 = Object.defineProperty;
var __defProps$1 = Object.defineProperties;
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues$1 = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp$1.call(b, prop))
__defNormalProp$1(a, prop, b[prop]);
if (__getOwnPropSymbols$1)
for (var prop of __getOwnPropSymbols$1(b)) {
if (__propIsEnum$1.call(b, prop))
__defNormalProp$1(a, prop, b[prop]);
}
return a;
};
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
const base = {
parser: "eslint-plugin-htm",
plugins: ["htm", "utils"],
processor: "utils/jsonMessage"
};
const recommended = __spreadProps$1(__spreadValues$1({}, base), {
rules: {
"htm/html": 1
}
});
var configs_ = /*#__PURE__*/Object.freeze({
__proto__: null,
base: base,
recommended: recommended
});
const import_meta = {};
const _filename = typeof __filename === "undefined" || core.EVAL_FILENAMES.has(__filename) ? node_url.fileURLToPath(import_meta.url) : __filename;
const { name, version } = core.cjsRequire(
path.resolve(_filename, "../../package.json")
);
var meta$1 = /*#__PURE__*/Object.freeze({
__proto__: null,
name: name,
version: version
});
const meta = {
name: "htm-eslint",
version
};
const parseForESLint = (text, _options) => {
var _a, _b;
const lines = text.split("\n");
return {
ast: {
// @ts-expect-error -- bad ts enum
type: "Program",
sourceType: "module",
comments: [],
tokens: [],
body: [],
range: [0, text.length],
loc: {
start: {
line: 1,
column: 0
},
end: {
line: lines.length,
column: (_b = (_a = lines.at(-1)) == null ? void 0 : _a.length) != null ? _b : 0
}
}
}
};
};
const parse = (text, options) => parseForESLint(text).ast;
var parser = /*#__PURE__*/Object.freeze({
__proto__: null,
meta: meta,
parse: parse,
parseForESLint: parseForESLint
});
const html = {
meta: {
type: "problem",
messages: {},
schema: []
},
defaultOptions: [],
create(context) {
const sourceText = context.sourceCode.text;
return {
Program() {
const results = htmlhint.HTMLHint.verify(sourceText);
for (const { evidence, message, line, col, rule } of results) {
context.report({
// @ts-expect-error -- it's fine
message: JSON.stringify({ evidence, message, rule }),
loc: {
line,
// ! eslint ast column is 0-indexed, but htmlhint is 1-indexed
column: col - 1
}
});
}
}
};
}
};
var rules = /*#__PURE__*/Object.freeze({
__proto__: null,
html: html
});
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
const htm = { meta: meta$1, rules };
const flatBase = {
name: "htm/flat-base",
files: ["**/*.html"],
plugins: { htm },
processor: eslintPluginUtils.jsonMessage,
languageOptions: { parser }
};
const flatRecommended = __spreadProps(__spreadValues({}, flatBase), {
name: "htm/flat-recommended",
rules: recommended.rules
});
const configs = __spreadProps(__spreadValues({}, configs_), {
flatBase,
flatRecommended
});
eslintPluginUtils.registerJsonMessageHandler("htm/html", ({ evidence, rule, message }) => {
var _a;
return {
ruleId: `htm/${rule.id}`,
message: `${message}
evidence: ${evidence}
reference: ${// istanbul ignore next
(_a = rule.link) != null ? _a : "-"}`
};
});
exports.configs = configs;
exports.meta = meta$1;
exports.parser = parser;
exports.rules = rules;
;