Skip to content

Commit

Permalink
Merge branch 'develop' into feature/issue-813-no-url-protocol-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
danwaz authored Aug 25, 2016
2 parents 1a8d984 + 69efff8 commit 453bac4
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 59 deletions.
4 changes: 4 additions & 0 deletions lib/rules/shorthand-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ var scanValue = function (node) {
fullVal += '#{' + scanValue(val.content) + '}';
}

else if (val.is('color')) {
fullVal += '#' + val.content + '';
}

else if (val.is('operator') || val.is('ident') || val.is('number') || val.is('unaryOperator')) {
fullVal += val.content;
}
Expand Down
66 changes: 38 additions & 28 deletions lib/selector-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ var simpleIdents = [
'attributeMatch'
];

var subSelectors = [
'parentSelectorExtension',
'attributeName',
'attributeValue',
'dimension',
'selector',
'function'
];

/**
* Adds grammar around our content blocks to construct selectors with
* more readable formats.
Expand Down Expand Up @@ -61,36 +70,44 @@ var constructSubSelector = function (val, prefix, suffix, constructSelector) {
var constructSelector = function (val) {
var content = null;

if (val.is('id')) {
content = addGrammar(val, '#', '');
if (val.is('arguments')) {
content = constructSubSelector(val, '(', ')', constructSelector);
}

else if (val.is('atkeyword')) {
content = constructSubSelector(val, '@', '', constructSelector);
}

else if (val.is('attributeSelector')) {
content = constructSubSelector(val, '[', ']', constructSelector);
}

else if (val.is('class')) {
content = addGrammar(val, '.', '');
}

else if (simpleIdents.indexOf(val.type) !== -1) {
content = val.content;
else if (val.is('id')) {
content = addGrammar(val, '#', '');
}

else if (val.is('arguments')) {
content = constructSubSelector(val, '(', ')', constructSelector);
else if (val.is('interpolation')) {
content = constructSubSelector(val, '#{', '}', constructSelector);
}

else if (val.is('attributeSelector')) {
content = constructSubSelector(val, '[', ']', constructSelector);
else if (val.is('nth')) {
content = addGrammar(val, '(', ')');
}

else if (val.is('atkeyword')) {
content = constructSubSelector(val, '@', '', constructSelector);
else if (val.is('nthSelector')) {
content = constructSubSelector(val, ':', '', constructSelector);
}

else if (val.is('placeholder')) {
content = constructSubSelector(val, '%', '', constructSelector);
else if (val.is('parentheses')) {
content = constructSubSelector(val, '(', ')', constructSelector);
}

else if (val.is('variable')) {
content = constructSubSelector(val, '$', '', constructSelector);
else if (val.is('placeholder')) {
content = constructSubSelector(val, '%', '', constructSelector);
}

else if (val.is('pseudoClass')) {
Expand All @@ -101,29 +118,22 @@ var constructSelector = function (val) {
content = addGrammar(val, '::', '');
}

else if (val.is('nth')) {
content = addGrammar(val, '(', ')');
}

else if (val.is('nthSelector')) {
content = constructSubSelector(val, ':', '', constructSelector);
else if (val.is('space')) {
content = ' ';
}

else if (val.is('parentheses')) {
content = constructSubSelector(val, '(', ')', constructSelector);
else if (val.is('variable')) {
content = constructSubSelector(val, '$', '', constructSelector);
}

else if (val.is('space')) {
content = ' ';
else if (simpleIdents.indexOf(val.type) !== -1) {
content = val.content;
}

else if (val.is('parentSelectorExtension') || val.is('attributeName') || val.is('attributeValue') || val.is('dimension')) {
else if (subSelectors.indexOf(val.type) !== -1) {
content = constructSubSelector(val, '', '', constructSelector);
}

else if (val.is('interpolation')) {
content = constructSubSelector(val, '#{', '}', constructSelector);
}
return content;
};

Expand Down
8 changes: 4 additions & 4 deletions tests/rules/no-mergeable-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('no mergeable selectors - scss', function () {
lint.test(file, {
'no-mergeable-selectors': 1
}, function (data) {
lint.assert.equal(22, data.warningCount);
lint.assert.equal(24, data.warningCount);
done();
});
});
Expand All @@ -25,7 +25,7 @@ describe('no mergeable selectors - scss', function () {
}
]
}, function (data) {
lint.assert.equal(21, data.warningCount);
lint.assert.equal(23, data.warningCount);
done();
});
});
Expand All @@ -40,7 +40,7 @@ describe('no mergeable selectors - sass', function () {
lint.test(file, {
'no-mergeable-selectors': 1
}, function (data) {
lint.assert.equal(20, data.warningCount);
lint.assert.equal(21, data.warningCount);
done();
});
});
Expand All @@ -57,7 +57,7 @@ describe('no mergeable selectors - sass', function () {
}
]
}, function (data) {
lint.assert.equal(19, data.warningCount);
lint.assert.equal(20, data.warningCount);
done();
});
});
Expand Down
28 changes: 14 additions & 14 deletions tests/rules/shorthand-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('shorthand values - scss', function () {
lint.test(file, {
'shorthand-values': 1
}, function (data) {
lint.assert.equal(76, data.warningCount);
lint.assert.equal(77, data.warningCount);
done();
});
});
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('shorthand values - scss', function () {
}
]
}, function (data) {
lint.assert.equal(38, data.warningCount);
lint.assert.equal(39, data.warningCount);
done();
});
});
Expand All @@ -60,7 +60,7 @@ describe('shorthand values - scss', function () {
}
]
}, function (data) {
lint.assert.equal(45, data.warningCount);
lint.assert.equal(46, data.warningCount);
done();
});
});
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('shorthand values - scss', function () {
}
]
}, function (data) {
lint.assert.equal(57, data.warningCount);
lint.assert.equal(58, data.warningCount);
done();
});
});
Expand All @@ -109,7 +109,7 @@ describe('shorthand values - scss', function () {
}
]
}, function (data) {
lint.assert.equal(64, data.warningCount);
lint.assert.equal(65, data.warningCount);
done();
});
});
Expand All @@ -126,7 +126,7 @@ describe('shorthand values - scss', function () {
}
]
}, function (data) {
lint.assert.equal(57, data.warningCount);
lint.assert.equal(58, data.warningCount);
done();
});
});
Expand All @@ -144,7 +144,7 @@ describe('shorthand values - scss', function () {
}
]
}, function (data) {
lint.assert.equal(76, data.warningCount);
lint.assert.equal(77, data.warningCount);
done();
});
});
Expand All @@ -161,7 +161,7 @@ describe('shorthand values - sass', function () {
lint.test(file, {
'shorthand-values': 1
}, function (data) {
lint.assert.equal(76, data.warningCount);
lint.assert.equal(77, data.warningCount);
done();
});
});
Expand Down Expand Up @@ -193,7 +193,7 @@ describe('shorthand values - sass', function () {
}
]
}, function (data) {
lint.assert.equal(38, data.warningCount);
lint.assert.equal(39, data.warningCount);
done();
});
});
Expand All @@ -209,7 +209,7 @@ describe('shorthand values - sass', function () {
}
]
}, function (data) {
lint.assert.equal(45, data.warningCount);
lint.assert.equal(46, data.warningCount);
done();
});
});
Expand Down Expand Up @@ -241,7 +241,7 @@ describe('shorthand values - sass', function () {
}
]
}, function (data) {
lint.assert.equal(57, data.warningCount);
lint.assert.equal(58, data.warningCount);
done();
});
});
Expand All @@ -258,7 +258,7 @@ describe('shorthand values - sass', function () {
}
]
}, function (data) {
lint.assert.equal(64, data.warningCount);
lint.assert.equal(65, data.warningCount);
done();
});
});
Expand All @@ -275,7 +275,7 @@ describe('shorthand values - sass', function () {
}
]
}, function (data) {
lint.assert.equal(57, data.warningCount);
lint.assert.equal(58, data.warningCount);
done();
});
});
Expand All @@ -293,7 +293,7 @@ describe('shorthand values - sass', function () {
}
]
}, function (data) {
lint.assert.equal(76, data.warningCount);
lint.assert.equal(77, data.warningCount);
done();
});
});
Expand Down
26 changes: 14 additions & 12 deletions tests/sass/no-mergeable-selectors.sass
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@ ul ~ p
.bar
content: ''

// Issue #834 - selectors/typeselectors not properly recognised
.fake-field
tbody
tr:nth-child(even)
background: lighten($theme-color-primary, 50%)
tr:nth-child(odd)
background: #FFFFFF

.not-test
&:not(:first-child)
border-left: none

&:not(:first-child)
border-left: 2px

.bar
@media (max-width: 40em) and (min-width: 20em) and (orientation: landscape)
Expand Down Expand Up @@ -237,15 +251,3 @@ ul ~ p
// opacity: 1
// Issue #703 - Interpolation in selector - ignored in Sass syntax for now due to gonzales issue
.navigation
@media #{$media-query-lg-up}
.nav-item
display: inline-block
@media #{$media-query-md-down}
// should not merge with the media query above
.nav-item
display: block
// should merge with the ruleset directly above
.nav-item
color: $blue
40 changes: 40 additions & 0 deletions tests/sass/no-mergeable-selectors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,43 @@ ul ~ p {
}
}
}

// issue 826 - media queries with functions
@media(min-width: break('large')) {
.test {
float: left;
}
}

@media(min-width: break('small')) {
.test {
float: left;
}
}

@media(min-width: break('small')) {
.test {
float: none;
}
}

// Issue #834 - selectors/typeselectors not properly recognised
.fake-field {
tbody {
tr:nth-child(even) {
background: lighten($theme-color-primary, 50%);
}
tr:nth-child(odd) {
background: #FFFFFF;
}
}
}

.pseudo-not {
&:not(:first-child) {
border-left: none;
}
&:not(:first-child) {
border-left: 2px;
}
}
7 changes: 7 additions & 0 deletions tests/sass/selector-helpers/selector-helpers.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,10 @@ p:nth-of-type(2) {
color: red;
}
}

tr:nth-child(even) {
background: lighten($theme-color-primary, 50%);
}
tr:nth-child(odd) {
background: #FFFFFF;
}
8 changes: 8 additions & 0 deletions tests/sass/shorthand-values.sass
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,11 @@

.value-four-diff-four-interp-function-mixed
margin: calc(#{$doc-header-height} + #{$global-whitespace--regular}) calc(#{$doc-header-height} + #{$global-whitespace--regular}) calc(#{$doc-header-height} - #{$global-whitespace--regular}) calc(#{$doc-header-height} - #{$global-whitespace--regular})

// issue #772 - Issue with colours not being correctly interpreted
// should be ignored;
.test
border-color: transparent transparent transparent #095b97

.test
border-color: transparent #095b97 transparent #095b97
Loading

0 comments on commit 453bac4

Please sign in to comment.