Skip to content

Commit

Permalink
Block indent: Change acceptable values
Browse files Browse the repository at this point in the history
`block-indent` option now accepts only these kind of values:
    - `{Number}` of spaces;
    - `{String}` of whitespaces and tabs. If there is any other character in the
      string, the value will not be set.
  • Loading branch information
tonyganch committed Dec 3, 2013
1 parent e792f82 commit 91486e0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .csscomb.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"node_modules/**"
],
"always-semicolon": true,
"block-indent": true,
"block-indent": " ",
"colon-space": true,
"color-case": "lower",
"color-shorthand": true,
Expand Down
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Example configuration:
"verbose": true,

"always-semicolon": true,
"block-indent": true,
"block-indent": " ",
"colon-space": true,
"color-case": "lower",
"color-shorthand": true,
Expand Down Expand Up @@ -330,10 +330,10 @@ div {
**Note**: better to use with [rule-indent](#rule-indent)
Available values:
* `{Boolean}` `true` (means 4 spaces)
* `{Number}` of spaces
* `{String}` of whitespace characters (`/[ \t]+/`)
Acceptable values:
* `{Number}` of spaces;
* `{String}` of whitespaces or tabs. If there is any other character in the
string, the value will not be set.
Example: `{ "block-indent": 2 }`
Expand All @@ -351,6 +351,23 @@ a { color: red
}
```
Example: `{ "block-indent": " " }`
```css
/* before */
a { color: red }
@media all { a { color: green } }
/* after */
a { color: red
}
@media all {
a { color: green
}
}
```
### colon-space
Available values:
Expand Down
11 changes: 7 additions & 4 deletions lib/options/block-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ module.exports = {
/**
* Sets handler value.
*
* @param {String|Number|Boolean} value Option value
* @param {String|Number} value Option value
* @returns {Object|undefined}
*/
setValue: function(value) {
delete this._value;
if (value === true) this._value = ' ';
if (typeof value === 'number' && value === Math.abs(Math.round(value)))

if (typeof value === 'number' && value === Math.abs(Math.round(value))) {
this._value = new Array(value + 1).join(' ');
if (typeof value === 'string' && value.match(/^[ \t]+$/)) this._value = value;
} else if (typeof value === 'string' && value.match(/^[ \t]+$/)) {
this._value = value;
}

if (typeof this._value === 'string') return this;
},

Expand Down
25 changes: 12 additions & 13 deletions test/block-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,29 @@ var assert = require('assert');

describe('options/block-indent', function() {
var comb;

beforeEach(function() {
comb = new Comb();
});

it('Invalid Number value should not change space after brace', function() {
var input = 'a { color: red }';
comb.configure({ 'block-indent': 3.5 });
assert.equal(
comb.processString('a { color: red }'),
'a { color: red }'
);
assert.equal(comb.processString(input), input);
});

it('Invalid String value should not change space after brace', function() {
var input = 'a { color: red }';
comb.configure({ 'block-indent': 'foobar' });
assert.equal(
comb.processString('a { color: red }'),
'a { color: red }'
);
assert.equal(comb.processString(input), input);
});
it('True Boolean value should set 4 spaces indent', function() {

it('Boolean value should not change space after brace', function() {
var input = ' \n a { color: red } @media all {.input__control { color: #000;\n}\n}';
comb.configure({ 'block-indent': true });
assert.equal(
comb.processString(' \n a { color: red } @media all {.input__control { color: #000;\n}\n}'),
' \na { color: red \n}\n@media all {\n .input__control { color: #000;\n }\n}'
);
assert.equal(comb.processString(input), input);
});

it('Valid Number value should set equal space after brace', function() {
comb.configure({ 'block-indent': 3 });
assert.equal(
Expand Down

0 comments on commit 91486e0

Please sign in to comment.