Skip to content

Commit 790ca4c

Browse files
committed
Use clearer approach for default options
1 parent c445cd2 commit 790ca4c

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

index.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var postcss = require('postcss');
2+
var objectAssign = require('object-assign');
23
var path = require('path');
34
var fs = require('fs');
45

@@ -7,14 +8,16 @@ function verifyOptions(options) {
78
options = {};
89
}
910

10-
options['sort-order'] = options['sort-order'] || 'default';
11-
options['empty-lines-between-children-rules'] = options['empty-lines-between-children-rules'] || 0;
12-
options['empty-lines-between-media-rules'] = options['empty-lines-between-media-rules'] || 0;
13-
options['preserve-empty-lines-between-children-rules'] = options['preserve-empty-lines-between-children-rules'] || false;
14-
options['empty-lines-before-comment'] = options['empty-lines-before-comment'] || 0;
15-
options['empty-lines-after-comment'] = options['empty-lines-after-comment'] || 0;
11+
var defaultOptions = {
12+
'sort-order': 'default',
13+
'empty-lines-between-children-rules': 0,
14+
'empty-lines-between-media-rules': 0,
15+
'preserve-empty-lines-between-children-rules': false,
16+
'empty-lines-before-comment': 0,
17+
'empty-lines-after-comment': 0,
18+
};
1619

17-
return options;
20+
return objectAssign({}, defaultOptions, options);
1821
}
1922

2023
function getSortOrderFromOptions(options) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"index.js"
2222
],
2323
"dependencies": {
24+
"object-assign": "^4.1.0",
2425
"postcss": "^5.1.2"
2526
},
2627
"devDependencies": {

test/test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,11 @@ test('Should sort at-rules by name', t => {
214214
});
215215

216216
test('Should use default config if config is empty', t => {
217-
return run(t, 'without-specified-config');
217+
return run(t, 'without-specified-config', null);
218+
});
219+
220+
test('Should use default config if config isn\'t an object', t => {
221+
return run(t, 'without-specified-config', 'config');
218222
});
219223

220224
test('Should sort prefixed propertyes as unprefixed if first one not in order, but second one in', t => {

0 commit comments

Comments
 (0)