UNPKG

eslint-plugin-dtslint

Version:
78 lines (77 loc) 2.73 kB
"use strict"; const utils_1 = require("../utils"); const rule = (0, utils_1.ruleCreator)({ defaultOptions: [], meta: { docs: { description: "Forbids dtslint-like expectations that have typographical errors.", recommended: false, }, fixable: undefined, hasSuggestions: false, messages: { typo: "Typo in dtslint expectation.", }, schema: [], type: "problem", }, name: "no-typo", create: (context) => { return { Program: (node) => { const { comments } = node; if (!comments) { return; } comments.forEach((comment) => { if (comment.type !== "Line") { return; } const match = comment.value.match(/(\s*)(.+)$/); if (!match) { return; } const [, whitespace, expectation] = match; const commentTokenWidth = 2; const loc = { ...comment.loc, start: { ...comment.loc.start, column: comment.loc.start.column + commentTokenWidth + whitespace.length, }, }; if (/^(\$\s+)?Expect/.test(expectation)) { context.report({ loc, messageId: "typo", }); return; } if (!/^\$Expect/.test(expectation)) { return; } if (!/^\$Expect(Type\s*|Error\s*$|Deprecation\s*$|NoDeprecation\s*$)/.test(expectation)) { context.report({ loc, messageId: "typo", }); return; } if (!/^\$ExpectType/.test(expectation)) { return; } if (!/^\$ExpectType\s+[^\s]/.test(expectation)) { context.report({ loc, messageId: "typo", }); return; } }); }, }; }, }); module.exports = rule;