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

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

Issue 520303004: Add presubmit check to warn about <label> for usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix check Created 6 years, 3 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/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 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 """ 5 """
6 Presubmit for Chromium HTML/CSS/JS resources. See chrome/browser/PRESUBMIT.py. 6 Presubmit for Chromium HTML resources. See chrome/browser/PRESUBMIT.py.
7 """ 7 """
8 8
9 import regex_check 9 import regex_check
10 10
11 11
12 class ResourceChecker(object): 12 class HtmlChecker(object):
13 def __init__(self, input_api, output_api, file_filter=None): 13 def __init__(self, input_api, output_api, file_filter=None):
14 self.input_api = input_api 14 self.input_api = input_api
15 self.output_api = output_api 15 self.output_api = output_api
16 self.file_filter = file_filter 16 self.file_filter = file_filter
17 17
18 def IncludeCheck(self, line_number, line): 18 def LabelCheck(self, line_number, line):
19 return regex_check.RegexCheck(self.input_api.re, line_number, line, 19 return regex_check.RegexCheck(self.input_api.re, line_number, line,
20 "(</include>)", "</include> is unnecessary. Please remove.") 20 "(for=)",
21 "Avoid 'for' attribute on <label>. Place the input within the <label>, "
22 "or use aria-labelledby for <select>.")
21 23
22 def RunChecks(self): 24 def RunChecks(self):
23 """Check for violations of the Chromium web development style guide. See 25 """Check for violations of the Chromium web development style guide. See
24 http://chromium.org/developers/web-development-style-guide 26 http://chromium.org/developers/web-development-style-guide
25 """ 27 """
26 results = [] 28 results = []
27 29
28 affected_files = self.input_api.change.AffectedFiles( 30 affected_files = self.input_api.change.AffectedFiles(
29 file_filter=self.file_filter, include_deletes=False) 31 file_filter=self.file_filter, include_deletes=False)
30 32
31 for f in affected_files: 33 for f in affected_files:
32 errors = [] 34 errors = []
33 35
34 for line_number, line in enumerate(f.NewContents(), start=1): 36 for line_number, line in f.ChangedContents():
35 error = self.IncludeCheck(line_number, line) 37 error = self.LabelCheck(line_number, line)
36 if error: 38 if error:
37 errors.append(error) 39 errors.append(error)
38 40
39 if errors: 41 if errors:
40 abs_local_path = f.AbsoluteLocalPath() 42 abs_local_path = f.AbsoluteLocalPath()
41 file_indicator = 'Found resources style issues in %s' % abs_local_path 43 file_indicator = 'Found HTML style issues in %s' % abs_local_path
42 prompt_msg = file_indicator + '\n\n' + '\n'.join(errors) + '\n' 44 prompt_msg = file_indicator + '\n\n' + '\n'.join(errors) + '\n'
43 results.append(self.output_api.PresubmitPromptWarning(prompt_msg)) 45 results.append(self.output_api.PresubmitPromptWarning(prompt_msg))
44 46
45 return results 47 return results
OLDNEW
« no previous file with comments | « chrome/browser/PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698