Skip to content

Instantly share code, notes, and snippets.

@a-tokyo
Created January 26, 2023 19:37
Show Gist options
  • Save a-tokyo/ad6fd401f67ef669924b540b5c00f5d6 to your computer and use it in GitHub Desktop.
Save a-tokyo/ad6fd401f67ef669924b540b5c00f5d6 to your computer and use it in GitHub Desktop.
stylelint-selector-class-pattern-bem
/** Root Stylelint configuration */
module.exports = {
rules: {
/** selector class pattern must match [BEM CSS](https://en.bem.info/methodology/css) - [Regex](https://regexr.com/3apms) */
'selector-class-pattern': [
'^[a-z]([-]?[a-z0-9]+)*(__[a-z0-9]([-]?[a-z0-9]+)*)?(--[a-z0-9]([-]?[a-z0-9]+)*)?$',
{
/** This option will resolve nested selectors with & interpolation. - https://stylelint.io/user-guide/rules/selector-class-pattern/#resolvenestedselectors-true--false-default-false */
resolveNestedSelectors: true,
/** Custom message */
message: function expected(selectorValue) {
return `Expected class selector "${selectorValue}" to match BEM CSS pattern https://en.bem.info/methodology/css. Selector validation tool: https://regexr.com/3apms`;
},
},
],
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment