Skip to content

Commit

Permalink
fix: better comment template
Browse files Browse the repository at this point in the history
  • Loading branch information
undead404 committed Nov 23, 2023
1 parent 148de83 commit 4e3c954
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions scripts/send-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ const markdown = readFileSync(markdownFile, "utf8");

const markdownRunes = Array.from(markdown);

const MARKDOWN_ESCAPE_REGEX = /([!"#'()*+.[\\\]_`{}-])/g;

function escapeTextForMarkdown(text) {
return text.replaceAll(MARKDOWN_ESCAPE_REGEX, "\\$1");
}

function convertOffsetToLineAndColumn(offset) {
let line = 1;
let column = 1;
Expand All @@ -29,10 +35,17 @@ function convertOffsetToLineAndColumn(offset) {

// eslint-disable-next-line no-restricted-syntax
for (const match of results.matches) {
const { context, message, offset, replacements, rule, sentence } = match;
let { length } = match;
const { context, message, replacements, rule, sentence, shortMessage } =
match;
let { length, offset } = match;
let start;
length += 1;
while (!start) {
offset += 1;
length -= 1;
start = Number.parseInt(mapping[offset], 10);
}
let endOffset = offset + length;
const start = Number.parseInt(mapping[offset], 10);
let end;
endOffset -= 1;
length -= 1;
Expand All @@ -53,18 +66,29 @@ for (const match of results.matches) {
throw new Error(`Column not found in source file: ${sentence}`);
}
// const errorformatLine = `${markdownFile}:${startLine}:${startColumn}:${endLine}:${endColumn}: ${message}`;
let comment = `### ${message}\n${rule.description}\n${rule.category.id}/${rule.id}: ${rule.description}\n`;
let comment = "";
if (shortMessage || rule.description) {
comment += `### ${escapeTextForMarkdown(
shortMessage || rule.description,
)}\n\n`;
}
comment += `${escapeTextForMarkdown(message)}\n${rule.category.id}/${
rule.id
}: ${escapeTextForMarkdown(rule.description)}\n`;
// console.log(`\`${markdownFile}:${startLine}:${startColumn}\n\``);
comment += `> ${context.text.slice(0, context.offset)}**${context.text.slice(
context.offset,
context.offset + context.length,
)}**${context.text.slice(context.offset + context.length)}`;
comment += `> ${escapeTextForMarkdown(
context.text.slice(0, context.offset),
)}**${escapeTextForMarkdown(
context.text.slice(context.offset, context.offset + context.length),
)}**${escapeTextForMarkdown(
context.text.slice(context.offset + context.length),
)}`;
if (replacements?.length) {
comment += "\n\n#### Варіанти заміни\n";
// eslint-disable-next-line no-restricted-syntax
for (const replacement of replacements) {
// console.log(`- ${replacement.value}`);
comment += `- ${replacement.value}\n`;
comment += `- ${escapeTextForMarkdown(replacement.value)}\n`;
}
}
const parameters = {
Expand All @@ -87,6 +111,7 @@ for (const match of results.matches) {
: ` -f ${key}="${value}"`;
}
console.log(command);
// command = command.replaceAll("\n", "\\\n");
console.log(`GH_TOKEN=${process.env.GH_TOKEN} ${command}`);
execSync(command, { stdio: "inherit" });
}

0 comments on commit 4e3c954

Please sign in to comment.