Skip to content

Conversation

@lilnasy
Copy link
Contributor

@lilnasy lilnasy commented Oct 27, 2025

  • eslint-plugin-vue depends on vue-eslint-parser to manage parsing and scopes.
  • We don't have a pluggable infra for parsing, so I created a generic interface for framework globals around the FrameworkOptions enum.
  • Rules can now call ctx.frameworks_options().has_global(name) to check if the effective framework provides a global variable by that name.
  • Provides a pipeline to address false positives and negatives in framework files without directly bringing in framework logic in vanilla rules.
  • Hopefully this is a good enough solution until there's a plan for handling parserOptions for linter milestone 2, which may touch on frameworks.
  • Closes linter: macros error no-undef #14987

Tasks

  • Framework: Vue
  • Framework: Svelte
  • Framework: Astro
  • Rule: no-undef
  • Rule: no-redeclare
  • Unit Tests
  • E2E Tests

@lilnasy lilnasy requested a review from camc314 as a code owner October 27, 2025 19:17
Copilot AI review requested due to automatic review settings October 27, 2025 19:17
@github-actions github-actions bot added A-linter Area - Linter C-enhancement Category - New feature or request labels Oct 27, 2025
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 introduces a generic interface for framework-provided globals, enabling the linter to recognize framework-specific identifiers (like Vue's defineProps or Svelte's $state) without requiring framework-specific parsing infrastructure. This prevents false positives in no-undef and no-redeclare rules when using framework compiler macros.

Key Changes:

  • Added FrameworkOptions enum variants for Svelte (Svelte, SvelteModule) and Astro (AstroFrontmatter) contexts
  • Implemented has_global() method to check if a variable is a framework-specific global
  • Updated no-undef and no-redeclare rules to recognize framework globals via ctx.frameworks_options().has_global()

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/oxc_linter/src/rules/eslint/no_undef.rs Added framework globals check to skip undefined variable errors
crates/oxc_linter/src/rules/eslint/no_redeclare.rs Extended built-in globals detection to include framework-provided globals
crates/oxc_linter/src/loader/partial_loader/svelte.rs Added detection of <script module> context and passes appropriate framework options
crates/oxc_linter/src/loader/partial_loader/astro.rs Updated to pass framework options (currently Default) for Astro frontmatter
crates/oxc_linter/src/frameworks.rs Defined framework-specific global arrays and implemented has_global() logic with comprehensive tests
Comments suppressed due to low confidence (1)

crates/oxc_linter/src/frameworks.rs:1

  • Comparing boolean expressions with == true or == false is redundant. Remove the explicit comparisons and use the boolean values directly: assert!(options.has_global(\"defineProps\")) and assert!(!options.has_global(\"console\")).
use std::{hash, path::Path};

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

@lilnasy lilnasy changed the title feat(linter): generic interface for framework-provided globals feat(linter): generic interface for Vue, Svelte, and Astro globals Oct 27, 2025
@lilnasy lilnasy force-pushed the feat/framework-globals branch from 11caf48 to 4239a7e Compare October 27, 2025 19:20
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 27, 2025

CodSpeed Performance Report

Merging #15005 will not alter performance

Comparing lilnasy:feat/framework-globals (d74a56d) with main (4904710)1

Summary

✅ 4 untouched
⏩ 33 skipped2

Footnotes

  1. No successful run was found on main (13060c8) during the generation of this report, so 4904710 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 33 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Contributor

@camc314 camc314 left a comment

Choose a reason for hiding this comment

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

Thank you for all your contributions and for looking at this, but I need to think about this more + possibly discuss with @ overlookmotel . I just worry about maintenance burden when we mix more and more different frameworks + different framework versions etc.

fyi, i'm OOO til wednesday, so probably won't get to this till towards the end of the week.

@lilnasy
Copy link
Contributor Author

lilnasy commented Oct 28, 2025

Thanks.

I realise that a more proper solution is possible here. It will definitely benefit from discussion with overlookmotel as it touches on whether the entire framework support needs to be abstracted differently for milestone 2.

I'm happy to help where I can.

@lilnasy lilnasy marked this pull request as draft October 28, 2025 06:02
@Sysix
Copy link
Member

Sysix commented Oct 28, 2025

Thank you for all the work ❤️

Some ideas:
I would love to see this in https://github.com/oxc-project/javascript-globals and be enabled via env.
Here was the original idea from: #11256

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linter: macros error no-undef

3 participants