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

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

Issue 882243004: web_dev_style: allow 0ms or 0s while we hash out the breakage of crbug.com/454776 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 | « chrome/browser/test_presubmit.py ('k') | no next file » | 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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 webkit_before_or_after_reg = re.compile(r'-webkit-(\w+-)(after|before):') 251 webkit_before_or_after_reg = re.compile(r'-webkit-(\w+-)(after|before):')
252 252
253 def suggest_top_or_bottom(line): 253 def suggest_top_or_bottom(line):
254 prop, pos = webkit_before_or_after_reg.search(line).groups() 254 prop, pos = webkit_before_or_after_reg.search(line).groups()
255 top_or_bottom = 'top' if pos == 'before' else 'bottom' 255 top_or_bottom = 'top' if pos == 'before' else 'bottom'
256 return ' (replace with %s)' % (prop + top_or_bottom) 256 return ' (replace with %s)' % (prop + top_or_bottom)
257 257
258 def webkit_before_or_after(line): 258 def webkit_before_or_after(line):
259 return webkit_before_or_after_reg.search(line) 259 return webkit_before_or_after_reg.search(line)
260 260
261 def zero_length_values(contents): 261 def zero_width_lengths(contents):
262 hsl_reg = re.compile(r""" 262 hsl_reg = re.compile(r"""
263 hsl\([^\)]* # hsl(<maybe stuff> 263 hsl\([^\)]* # hsl(<maybe stuff>
264 (?:[, ]|(?<=\()) # a comma or space not followed by a ( 264 (?:[, ]|(?<=\()) # a comma or space not followed by a (
265 (?:0?\.?)?0% # some equivalent to 0%""", 265 (?:0?\.?)?0% # some equivalent to 0%""",
266 re.VERBOSE) 266 re.VERBOSE)
267 zeros_reg = re.compile(r""" 267 zeros_reg = re.compile(r"""
268 ^.*(?:^|[^0-9.]) # start/non-number 268 ^.*(?:^|[^0-9.]) # start/non-number
269 (?:\.0|0(?:\.0? # .0, 0, or 0.0 269 (?:\.0|0(?:\.0? # .0, 0, or 0.0
270 |px|em|%|in|cm|mm|pc|pt|ex|deg|g?rad|m?s|k?hz)) # a length unit 270 |px|em|%|in|cm|mm|pc|pt|ex)) # a length unit
Dan Beam 2015/02/03 16:09:16 this is the functional change
271 (?:\D|$) # non-number/end 271 (?:\D|$) # non-number/end
272 (?=[^{}]+?}).*$ # only { rules }""", 272 (?=[^{}]+?}).*$ # only { rules }""",
273 re.MULTILINE | re.VERBOSE) 273 re.MULTILINE | re.VERBOSE)
274 errors = [] 274 errors = []
275 for z in re.finditer(zeros_reg, contents): 275 for z in re.finditer(zeros_reg, contents):
276 first_line = z.group(0).strip().splitlines()[0] 276 first_line = z.group(0).strip().splitlines()[0]
277 if not hsl_reg.search(first_line): 277 if not hsl_reg.search(first_line):
278 errors.append(' ' + first_line) 278 errors.append(' ' + first_line)
279 return errors 279 return errors
280 280
281 # NOTE: Currently multi-line checks don't support 'after'. Instead, add 281 # NOTE: Currently multi-line checks don't support 'after'. Instead, add
282 # suggestions while parsing the file so another pass isn't necessary. 282 # suggestions while parsing the file so another pass isn't necessary.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 'multiline': True, 329 'multiline': True,
330 }, 330 },
331 { 'desc': 'Use rgb() over #hex when not a shade of gray (like #333).', 331 { 'desc': 'Use rgb() over #hex when not a shade of gray (like #333).',
332 'test': rgb_if_not_gray, 332 'test': rgb_if_not_gray,
333 'after': suggest_rgb_from_hex, 333 'after': suggest_rgb_from_hex,
334 }, 334 },
335 { 'desc': 'Use *-top/bottom instead of -webkit-*-before/after.', 335 { 'desc': 'Use *-top/bottom instead of -webkit-*-before/after.',
336 'test': webkit_before_or_after, 336 'test': webkit_before_or_after,
337 'after': suggest_top_or_bottom, 337 'after': suggest_top_or_bottom,
338 }, 338 },
339 { 'desc': 'Make all zero length terms (i.e. 0px) 0 unless inside of ' 339 { 'desc': 'Use "0" for zero-width lengths (i.e. 0px -> 0)',
340 'hsl() or part of @keyframe.', 340 'test': zero_width_lengths,
341 'test': zero_length_values,
342 'multiline': True, 341 'multiline': True,
343 }, 342 },
344 ] 343 ]
345 344
346 results = [] 345 results = []
347 affected_files = self.input_api.AffectedFiles(include_deletes=False, 346 affected_files = self.input_api.AffectedFiles(include_deletes=False,
348 file_filter=self.file_filter) 347 file_filter=self.file_filter)
349 files = [] 348 files = []
350 for f in affected_files: 349 for f in affected_files:
351 # Remove all /*comments*/, @at-keywords, and grit <if|include> tags; we're 350 # Remove all /*comments*/, @at-keywords, and grit <if|include> tags; we're
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 '%s:\n%s' % (f[0], '\n\n'.join(file_errors)))) 382 '%s:\n%s' % (f[0], '\n\n'.join(file_errors))))
384 383
385 if results: 384 if results:
386 # Add your name if you're here often mucking around in the code. 385 # Add your name if you're here often mucking around in the code.
387 authors = ['dbeam@chromium.org'] 386 authors = ['dbeam@chromium.org']
388 results.append(self.output_api.PresubmitNotifyResult( 387 results.append(self.output_api.PresubmitNotifyResult(
389 'Was the CSS checker useful? Send feedback or hate mail to %s.' % 388 'Was the CSS checker useful? Send feedback or hate mail to %s.' %
390 ', '.join(authors))) 389 ', '.join(authors)))
391 390
392 return results 391 return results
OLDNEW
« no previous file with comments | « chrome/browser/test_presubmit.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698