Skip to content

fix(linter/plugins): report() accept loc with no end#16859

Merged
graphite-app[bot] merged 1 commit intomainfrom
12-14-fix_linter_plugins_report_accept_loc_with_no_end_
Dec 14, 2025
Merged

fix(linter/plugins): report() accept loc with no end#16859
graphite-app[bot] merged 1 commit intomainfrom
12-14-fix_linter_plugins_report_accept_loc_with_no_end_

Conversation

@overlookmotel
Copy link
Copy Markdown
Member

@overlookmotel overlookmotel commented Dec 14, 2025

Make Context#report accept multiple formats for loc property. These are all legal in ESLint:

{ start: { line, column }, end: { line, column } }
{ start: { line, column }, end: null }
{ start: { line, column }, end: undefined }
{ start: { line, column } }
{ line, column }

@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI A-linter-plugins Area - Linter JS plugins C-bug Category - Bug labels Dec 14, 2025
Copy link
Copy Markdown
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 December 14, 2025 21:00
Copilot AI review requested due to automatic review settings December 14, 2025 21:00
Copy link
Copy Markdown

@charliecreates charliecreates bot left a comment

Choose a reason for hiding this comment

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

The main risk is that report() currently treats any object with a start property as a valid location and may fail later with less actionable errors; adding lightweight shape validation would improve debuggability and robustness. Separately, endLine?: number | undefined / endColumn?: number | undefined is redundant and adds API noise; the meaningful behavior is driven by hasOwn checks rather than the type itself.

Additional notes (1)
  • Readability | apps/oxlint/src-js/package/rule_tester.ts:250-255
    ErrorBase.endLine?: number | undefined and endColumn?: number | undefined are semantically redundant: an optional property already implies it may be undefined. The real behavioral change here comes from the hasOwn(error, "endLine") checks, not the type.

If the intent is to encourage authors to explicitly include endLine: undefined in test cases, the type change doesn’t add much but does add noise to the public test-case interface. Consider keeping the simpler type and documenting the hasOwn behavior (or provide a dedicated sentinel/flag) so the API stays clean.

Summary of changes

Summary of changes

This PR updates JS-side lint reporting and tests to better match ESLint’s accepted loc shapes for Context#report().

  • apps/oxlint/src-js/plugins/report.ts

    • Expands DiagnosticBase.loc to accept either:
      • a { start, end? } shape where end may be omitted/null/undefined (LocationWithOptionalEnd), or
      • a shorthand { line, column } (LineColumn).
    • Updates report() to normalize these inputs into start/end offsets, defaulting end to start when missing.
    • Adds runtime narrowing via typeAssertIs for the supported shapes.
  • apps/oxlint/src-js/package/rule_tester.ts

    • Allows endLine/endColumn to be explicitly undefined.
    • Adjusts location assertions in ESLint compat mode so tests can expect end* to be undefined when loc was provided as { line, column } and oxlint internally sets end === start.
  • Conformance snapshots updated accordingly (apps/oxlint/conformance/snapshot.md).

Copy link
Copy Markdown
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 enhances the Context#report() function to accept multiple formats for the loc property, matching ESLint's flexible API. Previously, loc required both start and end properties with LineColumn objects. Now it accepts five different formats: full location with start and end, start with null/undefined end, start only, or a plain line/column pair.

Key Changes

  • Updated type definitions to allow LocationWithOptionalEnd | LineColumn for the loc property
  • Added logic to handle loc formats with optional or missing end coordinates
  • Enhanced rule tester to properly validate test cases in ESLint compatibility mode when endLine/endColumn are undefined

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
apps/oxlint/src-js/plugins/report.ts Added LocationWithOptionalEnd interface and updated report() to handle five different loc formats with appropriate branching logic
apps/oxlint/src-js/package/rule_tester.ts Updated ErrorBase interface and assertInvalidTestCaseLocationIsCorrect() to handle endLine/endColumn being explicitly undefined in ESLint compat mode

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@overlookmotel overlookmotel self-assigned this Dec 14, 2025
@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Dec 14, 2025
Copy link
Copy Markdown
Member Author

overlookmotel commented Dec 14, 2025

Merge activity

Make `Context#report` accept multiple formats for `loc` property. These are all legal in ESLint:

```
{ start: { line, column }, end: { line, column } }
{ start: { line, column }, end: null }
{ start: { line, column }, end: undefined }
{ start: { line, column } }
{ line, column }
```
@graphite-app graphite-app bot force-pushed the 12-14-fix_linter_plugins_report_accept_loc_with_no_end_ branch from 82cbdb6 to eccffcf Compare December 14, 2025 21:19
@graphite-app graphite-app bot merged commit eccffcf into main Dec 14, 2025
18 checks passed
@graphite-app graphite-app bot deleted the 12-14-fix_linter_plugins_report_accept_loc_with_no_end_ branch December 14, 2025 21:25
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 14, 2025
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 A-linter-plugins Area - Linter JS plugins C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants