Commit 422789b6 authored by estade's avatar estade Committed by Commit bot

Add presubmit check to warn about <label> for attribute usage.

BUG=409938
NOTRY=true

Review URL: https://codereview.chromium.org/520303004

Cr-Commit-Position: refs/heads/master@{#293601}
parent e5d4ccbd
......@@ -35,6 +35,7 @@ def _CommonChecks(input_api, output_api):
path.join(cwd, 'PRESUBMIT.py'),
path.join(cwd, 'test_presubmit.py'),
path.join(cwd, 'web_dev_style', 'css_checker.py'),
path.join(cwd, 'web_dev_style', 'html_checker.py'),
path.join(cwd, 'web_dev_style', 'js_checker.py'),
)
if any(f for f in affected_files if f in would_affect_tests):
......@@ -47,7 +48,8 @@ def _CommonChecks(input_api, output_api):
try:
sys.path = [cwd] + old_path
from web_dev_style import resource_checker, css_checker, js_checker
from web_dev_style import (resource_checker, css_checker, html_checker,
js_checker)
search_dirs = (resources, webui)
def _html_css_js_resource(p):
......@@ -63,6 +65,8 @@ def _CommonChecks(input_api, output_api):
input_api, output_api, file_filter=is_resource).RunChecks())
results.extend(css_checker.CSSChecker(
input_api, output_api, file_filter=is_resource).RunChecks())
results.extend(html_checker.HtmlChecker(
input_api, output_api, file_filter=is_resource).RunChecks())
results.extend(js_checker.JSChecker(
input_api, output_api, file_filter=is_resource).RunChecks())
finally:
......
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Presubmit for Chromium HTML resources. See chrome/browser/PRESUBMIT.py.
"""
import regex_check
class HtmlChecker(object):
def __init__(self, input_api, output_api, file_filter=None):
self.input_api = input_api
self.output_api = output_api
self.file_filter = file_filter
def LabelCheck(self, line_number, line):
return regex_check.RegexCheck(self.input_api.re, line_number, line,
"(for=)",
"Avoid 'for' attribute on <label>. Place the input within the <label>, "
"or use aria-labelledby for <select>.")
def RunChecks(self):
"""Check for violations of the Chromium web development style guide. See
http://chromium.org/developers/web-development-style-guide
"""
results = []
affected_files = self.input_api.change.AffectedFiles(
file_filter=self.file_filter, include_deletes=False)
for f in affected_files:
errors = []
for line_number, line in f.ChangedContents():
error = self.LabelCheck(line_number, line)
if error:
errors.append(error)
if errors:
abs_local_path = f.AbsoluteLocalPath()
file_indicator = 'Found HTML style issues in %s' % abs_local_path
prompt_msg = file_indicator + '\n\n' + '\n'.join(errors) + '\n'
results.append(self.output_api.PresubmitPromptWarning(prompt_msg))
return results
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment