UNPKG

eslint-plugin-markup

Version:

An incredible ESLint plugin for all markup languages based on markuplint

50 lines 1.72 kB
import { sync } from '../sync.js'; export const markup = { 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({ message: JSON.stringify({ severity, message, ruleId }), loc: { line, column: col - 1, }, fix() { if (fixed++) { return null; } const { fixedCode } = runMarkuplint(true); return sourceText === fixedCode ? null : { range: [0, sourceText.length], text: fixedCode, }; }, }); } }, }; }, }; //# sourceMappingURL=markup.js.map