in src/provider/linter.ts [40:72]
export function searchCode(
diagnosticCollection: vscode.Diagnostic[],
rule: Rule,
text: string,
document: vscode.TextDocument,
) {
const regex = new RegExp(rule.pattern, "gi");
const strRegex = new RegExp(`[\'\"\`](.*?)[\'\"\`]`, "gi");
let strMatch;
let matchTexts = [];
while ((strMatch = strRegex.exec(text)) !== null) {
const range = new vscode.Range(document.positionAt(strMatch.index), document.positionAt(strRegex.lastIndex));
const matchText = document.getText(range);
const pureString = matchText.substring(1, matchText.length - 1);
const isMatch = rule?.length
? regex.test(pureString) && pureString?.length === rule.length
: regex.test(pureString);
if (isMatch) {
matchTexts.push(pureString);
diagnosticCollection.push({
code: "",
message: rule.message,
range: range,
severity: vscode.DiagnosticSeverity.Error,
source: rule.source,
relatedInformation: [
new vscode.DiagnosticRelatedInformation(new vscode.Location(document.uri, range), rule.information),
],
});
}
}
return matchTexts;
}