eslint-plugin-markup
Version:
An incredible ESLint plugin for all markup languages based on markuplint
210 lines (196 loc) • 5.89 kB
JavaScript
var eslintPluginUtils = require('eslint-plugin-utils');
var path = require('node:path');
var core = require('@pkgr/core');
var node_url = require('node:url');
var synckit = require('synckit');
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-markup",
plugins: ["markup", "utils"],
processor: "utils/jsonMessage"
};
const recommended = __spreadProps$1(__spreadValues$1({}, base), {
rules: {
"markup/markup": 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 _dirname = path.dirname(_filename);
const { name, version } = core.cjsRequire(
path.resolve(_dirname, "../package.json")
);
var meta$1 = /*#__PURE__*/Object.freeze({
__proto__: null,
name: name,
version: version
});
const meta = {
name: "markup-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 workerPath = path.resolve(_dirname, "./worker.js");
const sync = {
get markuplintSync() {
return synckit.createSyncFn(workerPath);
}
};
const markup$1 = {
meta: {
fixable: "code",
type: "problem",
messages: {},
schema: []
},
defaultOptions: [],
create(context) {
const filename = context.filename;
const sourceText = context.sourceCode.text;
const markuplintOptions = {
sourceCode: sourceText,
name: filename
};
const runMarkuplint = (fix) => sync.markuplintSync(markuplintOptions, fix);
return {
Program() {
const { violations } = runMarkuplint();
if (violations.length === 0) {
return;
}
let fixed = 0;
for (const { ruleId, severity, message, line, col } of violations) {
context.report({
// @ts-expect-error -- it's fine
message: JSON.stringify({ severity, message, ruleId }),
loc: {
line,
// ! eslint ast column is 0-indexed, but markuplint is 1-indexed
column: col - 1
},
fix() {
if (fixed++) {
return null;
}
const { fixedCode } = runMarkuplint(true);
return sourceText === fixedCode ? null : {
range: [0, sourceText.length],
text: fixedCode
};
}
});
}
}
};
}
};
var rules = /*#__PURE__*/Object.freeze({
__proto__: null,
markup: markup$1
});
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 markup = { meta: meta$1, rules };
const flatBase = {
name: "markup/flat-base",
files: ["**/*.html"],
plugins: { markup },
processor: eslintPluginUtils.jsonMessage,
languageOptions: { parser }
};
const flatRecommended = __spreadProps(__spreadValues({}, flatBase), {
name: "markup/flat-recommended",
rules: recommended.rules
});
const configs = __spreadProps(__spreadValues({}, configs_), {
flatBase,
flatRecommended
});
const SEVERITIES = ["info", "warning", "error"];
eslintPluginUtils.registerJsonMessageHandler(
"markup/markup",
({ ruleId, severity, message }, { severity: eslintSeverity }) => ({
ruleId: `markup/${ruleId}`,
message,
severity: Math.max(
eslintSeverity,
SEVERITIES.indexOf(severity)
)
})
);
exports.configs = configs;
exports.meta = meta$1;
exports.parser = parser;
exports.rules = rules;
;