Skip to content

Commit

Permalink
Fix regex for selector-class-pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Brett Jankord authored and Brett Jankord committed Dec 31, 2016
1 parent bc384fe commit 3a39300
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.1.1

- Fixed: Regex for selector-class-pattern now matches lowercase with hyphens correctly

# 1.1.0

- Added: `scss/dollar-variable-colon-space-after` rule
Expand Down
28 changes: 24 additions & 4 deletions __tests__/selector-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,29 @@ import scssSyntax from "postcss-scss"
import test from "tape"

const invalidScss = (
`.SELECTOR__FORMAT {
`.Foo {
color: #f00;
}
.fooBar {
color: #f00;
}
.fooBar5 {
color: #f00;
}
.foo-Bar {
color: #f00;
}
.foo-Bar---baz {
color: #f00;
}
`)

test("Selector format scss", t => {
t.plan(2)
t.plan(6)

postcss()
.use(stylelint({ code: invalidScss, config: config,}))
Expand All @@ -20,9 +36,13 @@ test("Selector format scss", t => {
.catch(logError)

function checkResult(result) {
t.equal(result.warnings().length, 1, "flags 1 warning")
t.equal(result.warnings().length, 5, "flags 1 warning")
t.is(result.warnings()[0].text, "Selector should be written in lowercase with hyphens (selector-class-pattern)", "correct warning text")
}
t.is(result.warnings()[1].text, "Selector should be written in lowercase with hyphens (selector-class-pattern)", "correct warning text")
t.is(result.warnings()[2].text, "Selector should be written in lowercase with hyphens (selector-class-pattern)", "correct warning text")
t.is(result.warnings()[3].text, "Selector should be written in lowercase with hyphens (selector-class-pattern)", "correct warning text")
t.is(result.warnings()[4].text, "Selector should be written in lowercase with hyphens (selector-class-pattern)", "correct warning text")
}
})

function logError(err) {
Expand Down
84 changes: 84 additions & 0 deletions __tests__/valid-scss.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,90 @@ a:hover {
color: #f00;
}
.foo {
color: #f00;
}
.foo5 {
color: #f00;
}
.foo-5 {
color: #f00;
}
.foo--5 {
color: #f00;
}
.foo-bar {
color: #f00;
}
.foo--bar {
color: #f00;
}
.foo-bar-5 {
color: #f00;
}
.foo-bar-baz {
color: #f00;
}
.foo-bar--baz {
color: #f00;
}
.foo-bar-baz--qux {
color: #f00;
}
.foo-bar--baz--qux {
color: #f00;
}
.foo--bar--baz--qux {
color: #f00;
}
.u-hidden {
color: #f00;
}
.u-class-name {
color: #f00;
}
.is-stateclass {
color: #f00;
}
.has-state-class {
color: #f00;
}
.js-dependantclass {
color: #f00;
}
.namespace-u-text-center {
color: #f00;
}
.namespace-u-sm-size11of12 {
color: #f00;
}
.u-foobar17 {
color: #f00;
}
.u-16by9 {
color: #f00;
}
// Shorthand test
.shorthand {
margin: 1px;
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module.exports = {
"scss/percent-placeholder-pattern": "^[a-z]+([a-z0-9-]+[a-z0-9]+)?$",
"scss/selector-no-redundant-nesting-selector": true,
"selector-class-pattern": [
"^(?:u|is|has)-[a-z][a-zA-Z0-9]*$|^(?!u|is|has)[a-zA-Z][a-zA-Z0-9]*(?:-[a-z][a-zA-Z0-9]*)?(?:--[a-z][a-zA-Z0-9]*)?$",
"^[a-z0-9\\-]+$",
{
"message": "Selector should be written in lowercase with hyphens (selector-class-pattern)"
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stylelint-config-sass-guidelines",
"version": "1.1.0",
"version": "1.1.1",
"description": "Sharable stylelint config based on https://sass-guidelin.es/",
"keywords": [
"stylelint",
Expand Down
2 changes: 1 addition & 1 deletion src/.stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"scss/percent-placeholder-pattern": "^[a-z]+([a-z0-9-]+[a-z0-9]+)?$",
"scss/selector-no-redundant-nesting-selector": true,
"selector-class-pattern": [
"^(?:u|is|has)-[a-z][a-zA-Z0-9]*$|^(?!u|is|has)[a-zA-Z][a-zA-Z0-9]*(?:-[a-z][a-zA-Z0-9]*)?(?:--[a-z][a-zA-Z0-9]*)?$",
"^[a-z0-9\\-]+$",
{
"message": "Selector should be written in lowercase with hyphens (selector-class-pattern)"
}
Expand Down

0 comments on commit 3a39300

Please sign in to comment.