simonsmith / stylelint-selector-bem-pattern

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

Use root if no node for stylelint report for implicitComponents warnings #29

Closed ehzhang closed 7 years ago

ehzhang commented 7 years ago

Hi! Thanks for this plugin!

I've been trying to get implicitComponents to work and have been running into the following error:

TypeError: Cannot read property 'positionBy' of undefined
    at Object.module.exports [as report] (/Users/edwinzhang/co/backend/node_modules/stylelint/lib/utils/report.js:49:33)
    at /Users/edwinzhang/co/backend/node_modules/stylelint-selector-bem-pattern/index.js:57:23
    at Array.forEach (native)
    at /Users/edwinzhang/co/backend/node_modules/stylelint-selector-bem-pattern/index.js:56:23
    at Promise.resolve.then (/Users/edwinzhang/co/backend/node_modules/stylelint/lib/lintSource.js:161:9)
    at <anonymous>

It looks that postcss-bem-linter does not provide a node or a line, as expected by the stylelint.utils.report, causing this line to fail.

I tested this locally and fixes the error in my linter (so the warnings print properly). The change here seemed a bit more appropriate here vs in postcss-bem-linter since this is a stylelint plugin, and the expectation of a node | line is more a stylelint demand than the linter's expectation. What do you think?

ehzhang commented 7 years ago

Also seems like with: https://github.com/davidtheclark/stylelint-selector-bem-pattern/blob/master/package.json#L34

Anyone that is using postcss-bem-linter pre 2.7.0 will be silently failing the implicitComponents check.

davidtheclark commented 7 years ago

Thanks @ehzhang!