Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Oct 2, 2025

WIP. Need to add tests and refactor.

Implement sourceCode.getIndexFromLoc API, using the lines array added in #14290.

@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI C-enhancement Category - New feature or request labels Oct 2, 2025
Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@overlookmotel overlookmotel marked this pull request as ready for review October 2, 2025 11:07
@overlookmotel overlookmotel requested a review from camc314 as a code owner October 2, 2025 11:07
Copilot AI review requested due to automatic review settings October 2, 2025 11:07
@overlookmotel overlookmotel marked this pull request as draft October 2, 2025 11:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements the sourceCode.getIndexFromLoc method that converts line/column positions to character indices in the source text. The implementation uses the lines array infrastructure added in a previous PR.

  • Implements complete getIndexFromLoc method with input validation and edge case handling
  • Optimizes initLines function by adding early return guard to prevent redundant initialization
  • Replaces explicit length check with direct initLines() call in lines getter

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

*/

let lineEndOffset;
if (line === linesCount) {
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing null check for sourceText. The code calls initLines() which may call initSourceText(), but there's no guarantee that sourceText is not null at this point. Add a null check or ensure sourceText is properly initialized.

Suggested change
if (line === linesCount) {
if (line === linesCount) {
if (sourceText == null) {
throw new TypeError("sourceText is null or undefined when accessing its length.");
}

Copilot uses AI. Check for mistakes.
if (line === linesCount) {
lineEndOffset = sourceText.length;
if (offset <= lineEndOffset) return offset;
} else {
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential array bounds error. The code accesses lineStartOffsets[line] where line could equal linesCount, but lineStartOffsets may only have linesCount elements (0-indexed). This could cause an out-of-bounds access when line === linesCount.

Suggested change
} else {
} else {
// line is guaranteed to be < linesCount here, so lineStartOffsets[line] is in bounds
console.assert(line < linesCount, "lineStartOffsets[line] out of bounds");

Copilot uses AI. Check for mistakes.
@overlookmotel
Copy link
Member Author

Superceded by #14303.

@overlookmotel overlookmotel deleted the 10-02-feat_linter_plugins_implement_sourcecode_getindexfromloc_method branch October 2, 2025 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-linter Area - Linter C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants