Fix code quality issues from Copilot review
- Remove duplicated code block (lines 292-304) in check-md-conformance.js - Remove unused variable fenceStartLine in check-md-conformance.js - Remove unused variable hasLanguage in fix-fence-languages.js - Rename fixOpenTicks to fixOpenLine to store full original line
This commit is contained in:
parent
08ac1c1cf3
commit
a953439f08
|
|
@ -80,7 +80,6 @@ function checkFile(filePath) {
|
||||||
const violations = [];
|
const violations = [];
|
||||||
|
|
||||||
let inFence = false;
|
let inFence = false;
|
||||||
let fenceStartLine = -1;
|
|
||||||
|
|
||||||
// Pass 1: fence tracking to avoid interpreting list/table inside code blocks
|
// Pass 1: fence tracking to avoid interpreting list/table inside code blocks
|
||||||
const excluded = Array.from({ length: lines.length }).fill(false);
|
const excluded = Array.from({ length: lines.length }).fill(false);
|
||||||
|
|
@ -89,10 +88,8 @@ function checkFile(filePath) {
|
||||||
if (inFence) {
|
if (inFence) {
|
||||||
// closing fence
|
// closing fence
|
||||||
inFence = false;
|
inFence = false;
|
||||||
fenceStartLine = -1;
|
|
||||||
} else {
|
} else {
|
||||||
inFence = true;
|
inFence = true;
|
||||||
fenceStartLine = i;
|
|
||||||
}
|
}
|
||||||
excluded[i] = true;
|
excluded[i] = true;
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -289,16 +286,3 @@ if (require.main === module) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { checkFile };
|
module.exports = { checkFile };
|
||||||
{
|
|
||||||
console.log(`\n- ${path.relative(process.cwd(), file)}`);
|
|
||||||
for (const v of violations) {
|
|
||||||
console.log(` L${v.line.toString().padStart(4, ' ')} ${v.type} ${v.message}`);
|
|
||||||
}
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (require.main === module) {
|
|
||||||
main();
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = { checkFile };
|
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ function fixFile(filePath) {
|
||||||
let fixing = false;
|
let fixing = false;
|
||||||
let fixFenceStart = -1;
|
let fixFenceStart = -1;
|
||||||
let fixOpenIndent = '';
|
let fixOpenIndent = '';
|
||||||
let fixOpenTicks = '';
|
let fixOpenLine = '';
|
||||||
let fixOpenLen = 0;
|
let fixOpenLen = 0;
|
||||||
let fenceContent = [];
|
let fenceContent = [];
|
||||||
|
|
||||||
|
|
@ -117,7 +117,7 @@ function fixFile(filePath) {
|
||||||
|
|
||||||
fixes.push({
|
fixes.push({
|
||||||
line: fixFenceStart + 1,
|
line: fixFenceStart + 1,
|
||||||
original: fixOpenTicks,
|
original: fixOpenLine,
|
||||||
fixed: fixedOpenLine,
|
fixed: fixedOpenLine,
|
||||||
detectedLanguage: language,
|
detectedLanguage: language,
|
||||||
contentPreview: fenceContent.slice(0, 2).join('\n').slice(0, 60) + '...',
|
contentPreview: fenceContent.slice(0, 2).join('\n').slice(0, 60) + '...',
|
||||||
|
|
@ -127,7 +127,7 @@ function fixFile(filePath) {
|
||||||
fixing = false;
|
fixing = false;
|
||||||
fixFenceStart = -1;
|
fixFenceStart = -1;
|
||||||
fixOpenIndent = '';
|
fixOpenIndent = '';
|
||||||
fixOpenTicks = '';
|
fixOpenLine = '';
|
||||||
fixOpenLen = 0;
|
fixOpenLen = 0;
|
||||||
fenceContent = [];
|
fenceContent = [];
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -146,7 +146,6 @@ function fixFile(filePath) {
|
||||||
const ticksLen = ticks.length;
|
const ticksLen = ticks.length;
|
||||||
const rest = fenceLineMatch[3] || '';
|
const rest = fenceLineMatch[3] || '';
|
||||||
const restTrim = rest.trim();
|
const restTrim = rest.trim();
|
||||||
const hasLanguage = restTrim.length > 0; // simplistic but effective for our cases
|
|
||||||
|
|
||||||
// Determine if this is a closing fence for the current outer fence
|
// Determine if this is a closing fence for the current outer fence
|
||||||
if (fenceStack.length > 0) {
|
if (fenceStack.length > 0) {
|
||||||
|
|
@ -173,7 +172,7 @@ function fixFile(filePath) {
|
||||||
fixing = true;
|
fixing = true;
|
||||||
fixFenceStart = i;
|
fixFenceStart = i;
|
||||||
fixOpenIndent = indent;
|
fixOpenIndent = indent;
|
||||||
fixOpenTicks = ticks;
|
fixOpenLine = line;
|
||||||
fixOpenLen = ticksLen;
|
fixOpenLen = ticksLen;
|
||||||
fenceContent = [];
|
fenceContent = [];
|
||||||
// Do not push the original opening line; we'll emit the fixed one at close
|
// Do not push the original opening line; we'll emit the fixed one at close
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue