Skip to content

Commit 1ade7e6

Browse files
committed
Accept null for all options
1 parent a778b3e commit 1ade7e6

File tree

4 files changed

+59
-12
lines changed

4 files changed

+59
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## 2.0.1
6+
* Accept `null` for all options.
7+
58
## 2.0.0
69
This release completely incompatible with the previous API. There is a lot new options. Please read the documentation.
710

index.js

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function plugin(css, opts) {
4646
}
4747

4848
// Having this option before `properties-order`, because later one can add empty lines by `emptyLineBefore`
49-
if (opts['clean-empty-lines']) {
49+
if (opts['clean-empty-lines'] === true) {
5050
css.walk(function (node) {
5151
if (isRuleWithNodes(node)) {
5252
// Remove empty lines before every node
@@ -64,7 +64,10 @@ function plugin(css, opts) {
6464
});
6565
}
6666

67-
if (opts.order) {
67+
if (
68+
!_.isUndefined(opts.order)
69+
&& !_.isNull(opts.order)
70+
) {
6871
const expectedOrder = createExpectedOrder(opts.order);
6972

7073
css.walk(function (node) {
@@ -96,10 +99,20 @@ function plugin(css, opts) {
9699
});
97100
}
98101

99-
if (opts['properties-order']) {
102+
if (
103+
!_.isUndefined(opts['properties-order'])
104+
&& !_.isNull(opts['properties-order'])
105+
) {
100106
const isAlphabetical = opts['properties-order'] === 'alphabetical';
101107
const expectedOrder = isAlphabetical ? null : createExpectedPropertiesOrder(opts['properties-order']);
102-
const unspecifiedPropertiesPosition = _.get(opts, ['unspecified-properties-position'], 'bottom');
108+
let unspecifiedPropertiesPosition = opts['unspecified-properties-position'];
109+
110+
if (
111+
_.isUndefined(unspecifiedPropertiesPosition)
112+
|| _.isNull(unspecifiedPropertiesPosition)
113+
) {
114+
unspecifiedPropertiesPosition = 'bottom';
115+
}
103116

104117
css.walk(function (node) {
105118
// Process only rules and atrules with nodes
@@ -168,7 +181,10 @@ function plugin(css, opts) {
168181
});
169182
}
170183

171-
if (!_.isUndefined(opts['custom-property-empty-line-before'])) {
184+
if (
185+
!_.isUndefined(opts['custom-property-empty-line-before'])
186+
&& !_.isNull(opts['custom-property-empty-line-before'])
187+
) {
172188
let customPropertyEmptyLineBefore = opts['custom-property-empty-line-before'];
173189

174190
// Convert to common options format, e. g. `true` → `[true]`
@@ -259,7 +275,10 @@ function plugin(css, opts) {
259275
});
260276
}
261277

262-
if (!_.isUndefined(opts['dollar-variable-empty-line-before'])) {
278+
if (
279+
!_.isUndefined(opts['dollar-variable-empty-line-before'])
280+
&& !_.isNull(opts['dollar-variable-empty-line-before'])
281+
) {
263282
let dollarVariableEmptyLineBefore = opts['dollar-variable-empty-line-before'];
264283

265284
// Convert to common options format, e. g. `true` → `[true]`
@@ -350,7 +369,10 @@ function plugin(css, opts) {
350369
});
351370
}
352371

353-
if (!_.isUndefined(opts['declaration-empty-line-before'])) {
372+
if (
373+
!_.isUndefined(opts['declaration-empty-line-before'])
374+
&& !_.isNull(opts['declaration-empty-line-before'])
375+
) {
354376
let declarationEmptyLineBefore = opts['declaration-empty-line-before'];
355377

356378
// Convert to common options format, e. g. `true` → `[true]`
@@ -462,7 +484,10 @@ function plugin(css, opts) {
462484
});
463485
}
464486

465-
if (!_.isUndefined(opts['rule-nested-empty-line-before'])) {
487+
if (
488+
!_.isUndefined(opts['rule-nested-empty-line-before'])
489+
&& !_.isNull(opts['rule-nested-empty-line-before'])
490+
) {
466491
let ruleNestedEmptyLineBefore = opts['rule-nested-empty-line-before'];
467492

468493
// Convert to common options format, e. g. `true` → `[true]`
@@ -556,7 +581,10 @@ function plugin(css, opts) {
556581
});
557582
}
558583

559-
if (!_.isUndefined(opts['at-rule-nested-empty-line-before'])) {
584+
if (
585+
!_.isUndefined(opts['at-rule-nested-empty-line-before'])
586+
&& !_.isNull(opts['at-rule-nested-empty-line-before'])
587+
) {
560588
let atRuleNestedEmptyLineBefore = opts['at-rule-nested-empty-line-before'];
561589

562590
// Convert to common options format, e. g. `true` → `[true]`
@@ -711,7 +739,10 @@ function plugin(css, opts) {
711739
});
712740
}
713741

714-
if (!_.isUndefined(opts['comment-empty-line-before'])) {
742+
if (
743+
!_.isUndefined(opts['comment-empty-line-before'])
744+
&& !_.isNull(opts['comment-empty-line-before'])
745+
) {
715746
let commentEmptyLineBefore = opts['comment-empty-line-before'];
716747

717748
// Convert to common options format, e. g. `true` → `[true]`

lib/validateOptions.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
const _ = require('lodash');
44

55
module.exports = function validateOptions(options) {
6-
if (_.isUndefined(options)) {
6+
if (
7+
_.isUndefined(options)
8+
|| _.isNull(options)
9+
) {
710
return false;
811
}
912

@@ -13,69 +16,79 @@ module.exports = function validateOptions(options) {
1316

1417
if (
1518
!_.isUndefined(options.order)
19+
&& !_.isNull(options.order)
1620
&& !validateOrder(options.order)
1721
) {
1822
return reportInvalidOption('order');
1923
}
2024

2125
if (
2226
!_.isUndefined(options['properties-order'])
27+
&& !_.isNull(options['properties-order'])
2328
&& !validatePropertiesOrder(options['properties-order'])
2429
) {
2530
return reportInvalidOption('properties-order');
2631
}
2732

2833
if (
2934
!_.isUndefined(options['clean-empty-lines'])
35+
&& !_.isNull(options['clean-empty-lines'])
3036
&& !validateCleanEmptyLines(options['clean-empty-lines'])
3137
) {
3238
return reportInvalidOption('clean-empty-lines');
3339
}
3440

3541
if (
3642
!_.isUndefined(options['unspecified-properties-position'])
43+
&& !_.isNull(options['unspecified-properties-position'])
3744
&& !validateUnspecifiedPropertiesPosition(options['unspecified-properties-position'])
3845
) {
3946
return reportInvalidOption('unspecified-properties-position');
4047
}
4148

4249
if (
4350
!_.isUndefined(options['custom-property-empty-line-before'])
51+
&& !_.isNull(options['custom-property-empty-line-before'])
4452
&& !validateCustomPropertyEmptyLineBefore(options['custom-property-empty-line-before'])
4553
) {
4654
return reportInvalidOption('custom-property-empty-line-before');
4755
}
4856

4957
if (
5058
!_.isUndefined(options['dollar-variable-empty-line-before'])
59+
&& !_.isNull(options['dollar-variable-empty-line-before'])
5160
&& !validateDollarVariableEmptyLineBefore(options['dollar-variable-empty-line-before'])
5261
) {
5362
return reportInvalidOption('dollar-variable-empty-line-before');
5463
}
5564

5665
if (
5766
!_.isUndefined(options['declaration-empty-line-before'])
67+
&& !_.isNull(options['declaration-empty-line-before'])
5868
&& !validateDeclarationEmptyLineBefore(options['declaration-empty-line-before'])
5969
) {
6070
return reportInvalidOption('declaration-empty-line-before');
6171
}
6272

6373
if (
6474
!_.isUndefined(options['rule-nested-empty-line-before'])
75+
&& !_.isNull(options['rule-nested-empty-line-before'])
6576
&& !validateRuleNestedEmptyLineBefore(options['rule-nested-empty-line-before'])
6677
) {
6778
return reportInvalidOption('rule-nested-empty-line-before');
6879
}
6980

7081
if (
7182
!_.isUndefined(options['at-rule-nested-empty-line-before'])
83+
&& !_.isNull(options['at-rule-nested-empty-line-before'])
7284
&& !validateAtRuleNestedEmptyLineBefore(options['at-rule-nested-empty-line-before'])
7385
) {
7486
return reportInvalidOption('at-rule-nested-empty-line-before');
7587
}
7688

7789
if (
7890
!_.isUndefined(options['comment-empty-line-before'])
91+
&& !_.isNull(options['comment-empty-line-before'])
7992
&& !validateCommentEmptyLineBefore(options['comment-empty-line-before'])
8093
) {
8194
return reportInvalidOption('comment-empty-line-before');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-sorting",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "PostCSS plugin to keep rules and at-rules content in order.",
55
"keywords": [
66
"postcss",

0 commit comments

Comments
 (0)