Skip to content

Commit

Permalink
Allow options to accepts different boolean values
Browse files Browse the repository at this point in the history
If you want an option to accept `true` value and reject `false`:

    accepts: { boolean: [true] }

If you want an option to accept any boolean value:

    accepts: { boolean: [true, false] }
  • Loading branch information
tonyganch committed Jun 9, 2014
1 parent ff11557 commit fa20869
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 42 deletions.
2 changes: 2 additions & 0 deletions lib/csscomb.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ var Comb = function(config) {

switch (valueType) {
case 'boolean':
if (pattern.indexOf(value) < 0) throw new Error(' Value must be ' +
'one of the following: ' + pattern.join(', ') + '.');
return value;
case 'number':
if (value !== parseInt(value)) throw new Error('Value must be an integer.');
Expand Down
10 changes: 1 addition & 9 deletions lib/options/always-semicolon.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
module.exports = {
name: 'always-semicolon',

/**
* Sets handler value.
* @param {Boolean} value Option value
* @returns {Boolean}
*/
setValue: function(value) {
if (value !== true) throw new Error('The option accepts only `true` value.');
return value;
},
accepts: { boolean: [true] },

/**
* Processes tree node.
Expand Down
2 changes: 1 addition & 1 deletion lib/options/color-shorthand.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
name: 'color-shorthand',

accepts: { boolean: true },
accepts: { boolean: [true, false] },

/**
* Processes tree node.
Expand Down
2 changes: 1 addition & 1 deletion lib/options/eof-newline.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
name: 'eof-newline',

accepts: { boolean: true },
accepts: { boolean: [true, false] },

/**
* Processes tree node.
Expand Down
2 changes: 1 addition & 1 deletion lib/options/leading-zero.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
name: 'leading-zero',

accepts: { boolean: true },
accepts: { boolean: [true, false] },

/**
* Processes tree node.
Expand Down
11 changes: 1 addition & 10 deletions lib/options/remove-empty-rulesets.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,7 @@ module.exports = (function() {
return {
name: 'remove-empty-rulesets',

/**
* Sets handler value.
*
* @param {Boolean} value Option value
* @returns {Boolean}
*/
setValue: function(value) {
if (value !== true) throw new Error('The option accepts only `true` value.');
return value;
},
accepts: { boolean: [true] },

/**
* Remove rulesets with no declarations.
Expand Down
11 changes: 1 addition & 10 deletions lib/options/strip-spaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,7 @@ module.exports = (function() {
return {
name: 'strip-spaces',

/**
* Sets handler value.
*
* @param {Boolean} value Option value
* @returns {Boolean}
*/
setValue: function(value) {
if (value !== true) throw new Error('The option accepts only `true` value.');
return value;
},
accepts: { boolean: [true] },

/**
* Processes tree node.
Expand Down
11 changes: 1 addition & 10 deletions lib/options/unitless-zero.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
module.exports = {
name: 'unitless-zero',

/**
* Sets handler value.
*
* @param {Boolean} value Option value
* @returns {Boolean}
*/
setValue: function(value) {
if (value !== true) throw new Error('The option accepts only `true` value.');
return value;
},
accepts: { boolean: [true] },

/**
* Processes tree node.
Expand Down

0 comments on commit fa20869

Please sign in to comment.