simonsmith / stylelint-selector-bem-pattern

Stylelint plugin that incorporates postcss-bem-linter
MIT License
244 stars 13 forks source link

{componentName} interpolated just one time #18

Closed AndyOGo closed 8 months ago

AndyOGo commented 7 years ago

This issue will be fixed in postcss-bem-linter: https://github.com/postcss/postcss-bem-linter/pull/96

Though all the update workflow will be necessary.

I just started to write my config according to the docs regarding of interpolation of {componentName}.

But it just works for single interpolations, if I try to interpolate it multiple times, it throws: Error: "^\.{componentName}(?:__{componentName})*(?:--{componentName})?|\.(?:is|has)-{componentName}$" does not produce a valid regular expression

my config

{
  "rules": {
    "plugin/selector-bem-pattern": {
      "componentName": "[a-z0-9]+(?:-[a-z0-9]+)*",
      "componentSelectors": {
        "initial": "^\\.(?:no-)?js|\\.(?:is|has)-{componentName}|\\.{componentName}(?:__{componentName})*(?:--{componentName})?$",
        "combined": "^\\.{componentName}(?:__{componentName})*(?:--{componentName})?|\\.(?:is|has)-{componentName}$"
      }
    },
  }
}

error

/.../node/v5.10.1/bin/node /.../style-guide/node_modules/stylelint/dist/cli.js -f json --stdin-filename header.scss
Error: "^\.{componentName}(?:__{componentName})*(?:--{componentName})?|\.(?:is|has)-{componentName}$" does not produce a valid regular expression
    at /.../style-guide/node_modules/postcss-bem-linter/lib/to-interpolated-regexp.js:8:15
    at module.exports (/.../style-guide/node_modules/postcss-bem-linter/lib/validate-selectors.js:25:61)
    at checkRule (/.../style-guide/node_modules/postcss-bem-linter/index.js:78:7)
    at /.../style-guide/node_modules/postcss-bem-linter/index.js:45:9
    at Array.forEach (native)
    at /.../style-guide/node_modules/postcss-bem-linter/index.js:42:14
    at /.../style-guide/node_modules/postcss/lib/container.js:241:28
    at /.../style-guide/node_modules/postcss/lib/container.js:148:26
    at Root.each (/.../style-guide/node_modules/postcss/lib/container.js:114:22)
    at Root.walk (/.../style-guide/node_modules/postcss/lib/container.js:147:21)

Process finished with exit code 1

Cause of issue

The Issue is caused by https://github.com/postcss/postcss-bem-linter/blob/master/lib/to-interpolated-regexp.js#L6, which should use Array.join() not manual concatenation.