Commit 0ab2d066 authored by levin@chromium.org's avatar levin@chromium.org
Browse files

2011-02-15 David Levin <levin@chromium.org>

        Reviewed by Shinichiro Hamaji.

        check-webkit-style should do some detection for valid uses of WEBKIT_API (in chromium public api).
        https://bugs.webkit.org/show_bug.cgi?id=52271

        * Scripts/webkitpy/style/checkers/cpp.py: Added the check for WEBKIT_API usage.
        * Scripts/webkitpy/style/checkers/cpp_unittest.py: Added tests.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@78545 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f29a05b2
2011-02-15 David Levin <levin@chromium.org>
Reviewed by Shinichiro Hamaji.
check-webkit-style should do some detection for valid uses of WEBKIT_API (in chromium public api).
https://bugs.webkit.org/show_bug.cgi?id=52271
* Scripts/webkitpy/style/checkers/cpp.py: Added the check for WEBKIT_API usage.
* Scripts/webkitpy/style/checkers/cpp_unittest.py: Added tests.
2011-02-14 Dirk Pranke <dpranke@chromium.org>
 
Unreviewed, build fix.
......@@ -1565,21 +1565,40 @@ def _check_parameter_name_against_text(parameter, text, error):
return True
def check_function_definition(clean_lines, line_number, function_state, error):
def check_function_definition(filename, file_extension, clean_lines, line_number, function_state, error):
"""Check that function definitions for style issues.
Specifically, check that parameter names in declarations add information.
Args:
filename: Filename of the file that is being processed.
file_extension: The current file extension, without the leading dot.
clean_lines: A CleansedLines instance containing the file.
line_number: The number of the line to check.
function_state: Current function name and lines in body so far.
error: The function to call with any errors found.
"""
# Only do checks when we have a function declaration.
if line_number != function_state.body_start_position.row or not function_state.is_declaration:
if line_number != function_state.body_start_position.row:
return
modifiers_and_return_type = function_state.modifiers_and_return_type()
if search(r'\bWEBKIT_API\b', modifiers_and_return_type):
if filename.find('chromium/public/') == -1:
error(function_state.function_name_start_position.row, 'readability/webkit_api', 5,
'WEBKIT_API should only appear in the chromium public directory.')
elif not file_extension == "h":
error(function_state.function_name_start_position.row, 'readability/webkit_api', 5,
'WEBKIT_API should only be used in header files.')
elif not function_state.is_declaration or search(r'\binline\b', modifiers_and_return_type):
error(function_state.function_name_start_position.row, 'readability/webkit_api', 5,
'WEBKIT_API should not be used on a function with a body.')
elif function_state.is_pure:
error(function_state.function_name_start_position.row, 'readability/webkit_api', 5,
'WEBKIT_API should not be used with a pure virtual function.')
# Do checks specific to function declaractions.
if not function_state.is_declaration:
return
parameter_list = function_state.parameter_list()
for parameter in parameter_list:
if not parameter.name:
......@@ -3313,7 +3332,7 @@ def process_line(filename, file_extension,
check_for_function_lengths(clean_lines, line, function_state, error)
if search(r'\bNOLINT\b', raw_lines[line]): # ignore nolint lines
return
check_function_definition(clean_lines, line, function_state, error)
check_function_definition(filename, file_extension, clean_lines, line, function_state, error)
check_pass_ptr_usage(clean_lines, line, function_state, error)
check_for_multiline_comments_and_strings(clean_lines, line, error)
check_style(clean_lines, line, file_extension, class_state, file_state, error)
......@@ -3404,6 +3423,7 @@ class CppChecker(object):
'readability/streams',
'readability/todo',
'readability/utf8',
'readability/webkit_api',
'runtime/arrays',
'runtime/casting',
'runtime/explicit',
......
......@@ -4332,6 +4332,40 @@ class WebKitStyleTest(CppStyleTestBase):
'One space before end of line comments'
' [whitespace/comments] [5]')
def test_webkit_api_check(self):
webkit_api_error_rules = ('-',
'+readability/webkit_api')
self.assertEquals('',
self.perform_lint('WEBKIT_API int foo();\n',
'chromium/public/test.h',
webkit_api_error_rules))
self.assertEquals('WEBKIT_API should only be used in header files. [readability/webkit_api] [5]',
self.perform_lint('WEBKIT_API int foo();\n',
'chromium/public/test.cpp',
webkit_api_error_rules))
self.assertEquals('WEBKIT_API should only appear in the chromium public directory. [readability/webkit_api] [5]',
self.perform_lint('WEBKIT_API int foo();\n',
'other/src/test.h',
webkit_api_error_rules))
self.assertEquals('WEBKIT_API should not be used on a function with a body. [readability/webkit_api] [5]',
self.perform_lint('WEBKIT_API int foo() { }\n',
'chromium/public/test.h',
webkit_api_error_rules))
self.assertEquals('WEBKIT_API should not be used on a function with a body. [readability/webkit_api] [5]',
self.perform_lint('WEBKIT_API inline int foo()\n'
'{\n'
'}\n',
'chromium/public/test.h',
webkit_api_error_rules))
self.assertEquals('WEBKIT_API should not be used with a pure virtual function. [readability/webkit_api] [5]',
self.perform_lint('{}\n'
'WEBKIT_API\n'
'virtual\n'
'int\n'
'foo() = 0;\n',
'chromium/public/test.h',
webkit_api_error_rules))
def test_other(self):
# FIXME: Implement this.
pass
......
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