Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
Improve validateParameterSeparator rule
Browse files Browse the repository at this point in the history
Fix parameter separator validation

Closes gh-633
  • Loading branch information
davidchambers authored and markelog committed Sep 16, 2014
1 parent 20220f6 commit 15dee23
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/validate-parameter-separator.js
Expand Up @@ -6,7 +6,7 @@ module.exports.prototype = {

configure: function(validateParameterSeparator) {
assert(
typeof validateParameterSeparator === 'string' && / ?, ?/.test(validateParameterSeparator),
typeof validateParameterSeparator === 'string' && /^[ ]?,[ ]?$/.test(validateParameterSeparator),
'validateParameterSpacing option requires string value containing only a comma and optional spaces'
);

Expand Down
29 changes: 29 additions & 0 deletions test/test.validate-parameter-separator.js
Expand Up @@ -9,6 +9,35 @@ describe('rules/validate-parameter-separator', function() {
checker.registerDefaultRules();
});

it('accepts valid separator', function() {
var validSeparators = [
',',
' ,',
', ',
' , ',
];
validSeparators.forEach(function(sep) {
assert.doesNotThrow(function() {
checker.configure({ validateParameterSeparator: sep });
});
});
});

it('rejects invalid separator', function() {
var invalidSeparators = [
'x,',
',x',
'x,x',
' ,',
', ',
];
invalidSeparators.forEach(function(sep) {
assert.throws(function() {
checker.configure({ validateParameterSeparator: sep });
}, assert.AssertionError);
});
});

describe('(comma)', function() {
it('should report unexpected space for function a(b, c) {}', function() {
checker.configure({ validateParameterSeparator: ',' });
Expand Down

0 comments on commit 15dee23

Please sign in to comment.