Skip to content

Commit

Permalink
Components: Add eslint rule for theme CSS var usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka committed Feb 14, 2024
1 parent abdde7a commit 6ccb546
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,10 @@ module.exports = {
},
{
files: [ 'packages/components/src/**' ],
excludedFiles: [ 'packages/components/src/utils/colors-values.js' ],
excludedFiles: [
'packages/components/src/utils/colors-values.js',
'packages/components/src/theme/**',
],
rules: {
'no-restricted-syntax': [
'error',
Expand All @@ -369,6 +372,18 @@ module.exports = {
message:
'--wp-admin-theme-* variables do not support component theming. Use variables from the COLORS object in packages/components/src/utils/colors-values.js instead.',
},
{
selector:
'Literal[value=/var.+--wp-components-color-/]', // allow overriding definitions, but not access with var()
message:
'To ensure proper fallbacks, --wp-components-color-* variables should not be used directly. Use variables from the COLORS object in packages/components/src/utils/colors-values.js instead.',
},
{
selector:
'TemplateElement[value.cooked=/var.+--wp-components-color-/]', // allow overriding definitions, but not access with var()
message:
'To ensure proper fallbacks, --wp-components-color-* variables should not be used directly. Use variables from the COLORS object in packages/components/src/utils/colors-values.js instead.',
},
],
},
},
Expand Down

0 comments on commit 6ccb546

Please sign in to comment.