Skip to content

Conversation

@mejiaj
Copy link
Collaborator

@mejiaj mejiaj commented Sep 5, 2025

Summary

Add automated frontend formatting and linting checks and fix styles to comply. Keeps styles consistent in both Storybook and Bixal drupal theme.

Thanks to @levinmr, I used his work in Bixal/template-frontend#1 as a reference.

Related issue

Closes #492.

Solution

Lack of consistent style rules and CI checks allowed formatting drift across Storybook and the Drupal theme. This PR adds Prettier + Stylelint with CI checks so future changes are standardized and enforced.

Summary

Add automated frontend formatting and linting, and update SCSS to comply. Keeps USWDS styles consistent across Storybook and the Drupal theme.

Related issue

Closes #492

Solution

We lacked shared style rules and CI checks, which led to drift. This adds Prettier + Stylelint with a GitHub Action and aligns existing SCSS (syntax, mixins, selectors) so changes are standardized and enforced.

Major changes

  • New GitHub Action: “Frontend formatting & linting” runs on changes to stories and drupal theme styles.
  • New npm scripts (both in root and theme): format:styles, format:styles:fix, lint:styles, lint:styles:fix.
  • Stylelint config: extends stylelint-config-standard-scss and stylelint-prettier.
  • Ignore files that aren't ours: .prettierignore and .stylelintignore for storybook-sass, dist, libraries, contrib, core, node_modules.
  • SCSS cleanups to satisfy rules and modern CSS:
    • Use rgb() with alpha, color-mix(), and lowercase currentcolor.
    • Prefer ::before/::after; use :where()/:is() where appropriate.
    • Consistent quotes and USWDS mixin/function calls.
    • Remove duplicates/unused selectors.
  • Stylelint rules adjusted for our project-specific preferences:
    • Allow private CSS vars (custom-property-pattern: null).
    • Allow BEM (selector-class-pattern: null), prefer media query prefix notation.

Testing and review

  1. At root:

    npm ci && npm run format:styles && npm run lint:styles`

    There shouldn't be any changes or errors.

  2. In web/themes/custom/bixal_uswds:

    npm ci && npm run format:styles && npm run lint:styles

    There shouldn't be any changes or errors.

  3. Visual smoke test (Storybook and/or Drupal build): Header, Footer, Hero, Buttons, Site Alert, People List, Emphasis Block. Check borders, shadows, icon fills, spacing, and list styles.

  4. Confirm ignores work (no lint output from ignored directories).

For actions you should see Frontend formatting & linting. It runs on push and PRs.

capture-98ahJWxl-2025-09-05

The lint task relies on formatting, so it should fail if formatting fails.

capture-sOrpVovl-2025-09-05

On initial run formatting takes 20s and linting 27s.

Note

Checks will only run if SCSS changes.

Dependencies

Root package.json

Dependency Old New
prettier -- 3.6.2
stylelint-config-standard-scss -- 15.0.1

bixal_uswds

Dependency Old New
prettier -- 3.6.2
stylelint -- 16.23.1
stylelint-config-standard-scss -- 15.0.1
stylelint-prettier -- 5.0.3

Add stylelinting for both drupal theme and storybook components.
Disabled the following:
- `custom-property-pattern` because we're using private CSS vars to define component defaults
- `selector-class-pattern` because we're using BEM syntax and I didn't want to add another dependency for it
…dentally show as successful if one passes.
@mejiaj
Copy link
Collaborator Author

mejiaj commented Sep 5, 2025

I did a quick upload of the storybook on chromatic to compare to a non-styled branch. Checks seem to pass:
capture-EAAPguSs-2025-09-05

@mejiaj mejiaj requested a review from mattsqd September 5, 2025 20:11
@mejiaj mejiaj marked this pull request as ready for review September 5, 2025 20:11
@mejiaj mejiaj changed the title BSD-492: Frontend checks BSD-492: Frontend style checks Sep 5, 2025
"description": "",
"main": "gulpfile.js",
"scripts": {
"format:styles": "prettier './**/*.scss' --check",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Love this @mejiaj ! I didn't realize paths could be used in the action to only trigger when files in that dir change to run the action. I did a little more reading, and it seems if it's push it always run on the first because there's nothing to compare against. Makes me think about the validation I added in my commands, it runs regardless of changes in the branch. I'm not sure if I like the idea of a singular call that just does it all the time or a bunch of actions that have triggers on the paths they should be in.

What I wanted to ask was, are you sure we need this in the theme as well? It looks like your GitHub action runs only on the root, and that's configured so that it ignores stuff that shouldn't be run on in the theme already and overlaps the theme directories 100%.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@mattsqd I see what you mean. I added it so developers could check if they were only working inside the Drupal theme.

I've removed in 54d7c19. I also added a note in the README for these new scripts.

capture-gmkOanUo-2025-09-10
https://github.com/Bixal/bixal-site-drupal/blob/54d7c19b81b6897b07ee6b58f997662947751f97/README.md#run-validation-checks

…matting.

For now, we'll go with the top-level checks.
@mejiaj mejiaj requested a review from mattsqd September 10, 2025 13:33
@mattsqd mattsqd merged commit a588839 into develop Sep 10, 2025
4 checks passed
@mattsqd mattsqd deleted the feature/BSD-492-frontend-checks branch September 10, 2025 20:45
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.

bixal-site-drupal - feature request: Add linting & formatting checks for styles

3 participants