diff options
Diffstat (limited to 'WebKitTools/Scripts/webkitpy/style')
-rw-r--r-- | WebKitTools/Scripts/webkitpy/style/checkers/cpp.py | 14 | ||||
-rw-r--r-- | WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py | 24 |
2 files changed, 35 insertions, 3 deletions
diff --git a/WebKitTools/Scripts/webkitpy/style/checkers/cpp.py b/WebKitTools/Scripts/webkitpy/style/checkers/cpp.py index 611afdc..770ab40 100644 --- a/WebKitTools/Scripts/webkitpy/style/checkers/cpp.py +++ b/WebKitTools/Scripts/webkitpy/style/checkers/cpp.py @@ -1884,6 +1884,10 @@ def check_for_null(file_extension, clean_lines, line_number, error): if search(r'\bg_str(join|concat)\b', line): return + # Don't warn about NULL usage in gdk_pixbuf_save_to_*{join,concat}(). See Bug 43090. + if search(r'\bgdk_pixbuf_save_to\w+\b', line): + return + if search(r'\bNULL\b', line): error(line_number, 'readability/null', 5, 'Use 0 instead of NULL.') return @@ -1916,7 +1920,7 @@ def get_line_width(line): return len(line) -def check_style(clean_lines, line_number, file_extension, file_state, error): +def check_style(clean_lines, line_number, file_extension, class_state, file_state, error): """Checks rules from the 'C++ style rules' section of cppguide.html. Most of these rules are hard to test (naming, comment style), but we @@ -1927,6 +1931,8 @@ def check_style(clean_lines, line_number, file_extension, file_state, error): clean_lines: A CleansedLines instance containing the file. line_number: The number of the line to check. file_extension: The extension (without the dot) of the filename. + class_state: A _ClassState instance which maintains information about + the current stack of nested class declarations being parsed. file_state: A _FileState instance which maintains information about the state of things in the file. error: The function to call with any errors found. @@ -1987,6 +1993,10 @@ def check_style(clean_lines, line_number, file_extension, file_state, error): and not ((cleansed_line.find('case ') != -1 or cleansed_line.find('default:') != -1) and cleansed_line.find('break;') != -1) + # Also it's ok to have many commands in trivial single-line accessors in class definitions. + and not (match(r'.*\(.*\).*{.*.}', line) + and class_state.classinfo_stack + and line.count('{') == line.count('}')) and not cleansed_line.startswith('#define ')): error(line_number, 'whitespace/newline', 4, 'More than one command on the same line') @@ -2841,7 +2851,7 @@ def process_line(filename, file_extension, if search(r'\bNOLINT\b', raw_lines[line]): # ignore nolint lines return check_for_multiline_comments_and_strings(clean_lines, line, error) - check_style(clean_lines, line, file_extension, file_state, error) + check_style(clean_lines, line, file_extension, class_state, file_state, error) check_language(filename, clean_lines, line, file_extension, include_state, error) check_for_non_standard_constructs(clean_lines, line, class_state, error) diff --git a/WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py b/WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py index 2dde549..ee829aa 100644 --- a/WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py +++ b/WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py @@ -164,7 +164,7 @@ class CppStyleTestBase(unittest.TestCase): class_state = cpp_style._ClassState() file_state = cpp_style._FileState() for i in xrange(lines.num_lines()): - cpp_style.check_style(lines, i, file_extension, file_state, error_collector) + cpp_style.check_style(lines, i, file_extension, class_state, file_state, error_collector) cpp_style.check_for_non_standard_constructs(lines, i, class_state, error_collector) class_state.check_finished(error_collector) @@ -2594,6 +2594,19 @@ class NoNonVirtualDestructorsTest(CppStyleTestBase): self.assert_multi_line_lint( 'class Foo { void foo(); };', 'More than one command on the same line [whitespace/newline] [4]') + self.assert_multi_line_lint( + 'class MyClass {\n' + ' int getIntValue() { ASSERT(m_ptr); return *m_ptr; }\n' + '};\n', + '') + self.assert_multi_line_lint( + 'class MyClass {\n' + ' int getIntValue()\n' + ' {\n' + ' ASSERT(m_ptr); return *m_ptr;\n' + ' }\n' + '};\n', + 'More than one command on the same line [whitespace/newline] [4]') self.assert_multi_line_lint( '''class Qualified::Goo : public Foo { @@ -3472,6 +3485,15 @@ class WebKitStyleTest(CppStyleTestBase): self.assert_lint( 'gchar* result = g_strjoin(",", "part1", NULL);', '') + self.assert_lint( + 'gchar* result = gdk_pixbuf_save_to_callback(pixbuf, function, data, type, error, NULL);', + '') + self.assert_lint( + 'gchar* result = gdk_pixbuf_save_to_buffer(pixbuf, function, data, type, error, NULL);', + '') + self.assert_lint( + 'gchar* result = gdk_pixbuf_save_to_stream(pixbuf, function, data, type, error, NULL);', + '') # 2. C++ and C bool values should be written as true and # false. Objective-C BOOL values should be written as YES and NO. |