Skip to content

Commit

Permalink
New option: tab-size
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyganch committed Jun 9, 2014
1 parent 3453030 commit 4644605
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 0 deletions.
22 changes: 22 additions & 0 deletions doc/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,28 @@ Example: `{ "strip-spaces": true }`

`a { color: red }\t` → `a { color: red }`

## tab-size

Set tab size (number of spaces to replace hard tabs).

Acceptable values:

* `{Number}` — number of whitespaces;

Example: `{ 'tab-size': 2 }`

```scss
// Before:
a{
color: panda;
}

// After:
a {
color: panda;
}
```

## template

**Note:** See [configuration docs](configuration.md#override-templates-settings)
Expand Down
1 change: 1 addition & 0 deletions lib/csscomb.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var OPTIONS = [
'space-after-opening-brace',
'sort-order',
'block-indent',
'tab-size',
'unitless-zero',
'vendor-prefix-align'
];
Expand Down
16 changes: 16 additions & 0 deletions lib/options/tab-size.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
name: 'tab-size',

accepts: { number: true },

/**
* Processes tree node.
*
* @param {String} nodeType
* @param {node} node
*/
process: function(nodeType, node) {
if (nodeType !== 's') return;
node[0] = node[0].replace(/\t/, this.getValue('tab-size'));
}
};
20 changes: 20 additions & 0 deletions test/options/tab-size.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
describe('options/tab-size:', function() {
beforeEach(function() {
this.filename = __filename;
});

it('Test 1: String value => should not change anything', function() {
this.comb.configure({ 'tab-size': ' ' });
this.shouldBeEqual('test.css');
});

it('Test 2: Float value => should not change anything', function() {
this.comb.configure({ 'tab-size': 4.5 });
this.shouldBeEqual('test.css');
});

it('Test 3: Integer value => should replace tabs with proper number of spaces', function() {
this.comb.configure({ 'tab-size': 4 });
this.shouldBeEqual('test.css', 'test.expected.css');
});
});
4 changes: 4 additions & 0 deletions test/options/tab-size/test.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
a {
color: tomato;
top: 0;
}
4 changes: 4 additions & 0 deletions test/options/tab-size/test.expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
a {
color: tomato;
top: 0;
}

0 comments on commit 4644605

Please sign in to comment.