UNPKG

eslint-plugin-text

Version:

An incredible ESLint plugin for retext or textlint

55 lines 2.02 kB
import { lint } from '../sync.js'; export const retext = { meta: { type: 'problem', fixable: 'code', messages: {}, schema: [], }, defaultOptions: [], create(context) { const sourceText = context.sourceCode.text; return { Program(node) { const { messages, content: fixedText } = lint({ text: sourceText, filename: context.filename, linter: 'retext', fix: true, }); let fixed = 0; for (const { reason, ruleId, fatal, line, column, place } of messages) { const severity = fatal ? 2 : fatal == null ? 0 : 1; if (!severity) { continue; } const message = { message: reason, ruleId: ruleId, severity, }; const pos = place && 'start' in place ? place : undefined; context.report({ message: JSON.stringify(message), loc: pos ? { start: { ...pos.start, column: pos.start.column - 1 }, end: { ...pos.end, column: pos.end.column - 1 }, } : { line: line, column: column - 1 }, node, fix: fixedText === sourceText ? null : () => fixed++ ? null : { range: [0, sourceText.length], text: fixedText, }, }); } }, }; }, }; //# sourceMappingURL=retext.js.map