MCPcopy Index your code
hub / github.com/promptfoo/promptfoo / clampCommentLines

Function clampCommentLines

src/codeScan/util/diffLineRanges.ts:240–294  ·  view source on GitHub ↗
(
  filepath: string,
  startLine: number | null | undefined,
  endLine: number | null | undefined,
  ranges: FileLineRanges,
)

Source from the content-addressed store, hash-verified

238 * @returns Clamped line numbers, or null if file not in diff
239 */
240export function clampCommentLines(
241 filepath: string,
242 startLine: number | null | undefined,
243 endLine: number | null | undefined,
244 ranges: FileLineRanges,
245): ClampedLines | null {
246 const fileRanges = ranges.get(filepath);
247 if (!fileRanges || fileRanges.length === 0 || endLine == null) {
248 return null;
249 }
250
251 // Clamp the end line
252 const clampedEndLine = clampToValidLine(filepath, endLine, ranges);
253 if (clampedEndLine === null) {
254 return null;
255 }
256
257 // If no start line, it's a single-line comment
258 if (startLine == null) {
259 return {
260 startLine: null,
261 line: clampedEndLine,
262 };
263 }
264
265 // Clamp the start line
266 const clampedStartLine = clampToValidLine(filepath, startLine, ranges);
267 if (clampedStartLine === null) {
268 return {
269 startLine: null,
270 line: clampedEndLine,
271 };
272 }
273
274 // Ensure start <= end (if start > end after clamping, make it single-line)
275 if (clampedStartLine > clampedEndLine) {
276 return {
277 startLine: null,
278 line: clampedEndLine,
279 };
280 }
281
282 // If start and end are the same, make it single-line
283 if (clampedStartLine === clampedEndLine) {
284 return {
285 startLine: null,
286 line: clampedEndLine,
287 };
288 }
289
290 return {
291 startLine: clampedStartLine,
292 line: clampedEndLine,
293 };
294}

Callers 2

clampCommentToValidRangeFunction · 0.90

Calls 2

clampToValidLineFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…