Skip to content

feat(eslint-config): add no-page-meta-runtime-values#641

Merged
antfu merged 5 commits intomainfrom
feat/define-page-meta
Feb 7, 2026
Merged

feat(eslint-config): add no-page-meta-runtime-values#641
antfu merged 5 commits intomainfrom
feat/define-page-meta

Conversation

@danielroe
Copy link
Member

🔗 Linked issue

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

this adds a new eslint rule to help catch some edge cases with definePageMeta. we can probably extend this further, and I'm a bit wary about hard coding use* as something to avoid but 🤷

@danielroe danielroe self-assigned this Feb 6, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 6, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Adds a new ESLint rule no-page-meta-runtime-values that forbids runtime Vue/Nuxt context values and certain composable usages inside definePageMeta at the eager level. Implements the rule logic, exports it from the plugin, and registers it in the rules index. Adds a comprehensive test suite covering many valid and invalid scenarios. Updates the Nuxt ESLint configuration to include a nuxt/pages files entry enforcing the rule when pages are present. Also updates two dependency versions in pnpm-workspace.yaml.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(eslint-config): add no-page-meta-runtime-values' clearly and specifically describes the main change: adding a new ESLint rule.
Description check ✅ Passed The description is related to the changeset, explaining the purpose of the new rule for catching edge cases with definePageMeta.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/define-page-meta

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/eslint-plugin/src/rules/no-page-meta-runtime-values/index.ts`:
- Around line 17-51: The CONTEXT_APIS set used to mark APIs that require an
active component instance is missing 'provide'; add the string 'provide' to the
existing Set (alongside 'inject' and other Vue APIs) in the CONTEXT_APIS
declaration so that provide is treated as a runtime-only/context API by the
no-page-meta-runtime-values rule.
🧹 Nitpick comments (2)
packages/eslint-config/src/configs/nuxt.ts (1)

53-55: Nit: pages glob is duplicated from fileSingleRoot (Line 14).

The expression dirs.pages?.map(pagesDir => join(pagesDir, \**/*.${GLOB_EXTS}`)) || []` appears identically in both places. You could extract it into a shared variable to avoid the repetition.

Possible refactor
+ const filePages = (dirs.pages?.map(pagesDir => join(pagesDir, `**/*.${GLOB_EXTS}`)) || []).sort()
+
  const fileSingleRoot = [
    ...(dirs.layouts?.map(layoutsDir => join(layoutsDir, `**/*.${GLOB_EXTS}`)) || []),
-   ...(dirs.pages?.map(pagesDir => join(pagesDir, `**/*.${GLOB_EXTS}`)) || []),
+   ...filePages,
    ...(dirs.components?.map(componentsDir => join(componentsDir, `**/*.server.${GLOB_EXTS}`)) || []),
  ].sort()
- const filePages = [
-   ...(dirs.pages?.map(pagesDir => join(pagesDir, `**/*.${GLOB_EXTS}`)) || []),
- ].sort()
-
  if (filePages.length) {
packages/eslint-plugin/test/no-page-meta-runtime-values.test.ts (1)

66-137: Consider adding a valid test for object method shorthand.

The valid cases cover arrow functions and function expressions, but not the common method shorthand syntax. Since method shorthand desugars to a FunctionExpression, the rule should handle it, but an explicit test documents that intent.

// Composable inside method shorthand is fine (depth >= 1)
{
  code: `
    definePageMeta({
      middleware() {
        const route = useRoute()
        return route.path === '/'
      }
    })
  `,
},

Comment on lines +17 to +51
const CONTEXT_APIS = new Set([
// Vue reactivity (require active effect scope)
'ref',
'shallowRef',
'customRef',
'computed',
'reactive',
'shallowReactive',
'readonly',
'shallowReadonly',
'toRef',
'toRefs',
'watch',
'watchEffect',
'watchPostEffect',
'watchSyncEffect',
'effectScope',
'onScopeDispose',
// Vue lifecycle hooks
'onBeforeMount',
'onMounted',
'onBeforeUpdate',
'onUpdated',
'onBeforeUnmount',
'onUnmounted',
'onActivated',
'onDeactivated',
'onErrorCaptured',
'onRenderTracked',
'onRenderTriggered',
'onServerPrefetch',
// Vue component context
'inject',
'getCurrentInstance',
])
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

provide is missing from CONTEXT_APIS.

provide (counterpart to inject) also requires an active component instance — Vue docs state it can only be called during setup(). Since inject is included on Line 49, provide should be here too for completeness.

Suggested fix
   // Vue component context
   'inject',
+  'provide',
   'getCurrentInstance',
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const CONTEXT_APIS = new Set([
// Vue reactivity (require active effect scope)
'ref',
'shallowRef',
'customRef',
'computed',
'reactive',
'shallowReactive',
'readonly',
'shallowReadonly',
'toRef',
'toRefs',
'watch',
'watchEffect',
'watchPostEffect',
'watchSyncEffect',
'effectScope',
'onScopeDispose',
// Vue lifecycle hooks
'onBeforeMount',
'onMounted',
'onBeforeUpdate',
'onUpdated',
'onBeforeUnmount',
'onUnmounted',
'onActivated',
'onDeactivated',
'onErrorCaptured',
'onRenderTracked',
'onRenderTriggered',
'onServerPrefetch',
// Vue component context
'inject',
'getCurrentInstance',
])
const CONTEXT_APIS = new Set([
// Vue reactivity (require active effect scope)
'ref',
'shallowRef',
'customRef',
'computed',
'reactive',
'shallowReactive',
'readonly',
'shallowReadonly',
'toRef',
'toRefs',
'watch',
'watchEffect',
'watchPostEffect',
'watchSyncEffect',
'effectScope',
'onScopeDispose',
// Vue lifecycle hooks
'onBeforeMount',
'onMounted',
'onBeforeUpdate',
'onUpdated',
'onBeforeUnmount',
'onUnmounted',
'onActivated',
'onDeactivated',
'onErrorCaptured',
'onRenderTracked',
'onRenderTriggered',
'onServerPrefetch',
// Vue component context
'inject',
'provide',
'getCurrentInstance',
])
🤖 Prompt for AI Agents
In `@packages/eslint-plugin/src/rules/no-page-meta-runtime-values/index.ts` around
lines 17 - 51, The CONTEXT_APIS set used to mark APIs that require an active
component instance is missing 'provide'; add the string 'provide' to the
existing Set (alongside 'inject' and other Vue APIs) in the CONTEXT_APIS
declaration so that provide is treated as a runtime-only/context API by the
no-page-meta-runtime-values rule.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 7, 2026

Deploying nuxt-eslint with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9aa30bb
Status:🚫  Build failed.

View logs

@antfu antfu merged commit b74a0a9 into main Feb 7, 2026
7 of 8 checks passed
@antfu antfu deleted the feat/define-page-meta branch February 7, 2026 07:53
This was referenced Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants