Skip to content

Commit

Permalink
add more namespace tests - change of error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ernscht committed Jul 6, 2016
1 parent 1722354 commit ded41b7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ module.exports = stylelint.createPlugin(ruleName, function(options) {
}
var prefix = className.split('-')[0];
if (className.indexOf('-') === -1 || validPrefixes.indexOf(prefix) === -1) {
return 'start with a valid prefix: "' + namespace + validPrefixes.join('", "' + namespace) + '"'
return 'start with a valid prefix: "' + namespace + validPrefixes.join('-", "' + namespace) + '-"'
}
if (validHelpers.indexOf(prefix) !== -1) {
var subPrefix = className.split('-')[1];
if (validComponents.indexOf(subPrefix) === -1) {
return 'use ' + namespace + prefix + '-[prefix]-[block] syntax. Valid ' + namespace + prefix + ' prefixes: "' + namespace +
validComponents.map(function(component) {
return prefix + '-' + component;
}).join('", "' + namespace) + '"';
}).join('-", "' + namespace) + '-"';
}
}
if (/__(_|.*__)/.test(className)) {
Expand Down
22 changes: 15 additions & 7 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ testRule(plugin.rule, {
reject: [
{
code: '.z-block {}',
message: 'Expected class name "z-block" to start with a valid prefix: "a", "m", "o", "l", "g", "h", "state". (' + plugin.ruleName + ')',
message: 'Expected class name "z-block" to start with a valid prefix: "a-", "m-", "o-", "l-", "g-", "h-", "state-". (' + plugin.ruleName + ')',
},
{
code: '.0-block {}',
message: 'Expected class name "0-block" to start with a valid prefix: "a", "m", "o", "l", "g", "h", "state". (' + plugin.ruleName + ')',
message: 'Expected class name "0-block" to start with a valid prefix: "a-", "m-", "o-", "l-", "g-", "h-", "state-". (' + plugin.ruleName + ')',
},
{
code: '.-block {}',
message: 'Expected class name "-block" to start with a valid prefix: "a", "m", "o", "l", "g", "h", "state". (' + plugin.ruleName + ')',
message: 'Expected class name "-block" to start with a valid prefix: "a-", "m-", "o-", "l-", "g-", "h-", "state-". (' + plugin.ruleName + ')',
},
{
code: '.--block {}',
message: 'Expected class name "--block" to start with a valid prefix: "a", "m", "o", "l", "g", "h", "state". (' + plugin.ruleName + ')',
message: 'Expected class name "--block" to start with a valid prefix: "a-", "m-", "o-", "l-", "g-", "h-", "state-". (' + plugin.ruleName + ')',
},
{
code: '.a-block___x {}',
Expand All @@ -75,7 +75,7 @@ testRule(plugin.rule, {
},
{
code: '.state-block {}',
message: 'Expected class name "state-block" to use state-[prefix]-[block] syntax. Valid state prefixes: "state-a", "state-m", "state-o", "state-l", "state-g", "state-h". (' + plugin.ruleName + ')',
message: 'Expected class name "state-block" to use state-[prefix]-[block] syntax. Valid state prefixes: "state-a-", "state-m-", "state-o-", "state-l-", "state-g-", "state-h-". (' + plugin.ruleName + ')',
},
{
code: '.state-a-block {}',
Expand Down Expand Up @@ -132,11 +132,19 @@ testRule(plugin.rule, {
},
{
code: '.namespace-z-block {}',
message: 'Expected class name "namespace-z-block" to start with a valid prefix: "namespace-a", "namespace-m", "namespace-o", "namespace-l", "namespace-g", "namespace-h", "namespace-state". (' + plugin.ruleName + ')',
message: 'Expected class name "namespace-z-block" to start with a valid prefix: "namespace-a-", "namespace-m-", "namespace-o-", "namespace-l-", "namespace-g-", "namespace-h-", "namespace-state-". (' + plugin.ruleName + ')',
},
{
code: '.namespace-z-block__element {}',
message: 'Expected class name "namespace-z-block__element" to start with a valid prefix: "namespace-a-", "namespace-m-", "namespace-o-", "namespace-l-", "namespace-g-", "namespace-h-", "namespace-state-". (' + plugin.ruleName + ')',
},
{
code: '.namespace-state-m__element {}',
message: 'Expected class name "namespace-state-m__element" to use namespace-state-[prefix]-[block] syntax. Valid namespace-state prefixes: "namespace-state-a-", "namespace-state-m-", "namespace-state-o-", "namespace-state-l-", "namespace-state-g-", "namespace-state-h-". (' + plugin.ruleName + ')',
},
{
code: '.namespace-state-block {}',
message: 'Expected class name "namespace-state-block" to use namespace-state-[prefix]-[block] syntax. Valid namespace-state prefixes: "namespace-state-a", "namespace-state-m", "namespace-state-o", "namespace-state-l", "namespace-state-g", "namespace-state-h". (' + plugin.ruleName + ')',
message: 'Expected class name "namespace-state-block" to use namespace-state-[prefix]-[block] syntax. Valid namespace-state prefixes: "namespace-state-a-", "namespace-state-m-", "namespace-state-o-", "namespace-state-l-", "namespace-state-g-", "namespace-state-h-". (' + plugin.ruleName + ')',
},
{
code: '.namespace-state-a-block {}',
Expand Down

0 comments on commit ded41b7

Please sign in to comment.