Skip to content

Commit 33cd254

Browse files
committed
Return an empty array instead of null
`forEach` won't iterate over an empty array so this is better than returning a falsey value and checking for it.
1 parent 199ceab commit 33cd254

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

lib/validate-selectors.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function getSelectors(rule) {
4141
// Skip validation on rules with no declarations
4242
// as these don't exist after rules have been unwrapped
4343
if (hasNoDeclarations(rule)) {
44-
return null;
44+
return [];
4545
}
4646

4747
if (isNestedRule(rule)) {
@@ -75,8 +75,6 @@ module.exports = function(config) {
7575
: toInterpoloatedRegexp(initialPattern);
7676
var selectors = getSelectors(rule);
7777

78-
if (!selectors) {return;}
79-
8078
selectors.forEach(function(selector) {
8179
// Don't bother with :root
8280
if (selector === ':root') return;

test/nesting.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('getSelectors function', function() {
2222
componentRoot.append({selector: '.Component-d'});
2323
componentRoot.append({text: 'comment'});
2424

25-
assert.deepEqual(getSelectors(componentRoot), null);
25+
assert.deepEqual(getSelectors(componentRoot), []);
2626
});
2727

2828
it('should return a selector if the ruleset has declarations', function() {
@@ -56,8 +56,8 @@ describe('getSelectors function', function() {
5656
descendant.append([hover, state]);
5757
componentRoot.append(descendant);
5858

59-
assert.deepEqual(getSelectors(componentRoot), null);
60-
assert.deepEqual(getSelectors(descendant), null);
59+
assert.deepEqual(getSelectors(componentRoot), []);
60+
assert.deepEqual(getSelectors(descendant), []);
6161
assert.deepEqual(getSelectors(hover), ['.Component .Component-d:hover']);
6262
assert.deepEqual(getSelectors(state), ['.Component .Component-d.is-active']);
6363
});
@@ -70,7 +70,7 @@ describe('getSelectors function', function() {
7070
componentRoot.append([hover, state]);
7171
root.append(componentRoot);
7272

73-
assert.deepEqual(getSelectors(componentRoot), null);
73+
assert.deepEqual(getSelectors(componentRoot), []);
7474
assert.deepEqual(getSelectors(hover), ['.Component:hover', '.Component-d:hover']);
7575
assert.deepEqual(getSelectors(state), ['.Component.is-active', '.Component-d.is-active']);
7676
});
@@ -97,7 +97,7 @@ describe('getSelectors function', function() {
9797
componentRoot.append(rule);
9898
media.append(componentRoot);
9999

100-
assert.deepEqual(getSelectors(componentRoot), null);
100+
assert.deepEqual(getSelectors(componentRoot), []);
101101
assert.deepEqual(getSelectors(rule), ['.Component .Component-d']);
102102
});
103103
});
@@ -110,7 +110,7 @@ describe('getSelectors function', function() {
110110
componentRoot.append(media);
111111

112112
assert.deepEqual(getSelectors(rule), ['.Component .Component-d']);
113-
assert.deepEqual(getSelectors(componentRoot), null);
113+
assert.deepEqual(getSelectors(componentRoot), []);
114114
});
115115

116116
it('should return a selector for a ruleset with declarations and nested media query', function() {

0 commit comments

Comments
 (0)