Changeset 152719 in webkit


Ignore:
Timestamp:
Jul 16, 2013 6:05:24 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

check-webkit-style: "using namespace foo;" should be flagged as an error in headers
https://bugs.webkit.org/show_bug.cgi?id=57241

Patch by Brian Holt <brian.holt@samsung.com> on 2013-07-16
Reviewed by Ryosuke Niwa.

Added check for "using namespace foo" and unit test.

  • Scripts/webkitpy/style/checkers/cpp.py:

(check_using_namespace):
(check_style):
(CppChecker):

  • Scripts/webkitpy/style/checkers/cpp_unittest.py:

(WebKitStyleTest.test_using_namespace):

Location:
trunk/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r152718 r152719  
     12013-07-16  Brian Holt  <brian.holt@samsung.com>
     2
     3        check-webkit-style: "using namespace foo;" should be flagged as an error in headers
     4        https://bugs.webkit.org/show_bug.cgi?id=57241
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Added check for "using namespace foo" and unit test.
     9
     10        * Scripts/webkitpy/style/checkers/cpp.py:
     11        (check_using_namespace):
     12        (check_style):
     13        (CppChecker):
     14        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
     15        (WebKitStyleTest.test_using_namespace):
     16
    1172013-07-16  Anton Obzhirov  <a.obzhirov@samsung.com>
    218
  • trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py

    r150457 r152719  
    21622162
    21632163
     2164def check_using_namespace(clean_lines, line_number, file_state, error):
     2165    """Looks for 'using namespace foo;' which should be removed.
     2166
     2167    Args:
     2168      clean_lines: A CleansedLines instance containing the file.
     2169      line_number: The number of the line to check.
     2170      file_state: A _FileState instance which maintains information about
     2171                  the state of things in the file.
     2172      error: The function to call with any errors found.
     2173    """
     2174
     2175    # This check doesn't apply to C or Objective-C implementation files.
     2176    if file_state.is_c_or_objective_c():
     2177        return
     2178
     2179    line = clean_lines.elided[line_number]  # Get rid of comments and strings.
     2180
     2181    using_namespace_match = match(r'\s*using\s+namespace\s+(?P<method_name>\S+)\s*;\s*$', line)
     2182    if not using_namespace_match:
     2183        return
     2184
     2185    method_name = using_namespace_match.group('method_name')
     2186    error(line_number, 'build/using_namespace', 4,
     2187          "Do not use 'using namespace %s;'." % method_name)
     2188
    21642189def check_max_min_macros(clean_lines, line_number, file_state, error):
    21652190    """Looks use of MAX() and MIN() macros that should be replaced with std::max() and std::min().
     
    26462671    check_directive_indentation(clean_lines, line_number, file_state, error)
    26472672    check_using_std(clean_lines, line_number, file_state, error)
     2673    check_using_namespace(clean_lines, line_number, file_state, error)
    26482674    check_max_min_macros(clean_lines, line_number, file_state, error)
    26492675    check_ctype_functions(clean_lines, line_number, file_state, error)
     
    36313657        'build/storage_class',
    36323658        'build/using_std',
     3659        'build/using_namespace',
    36333660        'legal/copyright',
    36343661        'readability/braces',
  • trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py

    r150457 r152719  
    44914491            'foo.cpp')
    44924492
     4493    def test_using_namespace(self):
     4494        self.assert_lint(
     4495            'using namespace foo;',
     4496            "Do not use 'using namespace foo;'."
     4497            "  [build/using_namespace] [4]",
     4498            'foo.cpp')
     4499
    44934500    def test_max_macro(self):
    44944501        self.assert_lint(
Note: See TracChangeset for help on using the changeset viewer.