postcss / postcss-bem-linter

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

{componentName} interpolated just one time #95

Closed AndyOGo closed 7 years ago

AndyOGo commented 8 years ago

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.

simonsmith commented 7 years ago

Superseded by #102