'Hyphenated BEM' regex not behaving as expected
See original GitHub issueI’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:
- Created 7 years ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@karmasalad I’ve written up what I’m currently going with, here: http://www.sumnoise.com/2016/05/26/stylelint-hyphenated-bem-config/
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]+)*)?(?:\\[.+\\])?$"