postcss / postcss-bem-linter

A BEM linter for postcss
MIT License
572 stars 35 forks source link

[Feature request] Please add Harry robert's style BEM as a Preset. #112

Closed jitendravyas closed 5 years ago

jitendravyas commented 7 years ago

Please add Harry robert's style BEM as a Preset.

https://github.com/postcss/postcss-bem-linter/blob/master/lib/preset-patterns.js

.block {}
.block__element {}
.block--modifier {}
gunnx commented 7 years ago

I set my own componentSelectors

function bemSelectors(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 + '$');
}
ChristianStornowski commented 6 years ago

Original preset-patterns.js looks like

function 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}$`);
}

for function bemSelector but this should as suggested from gunnx like:

function 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}$`);
}

You can look at http://getbem.com/naming/

ausminternet commented 6 years ago

i made a fix here: https://github.com/postcss/postcss-bem-linter/pull/136

simonsmith commented 5 years ago

Closing as fixed