UNPKG

eslint-plugin-vuoto

Version:

ESLint plugin for detecting and fixing whitespace issues - zero-width characters, non-breaking spaces, and Unicode normalization

36 lines (35 loc) 1.19 kB
import { LINE_SEPARATOR } from 'vuoto/consts'; const rule = { meta: { type: 'suggestion', docs: { description: String.raw `disallow line separator (U+2028) characters and replace with a standard newline (\n)`, recommended: true, }, fixable: 'code', schema: [], messages: { unexpected: String.raw `Unexpected line separator (U+2028) character. Use a standard newline (\n) instead.`, }, }, create(context) { const sourceCode = context.sourceCode; const text = sourceCode.text; return { Program() { let match; while ((match = LINE_SEPARATOR.exec(text)) !== null) { const index = match.index; context.report({ loc: sourceCode.getLocFromIndex(index), messageId: 'unexpected', fix(fixer) { return fixer.replaceTextRange([index, index + match[0].length], '\n'); }, }); } }, }; }, }; export default rule;