Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/browser/web_dev_style/css_checker.py

Issue 1257863004: Just remove --css-mixins: {...}; in presubmit checked contents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/web_dev_style/css_checker_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Presubmit script for Chromium WebUI resources. 5 """Presubmit script for Chromium WebUI resources.
6 6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into depot_tools, and see 8 for more details about the presubmit API built into depot_tools, and see
9 http://www.chromium.org/developers/web-development-style-guide for the rules 9 http://www.chromium.org/developers/web-development-style-guide for the rules
10 we're checking against here. 10 we're checking against here.
(...skipping 15 matching lines...) Expand all
26 return (len(s) == 6 and s[0] == s[1] and s[2] == s[3] and s[4] == s[5]) 26 return (len(s) == 6 and s[0] == s[1] and s[2] == s[3] and s[4] == s[5])
27 27
28 def _is_gray(s): 28 def _is_gray(s):
29 return s[0] == s[1] == s[2] if len(s) == 3 else s[0:2] == s[2:4] == s[4:6] 29 return s[0] == s[1] == s[2] if len(s) == 3 else s[0:2] == s[2:4] == s[4:6]
30 30
31 def _remove_all(s): 31 def _remove_all(s):
32 s = _remove_grit(s) 32 s = _remove_grit(s)
33 s = _remove_ats(s) 33 s = _remove_ats(s)
34 s = _remove_comments(s) 34 s = _remove_comments(s)
35 s = _remove_template_expressions(s) 35 s = _remove_template_expressions(s)
36 s = _remove_mixins(s)
36 return s 37 return s
37 38
38 def _remove_ats(s): 39 def _remove_ats(s):
39 at_reg = re.compile(r""" 40 at_reg = re.compile(r"""
40 @(?!\d+x\b)\w+[^'"]*?{ # @at-keyword selector junk {, not @2x 41 @(?!\d+x\b)\w+[^'"]*?{ # @at-keyword selector junk {, not @2x
41 (.*{.*?})+ # inner { curly } blocks, rules, and selector 42 (.*{.*?})+ # inner { curly } blocks, rules, and selector
42 .*?} # stuff up to the first end curly } 43 .*?} # stuff up to the first end curly }
43 """, 44 """,
44 re.DOTALL | re.VERBOSE) 45 re.DOTALL | re.VERBOSE)
45 return at_reg.sub('\\1', s) 46 return at_reg.sub('\\1', s)
46 47
47 def _remove_comments(s): 48 def _remove_comments(s):
48 return re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', s) 49 return re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', s)
49 50
51 def _remove_mixins(s):
52 return re.sub(re.compile(r'--[\d\w-]+: {.*?};', re.DOTALL), '', s)
53
50 def _remove_template_expressions(s): 54 def _remove_template_expressions(s):
51 return re.sub(re.compile(r'\${[^}]*}', re.DOTALL), '', s) 55 return re.sub(re.compile(r'\${[^}]*}', re.DOTALL), '', s)
52 56
53 def _remove_grit(s): 57 def _remove_grit(s):
54 grit_reg = re.compile(r""" 58 grit_reg = re.compile(r"""
55 <if[^>]+>.*?<\s*/\s*if[^>]*>| # <if> contents </if> 59 <if[^>]+>.*?<\s*/\s*if[^>]*>| # <if> contents </if>
56 <include[^>]+> # <include> 60 <include[^>]+> # <include>
57 """, 61 """,
58 re.DOTALL | re.VERBOSE) 62 re.DOTALL | re.VERBOSE)
59 return re.sub(grit_reg, '', s) 63 return re.sub(grit_reg, '', s)
60 64
61 def _rgb_from_hex(s): 65 def _rgb_from_hex(s):
62 if len(s) == 3: 66 if len(s) == 3:
63 r, g, b = s[0] + s[0], s[1] + s[1], s[2] + s[2] 67 r, g, b = s[0] + s[0], s[1] + s[1], s[2] + s[2]
64 else: 68 else:
65 r, g, b = s[0:2], s[2:4], s[4:6] 69 r, g, b = s[0:2], s[2:4], s[4:6]
66 return int(r, base=16), int(g, base=16), int(b, base=16) 70 return int(r, base=16), int(g, base=16), int(b, base=16)
67 71
68 def _strip_prefix(s): 72 def _strip_prefix(s):
69 return re.sub(r'^-(?:o|ms|moz|khtml|webkit)-', '', s) 73 return re.sub(r'^-(?:o|ms|moz|khtml|webkit)-', '', s)
70 74
71 def alphabetize_props(contents): 75 def alphabetize_props(contents):
72 errors = [] 76 errors = []
77 # TODO(dbeam): make this smart enough to detect issues in mixins.
73 for rule in re.finditer(r'{(.*?)}', contents, re.DOTALL): 78 for rule in re.finditer(r'{(.*?)}', contents, re.DOTALL):
74 semis = map(lambda t: t.strip(), rule.group(1).split(';'))[:-1] 79 semis = map(lambda t: t.strip(), rule.group(1).split(';'))[:-1]
75 rules = filter(lambda r: ': ' in r, semis) 80 rules = filter(lambda r: ': ' in r, semis)
76 props = map(lambda r: r[0:r.find(':')], rules) 81 props = map(lambda r: r[0:r.find(':')], rules)
77 if props != sorted(props): 82 if props != sorted(props):
78 errors.append(' %s;\n' % (';\n '.join(rules))) 83 errors.append(' %s;\n' % (';\n '.join(rules)))
79 return errors 84 return errors
80 85
81 def braces_have_space_before_and_nothing_after(line): 86 def braces_have_space_before_and_nothing_after(line):
82 brace_space_reg = re.compile(r""" 87 brace_space_reg = re.compile(r"""
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) 410 '%s:\n%s' % (f[0], '\n\n'.join(file_errors))))
406 411
407 if results: 412 if results:
408 # Add your name if you're here often mucking around in the code. 413 # Add your name if you're here often mucking around in the code.
409 authors = ['dbeam@chromium.org'] 414 authors = ['dbeam@chromium.org']
410 results.append(self.output_api.PresubmitNotifyResult( 415 results.append(self.output_api.PresubmitNotifyResult(
411 'Was the CSS checker useful? Send feedback or hate mail to %s.' % 416 'Was the CSS checker useful? Send feedback or hate mail to %s.' %
412 ', '.join(authors))) 417 ', '.join(authors)))
413 418
414 return results 419 return results
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/web_dev_style/css_checker_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698