Skip to content

Commit 3c2e73c

Browse files
committed
Straight order for options
1 parent b5753ad commit 3c2e73c

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

lib/csscomb.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ var vfs = require('vow-fs');
99
* @name Comb
1010
*/
1111
var Comb = function() {
12-
this._options = {
13-
'colon-space': {},
14-
'rule-indent': {},
15-
'sort-order': {},
16-
'stick-brace': {},
17-
'strip-spaces': {}
18-
},
12+
this._handlers;
13+
this._options = [
14+
'strip-spaces',
15+
'stick-brace',
16+
'colon-space',
17+
'rule-indent',
18+
'sort-order'
19+
];
1920
this._config = {};
2021
this._exclude = null;
2122
};
@@ -29,14 +30,18 @@ Comb.prototype = {
2930
* @param {Object} config
3031
*/
3132
configure: function(config) {
32-
for (var option in config) {
33-
if (config.hasOwnProperty(option) && config[option] && this._options[option]) {
33+
var _this = this;
34+
this._handlers = [];
35+
this._options.forEach(function(option) {
36+
if (config[option]) {
3437
try {
3538
var handler = require('./options/' + option).setValue(config[option]);
36-
if (handler) this._config[option] = handler;
37-
} catch (e) {}
39+
handler && _this._handlers.push(handler);
40+
} catch (e) {
41+
throw new Error('Handler ' + option + ' was not found.');
42+
}
3843
}
39-
}
44+
});
4045
this._exclude = (config.exclude || []).map(function(pattern) {
4146
return new minimatch.Minimatch(pattern);
4247
});
@@ -63,11 +68,9 @@ Comb.prototype = {
6368
node.forEach(function(node) {
6469
if (!Array.isArray(node)) return;
6570
var nodeType = node.shift();
66-
for (var option in config) {
67-
if (config.hasOwnProperty(option)) {
68-
config[option].process(nodeType, node);
69-
}
70-
}
71+
_this._handlers.forEach(function(handler) {
72+
handler.process(nodeType, node);
73+
});
7174
node.unshift(nodeType);
7275
_this.processNode(node, level);
7376
});

0 commit comments

Comments
 (0)