Skip to content

Make sure it checks for display-scale #619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

lukasoppermann
Copy link
Contributor

This pull request introduces updates to the color validation logic and test cases in the colors plugin. The changes primarily enhance the handling of background, border, and related properties, expand the validation for shorthand properties, and add new test cases to cover display scale tokens.

@langermank @jonrohan I hope this change make sense. It is the first time for me working in this repo. I'll add some comments in the code to explain

@lukasoppermann lukasoppermann requested a review from a team as a code owner May 20, 2025 11:21
Copy link

changeset-bot bot commented May 20, 2025

🦋 Changeset detected

Latest commit: 1e3429d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/stylelint-config Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -25,8 +25,8 @@ export const messages = ruleMessages(ruleName, {
let variables = primitivesVariables('colors')
const validProps = {
'^color$': ['fgColor', 'iconColor'],
'^background(-color)?$': ['bgColor'],
'^border(-top|-right|-bottom|-left|-inline|-block)*(-color)?$': ['borderColor'],
'^background(-color|-image)?$': ['bgColor'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also test background-image

'^background(-color)?$': ['bgColor'],
'^border(-top|-right|-bottom|-left|-inline|-block)*(-color)?$': ['borderColor'],
'^background(-color|-image)?$': ['bgColor'],
'^border(?:-top|-right|-bottom|-left|-inline|-block)?(?:-color)?$': ['borderColor'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Enable testing for border

(/^border(-top|-right|-bottom|-left|-inline|-block)*$/.test(prop) || /^background$/.test(prop)) &&
!valueNode.value.toLowerCase().includes('color')
(/^border(?:-top|-right|-bottom|-left|-inline|-block)?$/.test(prop) || /^background$/.test(prop)) &&
['color', 'scale'].every(word => !valueNode.value.toLowerCase().includes(word))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We now only return if neither color nor scale is in the token, because we want --display-blue-scale-0 to fail.

If this is risky we could also consider changing the name of the token to --display-blue-color-0 or --display-blue-colorScale-0 CC:@langermank

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@lukasoppermann lukasoppermann requested a review from Copilot May 20, 2025 19:29
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the color validation rule to handle background-image properties, exclude display-scale tokens from shorthand props, and adds corresponding test coverage.

  • Broaden regexes to include -image for backgrounds and refine border shorthand matching
  • Update shorthand logic to skip values containing “scale” as well as “color”
  • Add new tests for rejecting --display-*-scale-* variables in various properties

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
plugins/colors.js Extended background regex, refined border shorthand logic, and updated the skip‐value check to also exclude “scale.”
tests/colors.js Added tests to ensure display‐scale tokens are rejected by the rule
.changeset/pink-beds-mix.md Bumped minor version and noted new background/border behavior
Comments suppressed due to low confidence (3)

plugins/colors.js:139

  • Typo in comment: shortand should be shorthand.
// Property is shortand and value doesn't include color

plugins/colors.js:29

  • The updated border regex only allows one segment (e.g., -top) but drops support for multi-part shorthands like border-inline-block. Change ? back to * on the segment group to restore repeated segments.
'^border(?:-top|-right|-bottom|-left|-inline|-block)?(?:-color)?$': ['borderColor'],

plugins/colors.js:51

  • Same issue here: this propType regex restricts to a single segment. Use (?:-top|-right|-bottom|-left|-inline|-block)* instead of ? to allow multiple segments in shorthand border props.
} else if (/^border(?:-top|-right|-bottom|-left|-inline|-block)?(?:-color)?$/.test(prop)) {

lukasoppermann and others added 2 commits May 22, 2025 12:47
Copy link
Member

@jonrohan jonrohan left a comment

Choose a reason for hiding this comment

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

Seems ok, we should verify there isn't too many new errors on the dotcom codebase by running lint with the canary build

@lukasoppermann
Copy link
Contributor Author

@jonrohan can you do this? I have no idea how to do what you just said.

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.

2 participants