Skip to content

Naming convention: drop BEM entirely, or adopt it consistently? #33

Open

Description

@troychaplin

Two reviewers have pointed in opposite directions on CSS class naming, and we're currently inconsistent in a way neither would endorse. The #16 lint series is landing the fixes as suggested in review — this issue is just to settle the convention so we stop rediscovering the question.

@aduth in #2, on "selector-class-pattern": null in .stylelintrc.json:

I assume this is overriding the BEM naming rule enforcement? Personally I think that could still be valuable to uphold.

@joedolson in #18:

I think we should change the remaining BEM style classes… The naming needs to be self-consistent.

Two things that aren't obvious

1. The Gutenberg convention isn't textbook BEM. It uses __ for child elements, but modifiers are not -- — they're separate is-/has- classes (.components-panel.is-opened). So badge--experiment is wrong under both readings; under Gutenberg it'd be .accessibility-lab-badge.is-experiment. We already do this correctly for .accessibility-lab-row.is-dependent.

2. Our linter currently enforces the opposite of Gutenberg. We extend @wordpress/stylelint-config, whose selector-class-pattern is hyphens-only and rejects __. Gutenberg uses a different package, @wordpress/stylelint-tools, which explicitly allows __ and -- and ships a suppressions file for grandfathering. Upholding the Gutenberg rule is a package switch, not a config tweak.

Options

A — Drop BEM, kebab-case everywhere. Matches @joedolson, already enforced by our linter for free, no tooling change. But diverges from the Gutenberg convention, and names get long with no block/element boundary (accessibility-lab-media-view-config-field-description).

B — Adopt Gutenberg properly: __ for descendants, is-/has- for modifiers, switch to @wordpress/stylelint-tools. Matches @aduth and upstream expectations. But it's a tooling change, and it means revisiting the src/settings classes a second time.

(@aduth's suppressions idea is a migration mechanism for either option, not a third answer.)

Scope

Feature State Occurrences
src/settings (#18) kebab-case 4 classes
src/media-view-config (#22) BEM 21
src/editor/framework (#19) BEM 9

~30 occurrences either way, so cost isn't the deciding factor — the question is really whether we follow upstream Gutenberg or our current linter.

Whichever we pick, it should go in CONTRIBUTING.md, which documents PHP naming in detail but says nothing about CSS classes.

Activity

  1. joedolson commented on Sep 23, 2026

    @joedolson
    Collaborator

    I prefer non-BEM, overall; but I'm not going to argue the point if others prefer BEM. It's not a big deal to me one way or the other, but I would prefer to be consistent.

  2. troychaplin commented on Sep 23, 2026

    @troychaplin
    MemberAuthor

    I'm a fan of BEM, but I don't care enough to push for that. Like @joedolson, I would prefer consistency.

  3. aduth commented on Sep 29, 2026

    @aduth
    Member

    Another option is to adopt CSS modules, which is what a lot of newer Gutenberg code uses, and makes the whole naming problem moot at least from a conflicts point-of-view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions