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

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

Issue 410603002: web_dev_style: add presubmit for superfluous </include> tags. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/test_presubmit.py ('k') | chrome/browser/web_dev_style/regex_check.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 JS resources. 5 """Presubmit script for Chromium JS resources.
6 6
7 See chrome/browser/PRESUBMIT.py 7 See chrome/browser/PRESUBMIT.py
8 """ 8 """
9 9
10 import regex_check
11
12
10 class JSChecker(object): 13 class JSChecker(object):
11 def __init__(self, input_api, output_api, file_filter=None): 14 def __init__(self, input_api, output_api, file_filter=None):
12 self.input_api = input_api 15 self.input_api = input_api
13 self.output_api = output_api 16 self.output_api = output_api
14 self.file_filter = file_filter 17 self.file_filter = file_filter
15 18
16 def RegexCheck(self, line_number, line, regex, message): 19 def RegexCheck(self, line_number, line, regex, message):
17 """Searches for |regex| in |line| to check for a particular style 20 return regex_check.RegexCheck(
18 violation, returning a message like the one below if the regex matches. 21 self.input_api.re, line_number, line, regex, message)
19 The |regex| must have exactly one capturing group so that the relevant
20 part of |line| can be highlighted. If more groups are needed, use
21 "(?:...)" to make a non-capturing group. Sample message:
22
23 line 6: Use var instead of const.
24 const foo = bar();
25 ^^^^^
26 """
27 match = self.input_api.re.search(regex, line)
28 if match:
29 assert len(match.groups()) == 1
30 start = match.start(1)
31 length = match.end(1) - start
32 return ' line %d: %s\n%s\n%s' % (
33 line_number,
34 message,
35 line,
36 self.error_highlight(start, length))
37 return ''
38 22
39 def ChromeSendCheck(self, i, line): 23 def ChromeSendCheck(self, i, line):
40 """Checks for a particular misuse of 'chrome.send'.""" 24 """Checks for a particular misuse of 'chrome.send'."""
41 return self.RegexCheck(i, line, r"chrome\.send\('[^']+'\s*(, \[\])\)", 25 return self.RegexCheck(i, line, r"chrome\.send\('[^']+'\s*(, \[\])\)",
42 'Passing an empty array to chrome.send is unnecessary') 26 'Passing an empty array to chrome.send is unnecessary')
43 27
44 def ConstCheck(self, i, line): 28 def ConstCheck(self, i, line):
45 """Check for use of the 'const' keyword.""" 29 """Check for use of the 'const' keyword."""
46 if self.input_api.re.search(r'\*\s+@const', line): 30 if self.input_api.re.search(r'\*\s+@const', line):
47 # Probably a JsDoc line 31 # Probably a JsDoc line
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 230
247 if results: 231 if results:
248 results.append(self.output_api.PresubmitNotifyResult( 232 results.append(self.output_api.PresubmitNotifyResult(
249 'See the JavaScript style guide at ' 233 'See the JavaScript style guide at '
250 'http://www.chromium.org/developers/web-development-style-guide' 234 'http://www.chromium.org/developers/web-development-style-guide'
251 '#TOC-JavaScript and if you have any feedback about the JavaScript ' 235 '#TOC-JavaScript and if you have any feedback about the JavaScript '
252 'PRESUBMIT check, contact tbreisacher@chromium.org or ' 236 'PRESUBMIT check, contact tbreisacher@chromium.org or '
253 'dbeam@chromium.org')) 237 'dbeam@chromium.org'))
254 238
255 return results 239 return results
OLDNEW
« no previous file with comments | « chrome/browser/test_presubmit.py ('k') | chrome/browser/web_dev_style/regex_check.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698