Adds a custom ESLint rule (local-rules/require-v2-layout-meta) that
fails any src/pages-v2/**.vue page missing
definePage({ meta: { layout: 'OrganizerLayoutV2' } }) (or PortalLayoutV2
under pages-v2/portal), preventing a silent wrong-shell fallback to the
default layout (RFC-WS-GUI-REDESIGN AD-G2). Wires eslint-plugin-local-rules
+ a pages-v2 override. The RuleTester spec is called at top level (ESLint
RuleTester self-manages describe/it under Vitest) and vitest.config.ts
gains the eslint-rules test glob so the spec is discovered.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
60 lines
1.9 KiB
JavaScript
60 lines
1.9 KiB
JavaScript
/**
|
|
* Enforces that every src/pages-v2/**.vue page declares
|
|
* definePage({ meta: { layout: 'OrganizerLayoutV2' } })
|
|
* (or 'PortalLayoutV2' for src/pages-v2/portal/**). Without this a v2
|
|
* page silently falls back to the `default` layout — a no-error
|
|
* wrong-shell bug. RFC-WS-GUI-REDESIGN AD-G2.
|
|
*/
|
|
'use strict'
|
|
|
|
module.exports = {
|
|
meta: {
|
|
type: 'problem',
|
|
docs: { description: 'require definePage layout meta on pages-v2' },
|
|
messages: {
|
|
missing: 'pages-v2 page must call definePage({ meta: { layout: ... } }).',
|
|
wrongLayout: 'pages-v2 layout must be {{expected}} (got {{actual}}).',
|
|
},
|
|
schema: [],
|
|
},
|
|
create(context) {
|
|
const filename = (context.filename || context.getFilename() || '').replace(/\\/g, '/')
|
|
if (!filename.includes('src/pages-v2/'))
|
|
return {}
|
|
|
|
const expected = filename.includes('src/pages-v2/portal/')
|
|
? 'PortalLayoutV2'
|
|
: 'OrganizerLayoutV2'
|
|
|
|
let sawDefinePage = false
|
|
|
|
return {
|
|
CallExpression(node) {
|
|
if (node.callee.type !== 'Identifier' || node.callee.name !== 'definePage')
|
|
return
|
|
sawDefinePage = true
|
|
|
|
const arg = node.arguments[0]
|
|
const metaProp = arg && arg.type === 'ObjectExpression'
|
|
? arg.properties.find(p => p.key && p.key.name === 'meta')
|
|
: null
|
|
const layoutProp = metaProp && metaProp.value.type === 'ObjectExpression'
|
|
? metaProp.value.properties.find(p => p.key && p.key.name === 'layout')
|
|
: null
|
|
|
|
if (!layoutProp || layoutProp.value.value !== expected) {
|
|
context.report({
|
|
node,
|
|
messageId: 'wrongLayout',
|
|
data: { expected, actual: layoutProp ? String(layoutProp.value.value) : 'none' },
|
|
})
|
|
}
|
|
},
|
|
'Program:exit': function (node) {
|
|
if (!sawDefinePage)
|
|
context.report({ node, messageId: 'missing' })
|
|
},
|
|
}
|
|
},
|
|
}
|