Skip to content

Tools: Ban classnames via Syncpack#79061

Merged
manzoorwanijk merged 1 commit into
trunkfrom
ban/classnames-via-syncpack
Jun 9, 2026
Merged

Tools: Ban classnames via Syncpack#79061
manzoorwanijk merged 1 commit into
trunkfrom
ban/classnames-via-syncpack

Conversation

@manzoorwanijk

@manzoorwanijk manzoorwanijk commented Jun 9, 2026

Copy link
Copy Markdown
Member

What?

Adds a Banned version group to syncpack.config.mjs so that any package.json declaring classnames causes npm run lint:deps (and CI) to fail.

Follow-up to #77950 — picks up the isBanned classnames suggestion from @ciampo's review.

Why?

Gutenberg standardised on clsx in #61138 and removed every classnames declaration across the monorepo. There is currently no guardrail preventing it from being re-added later — an npm install classnames --workspace @wordpress/<some-pkg> in any workspace would land silently and bloat bundles with both libraries side by side.

ESLint's no-restricted-imports already catches import classnames from 'classnames' at the source level, but not a stray package.json declaration with no matching import — which is exactly what would happen if someone re-adds the dep ahead of refactoring code. Syncpack catches the declaration; ESLint catches the import. Both layers complement each other.

How?

Single addition to syncpack.config.mjs:

{
    label: 'Banned dependencies that should not be reintroduced.',
    dependencies: [ 'classnames' ],
    packages: [ '**' ],
    isBanned: true,
},

The rule is purely preventive — no current declarations match, so this PR's diff in actual package.json files is empty.

Testing Instructions

# 1. Confirm lint passes on this branch as-is (no current `classnames` declarations):
npm run lint:deps          # exits 0, "✓ No issues found"

# 2. Add `classnames` to any workspace and verify the rule fires:
npm install classnames --workspace @wordpress/components
npm run lint:deps          # exits non-zero; reports `IsBanned`

# 3. `lint:deps:fix` removes the banned declaration:
npm run lint:deps:fix
npm run lint:deps          # exits 0 again

Testing Instructions for Keyboard

N/A — tooling/config only.

Screenshots or screencast

N/A — no UI changes.

Use of AI Tools

Drafted with assistance from Claude Code. The change and PR description were reviewed and edited by hand.

Screenshot 2026-06-09 at 10 03 36 PM

Gutenberg standardised on `clsx` in 2024 ([#61138]) and removed every
`classnames` declaration across the monorepo. There is currently no
guardrail preventing it from being re-added later — an `npm install
classnames` in any workspace would land silently.

Add a `Banned` version group to `syncpack.config.mjs` that fails
`lint:deps` (and CI) on any declaration of `classnames` in any
package.json. The rule is preventive: no current declarations are
affected.

Picked up as the follow-up suggested in #77950's review.

[#61138]: #61138
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@manzoorwanijk manzoorwanijk self-assigned this Jun 9, 2026
@manzoorwanijk manzoorwanijk requested review from aduth, ciampo and Copilot June 9, 2026 16:37
@manzoorwanijk manzoorwanijk added the [Type] Code Quality Issues or PRs that relate to code quality label Jun 9, 2026

Copilot AI 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.

Pull request overview

Adds a Syncpack guardrail to prevent classnames from being reintroduced anywhere in the monorepo via package.json declarations, complementing existing ESLint import restrictions and avoiding duplicate bundle weight alongside clsx.

Changes:

  • Add a new versionGroups entry in syncpack.config.mjs marking classnames as banned (isBanned: true) across all packages.

@Mamaduka Mamaduka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, this is nice!

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 8.44 MB

compressed-size-action

@manzoorwanijk manzoorwanijk enabled auto-merge (squash) June 9, 2026 16:43
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

Flaky tests detected in f3cab41.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/27220939432
📝 Reported issues:

@manzoorwanijk manzoorwanijk merged commit d651a81 into trunk Jun 9, 2026
49 of 50 checks passed
@manzoorwanijk manzoorwanijk deleted the ban/classnames-via-syncpack branch June 9, 2026 17:11
@github-actions github-actions Bot added this to the Gutenberg 23.4 milestone Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants