WordPress-Coding-Standards / stylelint-config-wordpress

WordPress shareable config for stylelint Note: Migrating to Gutenberg repo:

Home Page:https://github.com/WordPress/gutenberg/pull/22777

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is the regex in the 'selector-class-pattern' and 'selector-id-pattern' rules missing something?

sandrab opened this issue · comments

When I run the stylelint, it accepts camelCase selectors, like:

.myDiv {
    color: #fff;
}
#commentForm {
    color: #fff;
}

I would expect these to be caught by the 'selector-class-pattern' and 'selector-id-pattern' rules because the WordPress CSS Coding Standards state to avoid camelCase. But these rules use a regex like this:

'^[a-z]+(-[a-z]+)*'

Could it be the regex in these rules is missing and end indicator? So, should they not end with: $ to avoid any characters after the pattern?

'^[a-z]+(-[a-z]+)*$'

Compare with the examples in the stylelint faq that have the $ at the end as well.

Or is this the desired behaviour? In that case I am obviously missing something.

Sincere apologies @sandrab for not replying before now!

And you are correct, it looks like the regex indeed requires updating.

It looks also like the stylelint docs could do with an update too as the ^([a-z][a-z0-9]*)(-[a-z0-9]+)*$ regex throws warnings for these selector styles and it should not:

h1,
.heading-size-1 {
	font-size: 3.6rem;
	font-weight: 800;
	line-height: 1.138888889;
}

h2,
.heading-size-2 {
	font-size: 3.2rem;
}

h3,
.heading-size-3 {
	font-size: 2.8rem;
}