stylelint-declaration-use-variable icon indicating copy to clipboard operation
stylelint-declaration-use-variable copied to clipboard

feature: Support RegExp matching

Open danschalow opened this issue 4 years ago • 0 comments

The Problem

The problem I would like to solve is the following:

I would like to disallow variables on any properties including the string "color", unless it's a CSS variable. Maybe I'm barking up the wrong tree - is there already a solution for this?

Feature Request

Currently it is possible to configure rules with a regular expression as a string

"sh-waqar/declaration-use-variable": "/color/",

In the stylelint-declaration-use-variable plugin, the following matching is done:

var valueMatches = new RegExp(comparison.slice(1, -1)).test(prop);

This means that you must escape the regular expression in the string in your configuration. With more complex matchings, it can quickly get quite confusing (tbh, I'm not really sure which characters I need to escape, and end up testing with new RegExp):

"sh-waqar/declaration-use-variable": "/^(?!--)[-\\w]*color/",

I would like to be able to set the configuration as such:

"sh-waqar/declaration-use-variable": /^(?!--)[-\w]*color/,

I would like to be able to test my configuration in JavaScript like so:

/^(?!--)[-\w]*color/.test('--dropdown-border-color')

danschalow avatar Feb 11 '21 14:02 danschalow