Skip to content

Commit d23e70e

Browse files
committed
Use ultra-strict mode for diff parser
1 parent 5b6b354 commit d23e70e

File tree

2 files changed

+341
-435
lines changed

2 files changed

+341
-435
lines changed

docusaurus/scripts/style-validation/github-diff-parser.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -270,17 +270,17 @@ class GitHubURLDiffParser {
270270
const line = lines[i];
271271

272272
if (line.startsWith('+')) {
273-
// Added line
273+
// Added line - ONLY track this
274274
result.addedLines.add(currentNewLine);
275-
this.addContextAroundLine(currentNewLine, result.contextLines);
275+
// REMOVED: this.addContextAroundLine(currentNewLine, result.contextLines);
276276
currentNewLine++;
277277
} else if (line.startsWith('-')) {
278278
// Deleted line
279279
result.deletedLines.add(currentOldLine);
280280
currentOldLine++;
281281
} else if (line.startsWith(' ') || line === '') {
282-
// Context line (unchanged)
283-
result.contextLines.add(currentNewLine);
282+
// Context line (unchanged) - DON'T track these anymore
283+
// REMOVED: result.contextLines.add(currentNewLine);
284284
currentNewLine++;
285285
currentOldLine++;
286286
}
@@ -302,7 +302,7 @@ class GitHubURLDiffParser {
302302
}
303303

304304
/**
305-
* Generate filtered content for validation
305+
* Generate filtered content for validation - STRICT MODE: Only changed lines
306306
*/
307307
generateFilteredContent(originalContent, diffInfo) {
308308
if (diffInfo.analyzeEntireFile || diffInfo.isNewFile) {
@@ -319,26 +319,31 @@ class GitHubURLDiffParser {
319319
changedLines: {
320320
added: diffInfo.addedLines,
321321
modified: diffInfo.modifiedLines,
322-
context: diffInfo.contextLines
322+
context: new Set() // No context for new files
323323
}
324324
};
325325
}
326326

327327
const lines = originalContent.split('\n');
328+
329+
// STRICT: Only include actually added/modified lines
328330
const linesToInclude = new Set([
329331
...diffInfo.addedLines,
330-
...diffInfo.modifiedLines,
331-
...diffInfo.contextLines
332+
...diffInfo.modifiedLines
333+
// REMOVED: ...diffInfo.contextLines
332334
]);
333335

334-
// Expand for contextual rules
335-
const expandedLines = this.expandForContextualRules(lines, linesToInclude);
336+
// REMOVED: Expansion for contextual rules
337+
// const expandedLines = this.expandForContextualRules(lines, linesToInclude);
336338

337339
const filteredLines = [];
338340
const lineMapping = {};
339341
let filteredLineNumber = 1;
340342

341-
expandedLines.forEach(originalLineNumber => {
343+
// Convert Set to sorted array
344+
const sortedLines = Array.from(linesToInclude).sort((a, b) => a - b);
345+
346+
sortedLines.forEach(originalLineNumber => {
342347
if (originalLineNumber > 0 && originalLineNumber <= lines.length) {
343348
filteredLines.push(lines[originalLineNumber - 1]);
344349
lineMapping[filteredLineNumber] = originalLineNumber;
@@ -352,7 +357,7 @@ class GitHubURLDiffParser {
352357
changedLines: {
353358
added: diffInfo.addedLines,
354359
modified: diffInfo.modifiedLines,
355-
context: diffInfo.contextLines
360+
context: new Set() // No context in strict mode
356361
}
357362
};
358363
}
@@ -403,4 +408,4 @@ class GitHubURLDiffParser {
403408
}
404409
}
405410

406-
module.exports = GitHubURLDiffParser;
411+
module.exports = GitHubURLDiffParser;

0 commit comments

Comments
 (0)