Skip to content

Changed ghost/core to ESLint 9 / flat config#28807

Merged
9larsons merged 2 commits into
mainfrom
eslint9-08-ghost-core
Jun 23, 2026
Merged

Changed ghost/core to ESLint 9 / flat config#28807
9larsons merged 2 commits into
mainfrom
eslint9-08-ghost-core

Conversation

@9larsons

Copy link
Copy Markdown
Contributor

Summary

Migrates ghost/core — the backend — from .eslintrc.js to flat config. Largest of the per-workspace migrations because of the number of path-based overrides.

  • Replaced ghost/core/.eslintrc.js + ghost/core/test/.eslintrc.js with a single eslint.config.mjs. Two .eslintignore files folded into flat-config ignores (with the !member-attribution allow-back preserved as a negation entry).
  • Replaced ghost/filenames/match-regex with a small inline local-filenames/match-regex rule. The upstream rule's getExportedClass walks the scope chain via the removed context.getScope() API — that path triggers on module.exports = <Identifier> source, which is everywhere in ghost/core. The inline replacement does just the filename check (no ignoreExporting/ignoreExportingClass).
  • Preserved every legacy override block:
    • API endpoints — max-api-complexity
    • Migrations — filename pattern (with 1.*/2.*/3.* exclusions), no-restricted-syntax against loops + knex multi-join, ghost/no-return-in-loop/no-return-in-loop
    • core/server/data/schema/schema.jscreated_by / updated_by ban
    • core/**/*.{js,ts} — kebab-case filenames (adapters carve-out)
    • core/frontend/helpers/** + core/frontend/apps/*/lib/helpers/** — underscores allowed (Handlebars helper names)
    • core/frontend/src/admin-auth/** — browser env, no-console off, native errors allowed
    • core/frontend/src/member-attribution/** — the one frontend/src/ subtree that's lint-scoped, browser env, ESM source
    • core/frontend/** and core/server/** require allowlists (server↔frontend boundary)
  • Pinned 'no-unused-vars' caughtErrors: 'none' and disabled 'no-unused-private-class-members' (added to eslint:recommended in ESLint 9).
  • Relaxed typescript-eslint v8's stricter recommended rules (no-require-imports, no-unused-expressions, no-unsafe-function-type, ban-ts-comment) to match the legacy plugin:ghost/ts posture. The no-unused-expressions relaxation supersedes the temporary workaround in #28804, which disabled the rule in the legacy .eslintrc.js because the @typescript-eslint v8.49 plugin's rule wrapper was misbehaving under ESLint 8.
  • Updated three legacy eslint-disable ghost/filenames/match-regex comments to reference the new local-filenames/match-regex rule:
    • core/server/api/endpoints/utils/validators/input/automated_emails.js
    • core/server/api/endpoints/utils/validators/input/password_reset.js
    • core/server/api/endpoints/utils/validators/input/automation_email_previews.js
  • ESLint 9 dropped --ext and the --ignore-path flag; per-domain lint:server / lint:shared / lint:frontend / lint:test / lint:types scripts pass directory args and let the config block's files glob do the matching.
  • No ESM conversion. ghost/core has 2068 CJS files in core/server alone; converting is its own roadmap.
  • Tests use a mix of Mocha and Vitest; ghost/mocha/* rules disabled by default in the test block with the one legacy 'ghost/mocha/no-skipped-tests': 'error' kept on.

Test plan

  • CI lint passes
  • `pnpm --filter ghost lint:server` is green locally
  • `pnpm --filter ghost lint:shared` is green locally
  • `pnpm --filter ghost lint:frontend` is green locally
  • `pnpm --filter ghost lint:test` is green locally
  • `pnpm --filter ghost exec eslint '**/*.ts' --cache` is green locally

ref https://linear.app/tryghost/

- migrated ghost/core/.eslintrc.js + ghost/core/test/.eslintrc.js to a single
  eslint.config.mjs; folded the two .eslintignore files into flat-config
  'ignores' (with the !member-attribution allow-back preserved)
- replaced 'ghost/filenames/match-regex' with a local inline rule that does
  the same filename check (no scope traversal); the upstream rule's
  context.getScope() call is broken under ESLint 9
- preserved every legacy override: API endpoints, migrations (filenames +
  no-loops + no-return-in-loop), schema.js (no created_by/updated_by),
  core/** kebab-case filenames (adapters carve-out), frontend helpers
  underscores, admin-auth + member-attribution browser env, shared/frontend/
  server require allowlists
- pinned 'no-unused-vars' caughtErrors: 'none' and disabled
  'no-unused-private-class-members' (ESLint 9 added this to recommended)
- relaxed typescript-eslint v8's stricter recommended rules
  (no-require-imports, no-unused-expressions, no-unsafe-function-type,
  ban-ts-comment) to match the legacy plugin:ghost/ts posture; will tighten
  later — supersedes the temporary workaround in PR #28804 which disabled
  no-unused-expressions in the legacy .eslintrc.js
- removed --ext (ESLint 9 dropped it) and --ignore-path flags from lint scripts
- updated three eslint-disable comments that referenced
  ghost/filenames/match-regex to suppress the new local-filenames/match-regex
  rule (automated_emails.js, password_reset.js, automation_email_previews.js)
- tests run a mix of mocha + vitest; mocha rules off by default with the
  one legacy 'ghost/mocha/no-skipped-tests' kept on
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0c2ca0ce-b36b-4fac-877e-d3dd6395d8ec

📥 Commits

Reviewing files that changed from the base of the PR and between 2e7cdac and 3009d72.

📒 Files selected for processing (1)
  • ghost/core/eslint.config.mjs
🚧 Files skipped from review as they are similar to previous changes (1)
  • ghost/core/eslint.config.mjs

Walkthrough

The ghost/core ESLint configuration is migrated from the legacy cascading format (.eslintrc.js + .eslintignore files) to the ESLint 9 flat config format. A new eslint.config.mjs file is introduced that defines a custom local-filenames plugin with a match-regex rule (replacing the ESLint 9-incompatible scope-based approach), shared rule presets (ghostBaseRules, mochaRulesOff, migrationLoopRules), and all previously configured path-specific overrides for TypeScript, migrations, schema, frontend/server boundary enforcement, and test files. The package.json lint scripts are simplified and devDependencies are updated to explicit ESLint 9 packages. Three validator files have their inline eslint-disable comments updated to reference the renamed local-filenames/match-regex rule.

Possibly related PRs

  • TryGhost/Ghost#28791: Directly modifies ghost/core/test/.eslintrc.js Mocha rule settings — the same file this PR removes entirely when migrating to flat config.
  • TryGhost/Ghost#28802: Implements the same ESLint 8→9 flat-config migration pattern using tseslint.config(...) for a different workspace (apps/*).
  • TryGhost/Ghost#28804: Modifies ghost/core/.eslintrc.js to disable @typescript-eslint/no-unused-expressions — the same file this PR replaces with eslint.config.mjs.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: migrating ghost/core to ESLint 9 with flat config, which is the primary focus of this comprehensive refactoring across multiple configuration files.
Description check ✅ Passed The description thoroughly explains the migration's scope, technical rationale, preserved legacy configurations, and rule adjustments, all directly corresponding to the changeset's modifications.
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 eslint9-08-ghost-core

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.

@nx-cloud

nx-cloud Bot commented Jun 22, 2026

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 2e7cdac

Command Status Duration Result
nx run @tryghost/admin-x-settings:test:acceptance ✅ Succeeded 9m 48s View ↗
nx build @tryghost/announcement-bar ✅ Succeeded <1s View ↗
nx build @tryghost/sodo-search ✅ Succeeded 1s View ↗
nx build @tryghost/activitypub ✅ Succeeded 2s View ↗
nx build @tryghost/signup-form ✅ Succeeded <1s View ↗
nx build @tryghost/comments-ui ✅ Succeeded <1s View ↗
nx build @tryghost/admin-toolbar ✅ Succeeded <1s View ↗
nx build @tryghost/portal ✅ Succeeded <1s View ↗
Additional runs (15) ✅ Succeeded ... View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-06-22 22:29:13 UTC

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ghost/core/eslint.config.mjs`:
- Around line 193-196: The glob pattern in the max-api-complexity rule
configuration at the target location only matches top-level files in the
endpoints directory and excludes nested utility files in subdirectories. Either
update the glob pattern from the current single-level wildcard to a recursive
pattern to include nested endpoint files, or add a comment documenting why
utilities in nested subdirectories are intentionally excluded from the
complexity rule. This will clarify the design decision and prevent
inconsistencies if endpoint files are later organized in subdirectories.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 11f519b7-0bac-42cb-a77f-cc493c3723b6

📥 Commits

Reviewing files that changed from the base of the PR and between e4b5821 and 2e7cdac.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (9)
  • ghost/core/.eslintignore
  • ghost/core/.eslintrc.js
  • ghost/core/core/server/api/endpoints/utils/validators/input/automated_emails.js
  • ghost/core/core/server/api/endpoints/utils/validators/input/automation_email_previews.js
  • ghost/core/core/server/api/endpoints/utils/validators/input/password_reset.js
  • ghost/core/eslint.config.mjs
  • ghost/core/package.json
  • ghost/core/test/.eslintignore
  • ghost/core/test/.eslintrc.js
💤 Files with no reviewable changes (4)
  • ghost/core/test/.eslintignore
  • ghost/core/test/.eslintrc.js
  • ghost/core/.eslintrc.js
  • ghost/core/.eslintignore

Comment thread ghost/core/eslint.config.mjs
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.10%. Comparing base (e4b5821) to head (3009d72).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #28807      +/-   ##
==========================================
+ Coverage   74.07%   74.10%   +0.02%     
==========================================
  Files        1560     1560              
  Lines      134826   134826              
  Branches    16316    16328      +12     
==========================================
+ Hits        99875    99915      +40     
+ Misses      33941    33931      -10     
+ Partials     1010      980      -30     
Flag Coverage Δ
e2e-tests 76.23% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@9larsons 9larsons merged commit 10a5c7c into main Jun 23, 2026
54 checks passed
@9larsons 9larsons deleted the eslint9-08-ghost-core branch June 23, 2026 14:04
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