-
Notifications
You must be signed in to change notification settings - Fork 1
feat(tools): Add alignment clause drift detector (B-0058.4) #5871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
55e7662
feat(tools): Add alignment clause drift detector (B-0058.4)
0dd7668
feat(tools): Add tests for detect-clause-drift script
2f7207d
Merge remote-tracking branch 'origin/main' into HEAD
62dd5d9
fix(B-0058.4): strict-null safety + bun:test import for drift detector
6896b38
fix(B-0058.4): address 19 Copilot findings in detect-clause-drift
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
|
AceHack marked this conversation as resolved.
Outdated
|
||
|
|
||
|
AceHack marked this conversation as resolved.
Outdated
|
||
| const CLAUSE_REGEX = /(HC-[0-9]+|SD-[0-9]+|DIR-[0-9]+)/g; | ||
|
AceHack marked this conversation as resolved.
Outdated
AceHack marked this conversation as resolved.
Outdated
|
||
| const IGNORE_DIRS = ['node_modules', '.git', '.vscode', '.idea', 'dist', 'build']; | ||
| const IGNORE_EXTS = ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', '.pdf', '.zip', '.gz', '.tar', '.DS_Store']; | ||
|
AceHack marked this conversation as resolved.
Outdated
AceHack marked this conversation as resolved.
Outdated
AceHack marked this conversation as resolved.
Outdated
|
||
|
|
||
| interface Match { | ||
| file: string; | ||
| line: number; | ||
| clause: string; | ||
| text: string; | ||
| } | ||
|
|
||
| function searchInFile(filePath: string): Match[] { | ||
| const matches: Match[] = []; | ||
| if (IGNORE_EXTS.some(ext => filePath.endsWith(ext))) { | ||
| return matches; | ||
| } | ||
|
|
||
| try { | ||
| const content = fs.readFileSync(filePath, 'utf-8'); | ||
| const lines = content.split('\n'); | ||
|
|
||
| for (let i = 0; i < lines.length; i++) { | ||
| const line = lines[i]; | ||
| let match; | ||
| while ((match = CLAUSE_REGEX.exec(line)) !== null) { | ||
| matches.push({ | ||
| file: filePath, | ||
| line: i + 1, | ||
| clause: match[0], | ||
| text: line.trim(), | ||
| }); | ||
| } | ||
| } | ||
|
AceHack marked this conversation as resolved.
Outdated
|
||
| } catch (error) { | ||
| // Ignore errors from reading binary files etc. | ||
| } | ||
|
|
||
| return matches; | ||
| } | ||
|
|
||
| function searchInDirectory(dirPath: string): Match[] { | ||
| let allMatches: Match[] = []; | ||
| const entries = fs.readdirSync(dirPath, { withFileTypes: true }); | ||
|
|
||
| for (const entry of entries) { | ||
| const fullPath = path.join(dirPath, entry.name); | ||
| if (IGNORE_DIRS.includes(entry.name)) { | ||
| continue; | ||
| } | ||
|
|
||
| if (entry.isDirectory()) { | ||
| allMatches = allMatches.concat(searchInDirectory(fullPath)); | ||
| } else if (entry.isFile()) { | ||
| allMatches = allMatches.concat(searchInFile(fullPath)); | ||
| } | ||
| } | ||
|
|
||
| return allMatches; | ||
| } | ||
|
|
||
| function main() { | ||
| const searchDir = process.cwd(); | ||
| console.log(`Searching for alignment clause references in ${searchDir}... | ||
|
AceHack marked this conversation as resolved.
Outdated
|
||
| `); | ||
|
AceHack marked this conversation as resolved.
Outdated
|
||
|
|
||
|
AceHack marked this conversation as resolved.
Outdated
|
||
| const allMatches = searchInDirectory(searchDir); | ||
|
|
||
| const targetClause = process.argv[2]; | ||
|
|
||
|
AceHack marked this conversation as resolved.
Outdated
|
||
| const filteredMatches = targetClause | ||
| ? allMatches.filter(m => m.clause.toUpperCase() === targetClause.toUpperCase()) | ||
| : allMatches; | ||
|
|
||
| if (filteredMatches.length === 0) { | ||
| console.log('No alignment clause references found.'); | ||
| return; | ||
| } | ||
|
|
||
| const groupedByClause: { [key: string]: Match[] } = {}; | ||
| for (const match of filteredMatches) { | ||
| if (!groupedByClause[match.clause]) { | ||
| groupedByClause[match.clause] = []; | ||
| } | ||
| groupedByClause[match.clause].push(match); | ||
| } | ||
|
|
||
| for (const clause in groupedByClause) { | ||
| console.log(` | ||
| --- Found ${groupedByClause[clause].length} references to ${clause} --- | ||
| `); | ||
| for (const match of groupedByClause[clause]) { | ||
| console.log(`${match.file}:${match.line} - ${match.text}`); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| main(); | ||
|
AceHack marked this conversation as resolved.
Outdated
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.