UNPKG

@vrcd-community/zhlint

Version:

A linting tool for Chinese language.

27 lines (26 loc) 826 B
const ignoredCaseMatcher = /^(?:(?<prefix>.+?)-,)?(?<textStart>.+?)(?:,(?<textEnd>.+?))?(?:,-(?<suffix>.+?))?$/; export const parseIngoredCase = (text) => { const matchResult = text.match(ignoredCaseMatcher); if (matchResult) { const { prefix, textStart, textEnd, suffix } = matchResult.groups; return { prefix, textStart, textEnd, suffix }; } }; const parser = (data) => { const { ignoredByRules, value: raw } = data; const matcher = /<!--\s*zhlint\s*ignore:\s*(.+?)\s*-->/g; let result; while ((result = matcher.exec(raw)) !== null) { const ignoredCase = parseIngoredCase(result[1]); if (ignoredCase) { ignoredByRules.push(ignoredCase); } } return data; }; export default parser;