-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PromptString linter: Only error when the reported violation is within…
… one of the changed range (#3810)
- Loading branch information
1 parent
acde6c8
commit ac5fae2
Showing
3 changed files
with
86 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,51 @@ | ||
import { exec } from 'node:child_process' | ||
|
||
const EXTENSIONS = ['ts', 'tsx'] | ||
|
||
exec('git diff --unified=0 origin/main', (error, stdout, stderr) => { | ||
if (error) { | ||
console.error(`exec error: ${error}`) | ||
return | ||
} | ||
if (stderr) { | ||
console.error(`stderr: ${stderr}`) | ||
return | ||
} | ||
|
||
// Process the output | ||
const lines = stdout.split('\n') | ||
let currentFile = '' | ||
const fileRanges: { [key: string]: string[] } = {} | ||
|
||
for (const line of lines) { | ||
if (line.startsWith('diff --git')) { | ||
// Extract the filename correctly after the b/ prefix | ||
const parts = line.split(' ') | ||
currentFile = parts[2].substring(2) // Remove the 'b/' prefix | ||
} else if (line.startsWith('@@')) { | ||
// Extract the line numbers for additions | ||
const match = line.match(/\+([0-9]+),?([0-9]*)/) | ||
if (match) { | ||
const start = parseInt(match[1], 10) | ||
const count = parseInt(match[2] || '1', 10) | ||
const end = start + count - 1 | ||
if (count > 0) { | ||
// Ensure we only add ranges where lines were added | ||
if (!fileRanges[currentFile]) { | ||
fileRanges[currentFile] = [] | ||
} | ||
fileRanges[currentFile].push(`${start}-${end}`) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Output the results | ||
for (const [file, ranges] of Object.entries(fileRanges)) { | ||
if (!EXTENSIONS.includes(file.split('.').pop() || '')) { | ||
continue | ||
} | ||
|
||
console.log(`${file}:${ranges.join(',')}`) | ||
} | ||
}) |
This file contains 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