Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ module.exports = {
{
files: [ 'packages/eslint-plugin/**', 'packages/theme/**' ],
rules: {
'@wordpress/no-setting-ds-tokens': 'off',
'@wordpress/no-unknown-ds-tokens': 'off',
},
},
Expand Down
4 changes: 4 additions & 0 deletions packages/eslint-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Added [`use-recommended-components`](https://github.com/WordPress/gutenberg/blob/HEAD/packages/eslint-plugin/docs/rules/use-recommended-components.md) rule to encourage the use of recommended UI components in a WordPress environment ([#76222](https://github.com/WordPress/gutenberg/pull/76222)).

### Enhancements

- The `no-setting-ds-tokens` rule now checks all object property keys, not just those inside JSX `style` attributes ([#76212](https://github.com/WordPress/gutenberg/pull/76212)).

## 24.3.0 (2026-03-04)

### New Features
Expand Down
8 changes: 4 additions & 4 deletions packages/eslint-plugin/docs/rules/no-setting-ds-tokens.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Disallow setting Design System token CSS custom properties (no-setting-ds-tokens)

Design System tokens (CSS custom properties beginning with `--wpds-`) are meant to be consumed, not set. Setting these properties in inline styles can lead to unexpected behavior and breaks the Design System's theming capabilities.
Design System tokens (CSS custom properties beginning with `--wpds-`) are meant to be consumed, not set. Setting these properties can lead to unexpected behavior and breaks the Design System's theming capabilities.

This rule lints JSX inline styles. For CSS files, use the [corresponding Stylelint rule](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-theme/#stylelint-plugins) from the `@wordpress/theme` package.
This rule lints all object property keys in JavaScript/TypeScript files. For CSS files, use the [corresponding Stylelint rule](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-theme/#stylelint-plugins) from the `@wordpress/theme` package.

## Rule details

Expand All @@ -12,8 +12,8 @@ Examples of **incorrect** code for this rule:
<div style={ { '--wpds-color-fg-content-neutral': 'red' } } />
```

```jsx
<div style={ { '--wpds-font-size-md': '10px', color: 'blue' } } />
```js
const styles = { '--wpds-color-fg-content-neutral': 'red' };
```

Examples of **correct** code for this rule:
Expand Down
33 changes: 33 additions & 0 deletions packages/eslint-plugin/rules/__tests__/no-setting-ds-tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ ruleTester.run( 'no-setting-ds-tokens', rule, {
{
code: `<div style={ { margin: '10px' } } />`,
},
{
code: `const styles = { '--my-custom-prop': 'value' };`,
},
{
code: `const styles = { color: 'var(--wpds-color-fg-content-neutral)' };`,
},
{
code: `const { '--wpds-color-fg-content-neutral': neutralColor } = styles;`,
},
],
invalid: [
{
Expand All @@ -42,5 +51,29 @@ ruleTester.run( 'no-setting-ds-tokens', rule, {
},
],
},
{
code: `const styles = { '--wpds-color-fg-content-neutral': 'red' };`,
errors: [
{
messageId: 'disallowedSet',
},
],
},
{
code: `function getStyles() { return { '--wpds-font-size-md': '10px' }; }`,
errors: [
{
messageId: 'disallowedSet',
},
],
},
{
code: `const config = { inner: { '--wpds-color-fg-content-neutral': 'red' } };`,
errors: [
{
messageId: 'disallowedSet',
},
],
},
],
} );
6 changes: 2 additions & 4 deletions packages/eslint-plugin/rules/no-setting-ds-tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = /** @type {import('eslint').Rule.RuleModule} */ ( {
type: 'problem',
docs: {
description:
'Disallow setting any CSS custom property beginning with --wpds- in inline styles',
'Disallow setting any CSS custom property beginning with --wpds-',
},
schema: [],
messages: {
Expand All @@ -14,9 +14,7 @@ module.exports = /** @type {import('eslint').Rule.RuleModule} */ ( {
create( context ) {
return {
/** @param {import('estree').Property} node */
'JSXAttribute[name.name="style"] ObjectExpression > Property[key.value=/^--wpds-/]'(
node
) {
'ObjectExpression > Property[key.value=/^--wpds-/]'( node ) {
context.report( {
node: node.key,
messageId: 'disallowedSet',
Expand Down
Loading