question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'Hyphenated BEM' regex not behaving as expected

See original GitHub issue

I’m trying to emulate the ‘hyphenated BEM’ selector format from scss-lint, but the regex I’ve got doesn’t work in the context of the plugin (I’m fairly sure the regex itself is sound – it behaves as expected if I run it through e.g. regexper

Here’s my componentSelectors property:

"componentSelectors": {
  "initial": "^\\.{componentName}(((__|--)(([a-z0-9]+(?!-$)-?)+))+)?"
}

If I’ve defined a article-intro, then I would expect e.g. article-intro__heading or article-intro--primary to be good matches, and article-intro-_ to be an error, but the linter isn’t currently complaining at all about .article-intro-_. Any ideas?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
davidpmccormickcommented, Jul 12, 2016

@karmasalad I’ve written up what I’m currently going with, here: http://www.sumnoise.com/2016/05/26/stylelint-hyphenated-bem-config/

0reactions
coreybruyerecommented, Oct 21, 2016

Ok, ignore my last comment. It wasn’t bem-linter giving me that error. I’m extending another config with a rule assigned to “selector-class-pattern”. I used this to override that rule: "selector-class-pattern": "^(?:(?:o|c|u|t|s|is|has|_|js|qa)-)?[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*(?:__[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*)?(?:--[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*)?(?:\\[.+\\])?$"

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating Javascript RegEx to validate hyphenated BEM and ...
I have this Regex for detecting hyphenatedBEM in CSS files ... you add some example strings to be matched and some others not...
Read more >
The search for a Regex to match Hyphenated BEM CSS class ...
Before starting the search, we created a test-case that outlined what should and should not be matched. The BEM entities that are available...
Read more >
UTS #18: Unicode Regular Expressions
Unicode is a large character set—regular expression engines that are only adapted to handle small character sets will not scale well.
Read more >
Everything you need to know about Regular Expressions
After reading this article you will have a solid understanding of what regular expressions are, what they can do, and what they can't...
Read more >
Using regex | Stylelint
You can use regex in the ignore* secondary options and following classes of ... that start with a digit, two hyphens, or a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found