I have a working example following on from @jeddy3 answer.
This is a copy of my stylelint.config.js
We override the bemSelector()
function taken from https://github.com/postcss/postcss-bem-linter/blob/master/lib/preset-patterns.js
We use two dashes style instead of default BEM by changing the const modifier
to match
https://en.bem.info/methodology/naming-convention/#two-dashes-style
/**
* @param {String} block
* @param {Object} [presetOptions]
* @param {String} [presetOptions.namespace]
* @returns {RegExp}
*/
const bemSelector = (block, presetOptions) => {
const ns = (presetOptions && presetOptions.namespace) ? `${presetOptions.namespace}-` : '';
const WORD = '[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*';
const element = `(?:__${WORD})?`;
const modifier = `(?:--${WORD}){0,2}`;
const attribute = '(?:\\[.+\\])?';
return new RegExp(`^\\.${ns}${block}${element}${modifier}${attribute}$`);
}
module.exports = {
extends: 'stylelint-config-recommended-scss',
plugins: [
'stylelint-selector-bem-pattern'
],
rules: {
'plugin/selector-bem-pattern': {
preset: 'bem',
componentSelectors: bemSelector
}
}
}