Skip to content

✨ Recognised the @gift theme data global in v6#840

Open
jonatansberg wants to merge 1 commit into
mainfrom
ber-3738-gscan-gift-global
Open

✨ Recognised the @gift theme data global in v6#840
jonatansberg wants to merge 1 commit into
mainfrom
ber-3738-gscan-gift-global

Conversation

@jonatansberg

Copy link
Copy Markdown
Member

What

Teaches gscan that @gift is a known template data global in Ghost 6, so themes building their own gift-link reader UI with {{#if @gift}} / {{@gift.post_id}} don't fail validation with a GS120-NO-UNKNOWN-GLOBALS ("not a known global") error.

Ghost 6 exposes @gift to themes via the gift-links reader route (/g/<slug>). This should land before the feature is documented so theme authors writing @gift templates don't hit false errors.

Why version-scoped (v6 only)

@gift only exists in Ghost 6. A v5-targeting theme using @gift would break on Ghost 5, so it's a version-scoped global rather than a flat allowlist entry — v6 recognises it, v5 still (correctly) flags it.

This mirrors how pageBuilderProperties is defined per-spec: the active spec's new knownGlobals list is threaded through the AST linter into the scope's allowlist check.

  • lib/specs/v6.jsknownGlobals: _.union(previousSpec.knownGlobals, ['gift'])
  • lib/specs/v5.jsknownGlobals: []
  • lib/checks/120-no-unknown-globals.jslib/ast-linter/linter.jslib/ast-linter/rules/base.jslib/ast-linter/rules/internal/scope.jsknownGlobals flows into new Scope({extraGlobals})

The shared base allowlist (site/member/etc.) stays in scope.js; knownGlobals is purely additive per version.

Tests

  • New version-neutral fixture test/fixtures/themes/120-no-unknown-globals/v5/with-gift/ (uses {{#if @gift}} + {{@gift.post_id}})
  • v5: asserts @gift is flagged (2 failures)
  • v6: asserts it passes
  • Full suite green (411 tests), lint clean

Downstream (separate)

gscan is a published package — this does not change in-product theme validation until Ghost core bumps its gscan dependency to the release that includes this. That bump is a follow-up once this is released.

Refs https://linear.app/ghost/issue/BER-3738

Ghost 6 exposes `@gift` to themes via the gift-links reader route, so
themes can build their own gift-link reader UI with {{#if @gift}} and
{{@gift.post_id}}. Without this, GS120-NO-UNKNOWN-GLOBALS flagged it as
an unknown global.

`@gift` only exists in Ghost 6, so it's a version-scoped global rather
than a flat allowlist entry: the active spec's `knownGlobals` is now
threaded through the AST linter into the scope's allowlist check. v6
adds `gift`; v5 still (correctly) flags it, since a v5-targeting theme
using @gift would break on Ghost 5. Mirrors how `pageBuilderProperties`
is defined per-spec.

Refs https://linear.app/ghost/issue/BER-3738
@jonatansberg jonatansberg marked this pull request as ready for review June 17, 2026 12:57
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d8f39a6b-5bc5-4dbf-aa86-117d84b9b131

📥 Commits

Reviewing files that changed from the base of the PR and between e0b552a and aa7b569.

📒 Files selected for processing (8)
  • lib/ast-linter/linter.js
  • lib/ast-linter/rules/base.js
  • lib/ast-linter/rules/internal/scope.js
  • lib/checks/120-no-unknown-globals.js
  • lib/specs/v5.js
  • lib/specs/v6.js
  • test/120-no-unknown-globals.test.js
  • test/fixtures/themes/120-no-unknown-globals/v5/with-gift/default.hbs

Walkthrough

The PR introduces a knownGlobals mechanism for version-specific Handlebars data globals. The v5 spec gains an empty knownGlobals array; v6 extends it with 'gift' (the @gift global exposed by Ghost 6's gift-links reader route). The internal Scope class gains an extraGlobals constructor parameter that is checked alongside existing ghostGlobals/dataVars in isOnAllowlist and applied in isKnownVariable. BaseRule reads knownGlobals from its options and forwards it as extraGlobals when constructing Scope. linter.js threads knownGlobals from this.options into each rule config during buildScanner. The 120-no-unknown-globals check passes ruleSet.knownGlobals to ASTLinter. Tests assert @gift is flagged in v5 and accepted in v6.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • 9larsons
  • kevinansfield
  • troyciesco
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding recognition of @gift as a known global in Ghost v6 to prevent validation errors.
Description check ✅ Passed The description comprehensively explains the change, its purpose, technical implementation, testing approach, and downstream considerations, all directly related to the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ber-3738-gscan-gift-global

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.

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.

1 participant