From 28df1604bfebd9f56acdf1649e8f4de21930b81a Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Wed, 28 Jan 2026 02:04:25 +0000 Subject: [PATCH] fix(linter/plugins): allow line number passed to `report` to be 0 (#18642) Similar to #18341. Loosen checks for `loc` passed to `report()`. Allow `line` to 0, if `column` is 0. In this case, treat it offset 0. `eslint-plugin-sonarjs` reports errors with `loc` like this. --- apps/oxlint/src-js/plugins/report.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/oxlint/src-js/plugins/report.ts b/apps/oxlint/src-js/plugins/report.ts index ef5c4bfd37df8..a82af176ceecf 100644 --- a/apps/oxlint/src-js/plugins/report.ts +++ b/apps/oxlint/src-js/plugins/report.ts @@ -291,8 +291,13 @@ function getOffsetFromLineColumn(lineCol: LineColumn): number { debugAssertLinesIsInitialized(); if (line <= 0 || line > lineStartIndices.length) { - // Allow `line` to be 1 greater than the number of lines in the file if `column` is 0 - if (line === lineStartIndices.length + 1 && column === 0) return sourceText.length; + if (column === 0) { + // Allow `line` to be 0 if `column` is 0 + if (line === 0) return 0; + + // Allow `line` to be 1 greater than the number of lines in the file if `column` is 0 + if (line === lineStartIndices.length + 1) return sourceText.length; + } throw new RangeError( `Line number out of range (line ${line} requested). ` +