Skip to content

Commit

Permalink
Fixed multiple issues due to not(:something) syntax
Browse files Browse the repository at this point in the history
Fixed #618
Fixed #786
Fixed #952
  • Loading branch information
bitwiseman committed Aug 7, 2016
1 parent 320171b commit 785e70d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
3 changes: 2 additions & 1 deletion js/lib/beautify-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@
} else if (ch === ":") {
eatWhitespace();
if ((insideRule || enteringConditionalGroup) &&
!(lookBack("&") || foundNestedPseudoClass())) {
!(lookBack("&") || foundNestedPseudoClass()) &&
!lookBack("(")) {
// 'property: value' delimiter
// which could be in a conditional group query
insidePropertyValue = true;
Expand Down
9 changes: 9 additions & 0 deletions js/test/generated/beautify-css-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,15 @@ function run_css_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_bea
'\twidth: calc((100% - ((#{$items} - 1) * #{$margin}rem)) / #{$items});\n' +
'\tmargin: 1.6rem #{$margin}rem 1.6rem 0;\n' +
'}');

// Multiple filed issues in LESS due to not(:blah)
t('&:first-of-type:not(:last-child) {}');
t(
'div {\n' +
'\t&:not(:first-of-type) {\n' +
'\t\tbackground: red;\n' +
'\t}\n' +
'}');


reset_options();
Expand Down
5 changes: 3 additions & 2 deletions python/cssbeautifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __repr__(self):
newline_between_rules = [%s]
space_around_selector_separator = [%s]
""" % (self.indent_size, self.indent_char, self.indent_with_tabs,
self.selector_separator_newline, self.end_with_newline, self.newline_between_rules,
self.selector_separator_newline, self.end_with_newline, self.newline_between_rules,
self.space_around_selector_separator)


Expand Down Expand Up @@ -400,7 +400,8 @@ def beautify(self):
elif self.ch == ":":
self.eatWhitespace()
if (insideRule or enteringConditionalGroup) and \
not (self.lookBack('&') or self.foundNestedPseudoClass()):
not (self.lookBack('&') or self.foundNestedPseudoClass()) and \
not self.lookBack('('):
# 'property: value' delimiter
# which could be in a conditional group query
insidePropertyValue = True
Expand Down
9 changes: 9 additions & 0 deletions python/cssbeautifier/tests/generated/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@ def testGenerated(self):
'\twidth: calc((100% - ((#{$items} - 1) * #{$margin}rem)) / #{$items});\n' +
'\tmargin: 1.6rem #{$margin}rem 1.6rem 0;\n' +
'}')

# Multiple filed issues in LESS due to not(:blah)
t('&:first-of-type:not(:last-child) {}')
t(
'div {\n' +
'\t&:not(:first-of-type) {\n' +
'\t\tbackground: red;\n' +
'\t}\n' +
'}')


self.reset_options();
Expand Down
14 changes: 14 additions & 0 deletions test/data/css/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,21 @@ exports.test_data = {
'\tmargin: 1.6rem #{$margin}rem 1.6rem 0;',
'}'
]
},
{
comment: "Multiple filed issues in LESS due to not(:blah)",
unchanged: '&:first-of-type:not(:last-child) {}'
},
{
unchanged: [
'div {',
'\t&:not(:first-of-type) {',
'\t\tbackground: red;',
'\t}',
'}',
]
}

],
}, {

Expand Down

0 comments on commit 785e70d

Please sign in to comment.