Skip to content

Extracted shared ESLint rules + filename shim into root eslint.shared.mjs#28833

Merged
9larsons merged 3 commits into
mainfrom
worktree-eslint-shared-rules
Jun 23, 2026
Merged

Extracted shared ESLint rules + filename shim into root eslint.shared.mjs#28833
9larsons merged 3 commits into
mainfrom
worktree-eslint-shared-rules

Conversation

@9larsons

Copy link
Copy Markdown
Contributor

Summary

Adds eslint.shared.mjs at the repo root and refactors 16 workspace flat configs to import from it instead of redefining the same rule objects inline.

Shared module exports:

  • correctnessRules — the 12 shared correctness rules (eqeqeq, no-eval, no-console, no-shadow, etc.)
  • tsUnusedVarsRule / jsUnusedVarsRule — the two unused-vars shapes (TS-aware vs vanilla with caughtErrors: 'none')
  • sortImportsRuleghost/sort-imports-es6-autofix/sort-imports-es6 (used by ~6 workspaces)
  • shadeLayeredImportsRule — restricts barrel imports of @tryghost/shade
  • reactDefaultsOff / reactStrictRules — common React rule sets across the React workspaces
  • tailwindRulesV4 (settings-based) / tailwindRulesWithConfig(cfg) (v3, per-rule config)
  • mochaRulesOff(ghostPlugin) — helper that disables every ghost/mocha/* rule
  • localFilenamesPlugin — ESLint-9-compatible replacement for eslint-plugin-filenames-ts's match-regex (the upstream still calls context.getScope(), removed in ESLint 9). Includes ignoreExporting support that previously only ghost/core had.

Workspaces refactored (each keeps its workspace-specific extras inline):

  • React/TS: apps/{activitypub, admin-x-design-system, admin-x-framework, admin-x-settings, announcement-bar, comments-ui, portal, posts, shade, signup-form, sodo-search, stats}
  • Node: ghost/{i18n, parse-email-address}
  • Filename-shim only: ghost/{core, admin} (their rule sets stay inline; just the shim was extracted)

Notes:

  • ghost/i18n explicitly disables ghost/filenames/match-regex (added by correctnessRules) because this workspace uses the local-filenames/match-regex variant instead.
  • Comments-ui and signup-form opt out of reactStrictRules and inline 3 of its 4 rules — they don't want react/jsx-key: 'off'.

Test plan

  • Verified lint output byte-identical to baseline for all 14 React/TS workspaces (full pnpm exec eslint output diffed before/after — zero changes)
  • ghost/core and ghost/admin lint counts match baseline (47 and 9 warnings respectively)
  • CI lint passes across every workspace

@9larsons 9larsons requested a review from EvanHahn as a code owner June 23, 2026 16:16
@coderabbitai

coderabbitai Bot commented Jun 23, 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: 8aa2814c-1304-4692-92c1-dcc32af5f221

📥 Commits

Reviewing files that changed from the base of the PR and between 0a55e86 and 5c51274.

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

Walkthrough

A new root-level shared module eslint.shared.mjs is introduced, exporting reusable ESLint flat-config rule objects and helpers: correctnessRules, tsUnusedVarsRule, jsUnusedVarsRule, sortImportsRule, shadeLayeredImportsRule, reactDefaultsOff, reactStrictRules, tailwindRulesV4, tailwindRulesWithConfig, mochaRulesOff, and localFilenamesPlugin. All per-workspace ESLint configs across apps/* and ghost/* packages are then updated to import these shared exports, removing locally-defined equivalent ghostRules, mochaRulesOff, and localFilenamesPlugin implementations. Associated package versions are incremented.

Possibly related PRs

  • TryGhost/Ghost#28803: Introduced ESLint 9 flat configs with locally defined ghostRules/mochaRulesOff in apps/activitypub and related packages that this PR refactors to use shared presets.
  • TryGhost/Ghost#28807: Introduced the inline localFilenamesPlugin in ghost/core/eslint.config.mjs that this PR centralizes into eslint.shared.mjs.
  • TryGhost/Ghost#28802: Introduced eslint.config.js files for apps/admin-x-design-system, apps/admin-x-framework, and apps/shade with local rule bundles that this PR replaces with eslint.shared.mjs imports.

Suggested labels

ok to merge for me

Suggested reviewers

  • EvanHahn
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: extracting shared ESLint rules and a filename plugin into a root eslint.shared.mjs file, which is the core focus of this PR.
Description check ✅ Passed The description comprehensively explains the PR's purpose, shared module exports, refactored workspaces, and includes verification notes—all directly related to the changeset.
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 worktree-eslint-shared-rules

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 23, 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 6d558f2

Command Status Duration Result
nx run-many --target=build --projects=@tryghost... ✅ Succeeded 15s View ↗

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


☁️ Nx Cloud last updated this comment at 2026-06-23 16:19:35 UTC

@nx-cloud

nx-cloud Bot commented Jun 23, 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 5c51274

Command Status Duration Result
nx run @tryghost/admin-x-settings:test:acceptance ✅ Succeeded 11m 11s View ↗
nx run ghost:test:ci:integration:no-coverage ✅ Succeeded 2m 34s View ↗
nx run ghost:test:ci:integration ✅ Succeeded 2m 27s View ↗
nx run ghost:test:ci:legacy ✅ Succeeded 2m 54s View ↗
nx run ghost:test:ci:e2e ✅ Succeeded 2m 37s View ↗
nx run ghost:test:ci:e2e:no-coverage ✅ Succeeded 2m 17s View ↗
nx build @tryghost/activitypub ✅ Succeeded 2s View ↗
nx build @tryghost/signup-form ✅ 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-23 16:52:27 UTC

@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.10%. Comparing base (1ed2aac) to head (5c51274).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #28833      +/-   ##
==========================================
+ Coverage   74.07%   74.10%   +0.02%     
==========================================
  Files        1560     1560              
  Lines      134884   134884              
  Branches    16332    16335       +3     
==========================================
+ Hits        99913    99952      +39     
+ Misses      33991    33952      -39     
  Partials      980      980              
Flag Coverage Δ
e2e-tests 76.22% <ø> (+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 added 2 commits June 23, 2026 11:30
….mjs

no ref

- added eslint.shared.mjs at repo root exporting: correctnessRules (12 shared rules), tsUnusedVarsRule, jsUnusedVarsRule, sortImportsRule, shadeLayeredImportsRule, reactDefaultsOff, reactStrictRules, tailwindRulesV4, tailwindRulesWithConfig(cfg) for v3, mochaRulesOff(ghostPlugin), and localFilenamesPlugin (an ESLint 9-compatible replacement for eslint-plugin-filenames-ts's match-regex)
- refactored 14 React/TS workspace flat configs (apps/activitypub, admin-x-design-system, admin-x-framework, admin-x-settings, announcement-bar, comments-ui, portal, posts, shade, signup-form, sodo-search, stats; ghost/i18n, ghost/parse-email-address) to import from the shared module — each config keeps its workspace-specific extras inline
- replaced inline filenamesMatchRegex shims in ghost/core, ghost/admin, and ghost/i18n with the shared localFilenamesPlugin (the shared version includes ignoreExporting support, previously only in ghost/core)
- ghost/i18n explicitly disables ghost/filenames/match-regex (added by correctnessRules) since this workspace uses the local-filenames variant instead
- net: -450 lines across 16 configs; lint output verified byte-identical to baseline for every workspace touched
no ref

Patch-bumped portal, comments-ui, signup-form, sodo-search, and announcement-bar — they ship as UMD bundles to the CDN and the version-bump CI gate requires a bump whenever any file in their workspace changes (eslint.config.js in this case).
@9larsons 9larsons force-pushed the worktree-eslint-shared-rules branch from 6d558f2 to 0a55e86 Compare June 23, 2026 16:31
no ref

- tailwindcss/enforces-negative-arbitrary-values: warn → error
- tailwindcss/enforces-shorthand: warn → error
- tailwindcss/migration-from-tailwind-2: warn → off (Ghost is on Tailwind v4; this rule was a v2→v3 migration helper, no longer providing value)
Ghost's stance is error-or-off; warn-level rules get ignored by humans and agents and just pollute the lint output. The per-workspace warn-level rules (no-explicit-any, no-var, etc.) will be addressed in the profile-convergence follow-up.
@9larsons 9larsons enabled auto-merge (squash) June 23, 2026 16:36
@9larsons 9larsons merged commit ab5bcb4 into main Jun 23, 2026
54 checks passed
@9larsons 9larsons deleted the worktree-eslint-shared-rules branch June 23, 2026 17:00
9larsons added a commit that referenced this pull request Jun 23, 2026
…workspaces

no ref

Added three profile rule-sets to eslint.shared.mjs:
- tsReactAppRules — universal TS React subset (9 workspaces)
- viteTsReactExtras — react-hooks/react-refresh defaults for Vite apps (7 workspaces)
- jsReactAppRules — vanilla JS React (portal, sodo-search, announcement-bar)
- nodeLibRules — backend Node lib base (ghost/i18n, parse-email-address; ghost/core uses it too)
- noGhostIgnitionRequireRule — restricted-require helper for ghost/i18n
- strictLinterOptions — sets reportUnusedDisableDirectives to error so stale inline directives fail CI

Each affected workspace's config now spreads its profile preset instead of redefining the rule sets inline. Decisions were data-driven: every contested rule was probed at 'error' across its consumers and either kept at 'error' (zero violations) or dropped to 'off' (any violations). No source-code fixes for violations — Ghost's stance is opinionated config, not silent warnings.

Specifically flipped 'warn' → 'error' (zero violations):
- tailwindcss rules (already done in #28833)
- @typescript-eslint/no-explicit-any in ghost/core (4 places)
- no-var (1 violation in portal/src/utils/contrast-color.js fixed inline; var → const)
- one-var ['error', 'never'] in node libs

Dropped to 'off' (had violations):
- @typescript-eslint/no-explicit-any in profile (41+ violations across comments-ui/admin-x-settings)
- react-refresh/only-export-components (195)
- @typescript-eslint/no-non-null-assertion (97)
- @typescript-eslint/no-empty-function (121)
- react-hooks/exhaustive-deps (7)
- react/jsx-key (22)
- tailwindcss/migration-from-tailwind-2 (Ghost is on v4, rule no longer relevant)

Enabling reportUnusedDisableDirectives: 'error' caused autofix to delete ~70 stale inline eslint-disable comments across 40+ source files — those rules don't fire anymore and the comments were dead weight.

Result: 0 errors and 0 warnings across every affected workspace (apps/{12 frontend apps}, ghost/{i18n, parse-email-address, core, admin}).
9larsons added a commit that referenced this pull request Jun 23, 2026
…workspaces

no ref

Added three profile rule-sets to eslint.shared.mjs:
- tsReactAppRules — universal TS React subset (9 workspaces)
- viteTsReactExtras — react-hooks/react-refresh defaults for Vite apps (7 workspaces)
- jsReactAppRules — vanilla JS React (portal, sodo-search, announcement-bar)
- nodeLibRules — backend Node lib base (ghost/i18n, parse-email-address; ghost/core uses it too)
- noGhostIgnitionRequireRule — restricted-require helper for ghost/i18n
- strictLinterOptions — sets reportUnusedDisableDirectives to error so stale inline directives fail CI

Each affected workspace's config now spreads its profile preset instead of redefining the rule sets inline. Decisions were data-driven: every contested rule was probed at 'error' across its consumers and either kept at 'error' (zero violations) or dropped to 'off' (any violations). No source-code fixes for violations — Ghost's stance is opinionated config, not silent warnings.

Specifically flipped 'warn' → 'error' (zero violations):
- tailwindcss rules (already done in #28833)
- @typescript-eslint/no-explicit-any in ghost/core (4 places)
- no-var (1 violation in portal/src/utils/contrast-color.js fixed inline; var → const)
- one-var ['error', 'never'] in node libs

Dropped to 'off' (had violations):
- @typescript-eslint/no-explicit-any in profile (41+ violations across comments-ui/admin-x-settings)
- react-refresh/only-export-components (195)
- @typescript-eslint/no-non-null-assertion (97)
- @typescript-eslint/no-empty-function (121)
- react-hooks/exhaustive-deps (7)
- react/jsx-key (22)
- tailwindcss/migration-from-tailwind-2 (Ghost is on v4, rule no longer relevant)

Enabling reportUnusedDisableDirectives: 'error' caused autofix to delete ~70 stale inline eslint-disable comments across 40+ source files — those rules don't fire anymore and the comments were dead weight.

Result: 0 errors and 0 warnings across every affected workspace (apps/{12 frontend apps}, ghost/{i18n, parse-email-address, core, admin}).
9larsons added a commit that referenced this pull request Jun 23, 2026
…workspaces

no ref

Added three profile rule-sets to eslint.shared.mjs:
- tsReactAppRules — universal TS React subset (9 workspaces)
- viteTsReactExtras — react-hooks/react-refresh defaults for Vite apps (7 workspaces)
- jsReactAppRules — vanilla JS React (portal, sodo-search, announcement-bar)
- nodeLibRules — backend Node lib base (ghost/i18n, parse-email-address; ghost/core uses it too)
- noGhostIgnitionRequireRule — restricted-require helper for ghost/i18n
- strictLinterOptions — sets reportUnusedDisableDirectives to error so stale inline directives fail CI

Each affected workspace's config now spreads its profile preset instead of redefining the rule sets inline. Decisions were data-driven: every contested rule was probed at 'error' across its consumers and either kept at 'error' (zero violations) or dropped to 'off' (any violations). No source-code fixes for violations — Ghost's stance is opinionated config, not silent warnings.

Specifically flipped 'warn' → 'error' (zero violations):
- tailwindcss rules (already done in #28833)
- @typescript-eslint/no-explicit-any in ghost/core (4 places)
- no-var (1 violation in portal/src/utils/contrast-color.js fixed inline; var → const)
- one-var ['error', 'never'] in node libs

Dropped to 'off' (had violations):
- @typescript-eslint/no-explicit-any in profile (41+ violations across comments-ui/admin-x-settings)
- react-refresh/only-export-components (195)
- @typescript-eslint/no-non-null-assertion (97)
- @typescript-eslint/no-empty-function (121)
- react-hooks/exhaustive-deps (7)
- react/jsx-key (22)
- tailwindcss/migration-from-tailwind-2 (Ghost is on v4, rule no longer relevant)

Enabling reportUnusedDisableDirectives: 'error' caused autofix to delete ~70 stale inline eslint-disable comments across 40+ source files — those rules don't fire anymore and the comments were dead weight.

Result: 0 errors and 0 warnings across every affected workspace (apps/{12 frontend apps}, ghost/{i18n, parse-email-address, core, admin}).
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