Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix boolean strictbem modifiers #892

Merged
merged 3 commits into from
Oct 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/rules/class-name-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ When enabled, the following are allowed:
.owner-name_mod-name_mod-val {
content: '';
}

.block-name__elem-name_mod-bool {
content: '';
}
```

When enabled, the following are disallowed:
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ helpers.isSnakeCase = function (str) {
* @returns {boolean} Whether str adheres to strict-BEM format
*/
helpers.isStrictBEM = function (str) {
return /^[a-z](\-?[a-z0-9]+)*(__[a-z0-9](\-?[a-z0-9]+)*)?((_[a-z0-9](\-?[a-z0-9]+)*){2})?$/.test(str);
return /^[a-z](\-?[a-z0-9]+)*(__[a-z0-9](\-?[a-z0-9]+)*)?((_[a-z0-9](\-?[a-z0-9]+)*){0,2})?$/.test(str);
};

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/isStrictBEM.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ describe('helpers - isStrictBEM', function () {
done();
});

it('isStrictBEM - [\'abc_def\' - false]', function (done) {
it('isStrictBEM - [\'abc_def\' - true]', function (done) {

var result = helpers.isStrictBEM('abc_def');

assert.equal(false, result);
assert.equal(true, result);
done();
});

Expand Down
36 changes: 18 additions & 18 deletions tests/rules/class-name-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('class name format - scss', function () {
lint.test(file, {
'class-name-format': 1
}, function (data) {
lint.assert.equal(27, data.warningCount);
lint.assert.equal(31, data.warningCount);
done();
});
});
Expand All @@ -26,7 +26,7 @@ describe('class name format - scss', function () {
}
]
}, function (data) {
lint.assert.equal(26, data.warningCount);
lint.assert.equal(30, data.warningCount);
done();
});
});
Expand All @@ -40,7 +40,7 @@ describe('class name format - scss', function () {
}
]
}, function (data) {
lint.assert.equal(36, data.warningCount);
lint.assert.equal(40, data.warningCount);
done();
});
});
Expand All @@ -54,7 +54,7 @@ describe('class name format - scss', function () {
}
]
}, function (data) {
lint.assert.equal(36, data.warningCount);
lint.assert.equal(40, data.warningCount);
done();
});
});
Expand All @@ -68,7 +68,7 @@ describe('class name format - scss', function () {
}
]
}, function (data) {
lint.assert.equal(32, data.warningCount);
lint.assert.equal(36, data.warningCount);
done();
});
});
Expand All @@ -82,7 +82,7 @@ describe('class name format - scss', function () {
}
]
}, function (data) {
lint.assert.equal(22, data.warningCount);
lint.assert.equal(17, data.warningCount);
done();
});
});
Expand All @@ -96,7 +96,7 @@ describe('class name format - scss', function () {
}
]
}, function (data) {
lint.assert.equal(20, data.warningCount);
lint.assert.equal(24, data.warningCount);
done();
});
});
Expand All @@ -110,7 +110,7 @@ describe('class name format - scss', function () {
}
]
}, function (data) {
lint.assert.equal(38, data.warningCount);
lint.assert.equal(42, data.warningCount);
done();
});
});
Expand All @@ -126,7 +126,7 @@ describe('class name format - scss', function () {
}
]
}, function (data) {
lint.assert.equal(34, data.warningCount);
lint.assert.equal(38, data.warningCount);
lint.assert.equal(data.messages[0].message, message);
done();
});
Expand All @@ -143,7 +143,7 @@ describe('class name format - sass', function () {
lint.test(file, {
'class-name-format': 1
}, function (data) {
lint.assert.equal(27, data.warningCount);
lint.assert.equal(31, data.warningCount);
done();
});
});
Expand All @@ -157,7 +157,7 @@ describe('class name format - sass', function () {
}
]
}, function (data) {
lint.assert.equal(26, data.warningCount);
lint.assert.equal(30, data.warningCount);
done();
});
});
Expand All @@ -171,7 +171,7 @@ describe('class name format - sass', function () {
}
]
}, function (data) {
lint.assert.equal(36, data.warningCount);
lint.assert.equal(40, data.warningCount);
done();
});
});
Expand All @@ -185,7 +185,7 @@ describe('class name format - sass', function () {
}
]
}, function (data) {
lint.assert.equal(36, data.warningCount);
lint.assert.equal(40, data.warningCount);
done();
});
});
Expand All @@ -199,7 +199,7 @@ describe('class name format - sass', function () {
}
]
}, function (data) {
lint.assert.equal(32, data.warningCount);
lint.assert.equal(36, data.warningCount);
done();
});
});
Expand All @@ -213,7 +213,7 @@ describe('class name format - sass', function () {
}
]
}, function (data) {
lint.assert.equal(22, data.warningCount);
lint.assert.equal(17, data.warningCount);
done();
});
});
Expand All @@ -227,7 +227,7 @@ describe('class name format - sass', function () {
}
]
}, function (data) {
lint.assert.equal(20, data.warningCount);
lint.assert.equal(24, data.warningCount);
done();
});
});
Expand All @@ -241,7 +241,7 @@ describe('class name format - sass', function () {
}
]
}, function (data) {
lint.assert.equal(38, data.warningCount);
lint.assert.equal(42, data.warningCount);
done();
});
});
Expand All @@ -257,7 +257,7 @@ describe('class name format - sass', function () {
}
]
}, function (data) {
lint.assert.equal(34, data.warningCount);
lint.assert.equal(38, data.warningCount);
lint.assert.equal(data.messages[0].message, message);
done();
});
Expand Down
4 changes: 2 additions & 2 deletions tests/rules/function-name-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('function name format - scss', function () {
}
]
}, function (data) {
lint.assert.equal(13, data.warningCount);
lint.assert.equal(10, data.warningCount);
done();
});
});
Expand Down Expand Up @@ -177,7 +177,7 @@ describe('function name format - sass', function () {
}
]
}, function (data) {
lint.assert.equal(13, data.warningCount);
lint.assert.equal(10, data.warningCount);
done();
});
});
Expand Down
4 changes: 2 additions & 2 deletions tests/rules/mixin-name-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('mixin name format - scss', function () {
}
]
}, function (data) {
lint.assert.equal(13, data.warningCount);
lint.assert.equal(9, data.warningCount);
done();
});
});
Expand Down Expand Up @@ -177,7 +177,7 @@ describe('mixin name format - sass', function () {
}
]
}, function (data) {
lint.assert.equal(13, data.warningCount);
lint.assert.equal(9, data.warningCount);
done();
});
});
Expand Down
4 changes: 2 additions & 2 deletions tests/rules/placeholder-name-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('placeholder name format - scss', function () {
}
]
}, function (data) {
lint.assert.equal(13, data.warningCount);
lint.assert.equal(9, data.warningCount);
done();
});
});
Expand Down Expand Up @@ -185,7 +185,7 @@ describe('placeholder name format - sass', function () {
}
]
}, function (data) {
lint.assert.equal(13, data.warningCount);
lint.assert.equal(9, data.warningCount);
done();
});
});
Expand Down
4 changes: 2 additions & 2 deletions tests/rules/variable-name-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('variable name format - scss', function () {
}
]
}, function (data) {
lint.assert.equal(12, data.warningCount);
lint.assert.equal(9, data.warningCount);
done();
});
});
Expand Down Expand Up @@ -185,7 +185,7 @@ describe('variable name format - sass', function () {
}
]
}, function (data) {
lint.assert.equal(12, data.warningCount);
lint.assert.equal(9, data.warningCount);
done();
});
});
Expand Down
13 changes: 13 additions & 0 deletions tests/sass/class-name-format.sass
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,16 @@
.APascalCase
.camelCase
color: red

// Issue #872 - incorrect strict bem regex
.strict-bem__elem_bool
color: red

.strict-bem__elem_bool-modifier
color: red

.strict-bem__elem_key-val
color: red

.strict-bem__elem_key--fail
color: red
17 changes: 17 additions & 0 deletions tests/sass/class-name-format.scss
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,20 @@
}
}
}

// Issue #872 - incorrect strict bem regex
.strict-bem__elem_bool {
color: red;
}

.strict-bem__elem_bool-modifier {
color: red;
}

.strict-bem__elem_key-val {
color: red;
}

.strict-bem__elem_key--fail {
color: red;
}