css: Enforce one selector per line.

While it's sometimes nice to put a few selectors on the same line,
it is generally better to have a consistent way of formatting our
selectors, and most of our code up until now lists them vertically.
This change fixes the linter to enforce one selector per line, and
it cleans up the places in the CSS where we had multiple selectors
on the same line.

The advantages of one-per-line are as followers:
    * cleaner diffs
    * easier to see when multiple areas of the app may have the
      same format
    * less likely to go over 80 cols
    * makes it more clear where we have deep nesting in the
      individual selectors
    * makes it easier for our linting tools to enforce
      whitespace violations

This also fixed an old bug where we had ".landing_page h2, h4", which
sets "h4" styles outside of the landing page.
This commit is contained in:
Steve Howell
2017-03-26 13:24:35 -07:00
committed by showell
parent 3d76088f59
commit c0a6038a95
7 changed files with 70 additions and 44 deletions

View File

@@ -418,15 +418,7 @@ class CssSelectorList(object):
def text(self):
# type: () -> str
res = ''
for i, sel in enumerate(self.selectors):
sel_list_render = sel.text()
if i != 0 and sel_list_render[0] != '\n':
res += ' '
res += sel_list_render
if i != len(self.selectors) - 1:
res += ','
return res
return ',\n'.join(sel.text() for sel in self.selectors)
class CssSelector(object):
def __init__(self, tokens, pre_fluff, post_fluff, levels):
@@ -438,10 +430,7 @@ class CssSelector(object):
def text(self):
# type: () -> str
res = ''
res += handle_prefluff(self.pre_fluff)
res += ' '.join(level.s for level in self.levels)
res += handle_postfluff(self.post_fluff)
res = ' '.join(level.s for level in self.levels)
return res
class CssDeclarationBlock(object):