Skip to content
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

Show warning when using unsupported bare value data type #17464

Merged
merged 7 commits into from
Apr 4, 2025

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Mar 31, 2025

This PR will show a warning if you are using a bare value data type that is not supported.

Let's say you want to create a new utility that allows color to be a bare value data type like this:

@utility paint-* {
  paint: --value([color], color);
}

This means that this would enable new syntax that we don't support yet. E.g.: paint-#0088cc.

The only supported data types for bare values are:

  • number2.5
  • integer2
  • ratio1/2
  • percentage50%

All other data types are not supported in this position. This PR will now show a warning:

Unsupported bare value data type: "color".
Only valid data types are: "number", "integer", "ratio", "percentage".

```css
--value([color],color)
                ^^^^^
```

Once we have better sourcemap / location tracking support, this warning will point to the exact spot, but for now, only a re-print of the AST can be used.

If you do want to use other data types, then you will have to use arbitrary value syntax with […] instead.

@utility paint-* {
  paint: --value([color]);
}

This will allow for paint-[#0088cc] for example.

Note: this is not a behavioral change, we already didn't support other data types, but we silently ignored them. This means that we have to do more parsing at runtime when evaluating the utility.

With this change, a warning is shown when registering the @utility, not when using it.

@RobinMalfait RobinMalfait requested a review from a team as a code owner March 31, 2025 10:24
!BARE_VALUE_DATA_TYPES.includes(node.value)
) {
console.warn(
`Unsupported bare value data type: "${node.value}".\nOnly valid data types are: ${BARE_VALUE_DATA_TYPES.map((x) => `"${x}"`).join(', ')}\n`,
Copy link
Member Author

Choose a reason for hiding this comment

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

@adamwathan do you want to make any changes to this warning?

Output looks something like this right now:

Unsupported bare value data type: "color".
Only valid data types are: "number", "integer", "ratio", "percentage"

```css
--value([color],color)
                ^^^^^
```

Copy link
Member

Choose a reason for hiding this comment

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

My 5 ct: I don't think the term "bare value" is something that people of that API will be familiar with but maybe we just call it "value data type" (since it's the --value(…) function)?

Unsupported value data type: "color".
Only valid data types are: "number", "integer", "ratio", "percentage".

```css
--value([color],color)
                ^^^^^
```

The rest I think is fine personally but I'd add a dot at the end of the second sentence

Copy link
Member Author

Choose a reason for hiding this comment

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

I think people writing plugins like that will be more familiar with the term (or at least should be because they will have to know the difference between color and [color]).

Main reason I used it is because that's what we use in the docs for it: https://tailwindcss.com/docs/adding-custom-styles#bare-values

Copy link
Member

Choose a reason for hiding this comment

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

Ohh right we do refer to it like that in the docs huh, yep then I think this does make sense

@RobinMalfait RobinMalfait force-pushed the feat/warn-when-using-invalid-bare-data-type branch from 33c8609 to 3fef1e4 Compare April 3, 2025 16:16
@RobinMalfait RobinMalfait enabled auto-merge (squash) April 4, 2025 12:17
@RobinMalfait RobinMalfait merged commit 2fd7c8d into main Apr 4, 2025
7 checks passed
@RobinMalfait RobinMalfait deleted the feat/warn-when-using-invalid-bare-data-type branch April 4, 2025 12:20
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.

3 participants