<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[51619] trunk/WebKitTools</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/51619">51619</a></dd>
<dt>Author</dt> <dd>eric@webkit.org</dd>
<dt>Date</dt> <dd>2009-12-02 21:08:59 -0800 (Wed, 02 Dec 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>2009-12-02  David Levin  &lt;levin@chromium.org&gt;

        Reviewed by Adam Barth.

        check-webkit-style is too noisy about namespace indenting issues.
        https://bugs.webkit.org/show_bug.cgi?id=32096

        * Scripts/modules/cpp_style.py:
        Added a _FileState object to be able to track file level information. In this
        case, it simply tracks whether the error has already been given, so that it isn't
        done again.
        * Scripts/modules/cpp_style_unittest.py:
        Modified test cases to pass in the _FileState object and fix a test that expected
        to see the namespace error twice (now it only occurs once). No new tests because
        existing tests cover the change in functionality.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkWebKitToolsChangeLog">trunk/WebKitTools/ChangeLog</a></li>
<li><a href="#trunkWebKitToolsScriptsmodulescpp_stylepy">trunk/WebKitTools/Scripts/modules/cpp_style.py</a></li>
<li><a href="#trunkWebKitToolsScriptsmodulescpp_style_unittestpy">trunk/WebKitTools/Scripts/modules/cpp_style_unittest.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkWebKitToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/WebKitTools/ChangeLog (51618 => 51619)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKitTools/ChangeLog        2009-12-03 00:38:45 UTC (rev 51618)
+++ trunk/WebKitTools/ChangeLog        2009-12-03 05:08:59 UTC (rev 51619)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2009-12-02  David Levin  &lt;levin@chromium.org&gt;
+
+        Reviewed by Adam Barth.
+
+        check-webkit-style is too noisy about namespace indenting issues.
+        https://bugs.webkit.org/show_bug.cgi?id=32096
+
+        * Scripts/modules/cpp_style.py:
+        Added a _FileState object to be able to track file level information. In this
+        case, it simply tracks whether the error has already been given, so that it isn't
+        done again.
+        * Scripts/modules/cpp_style_unittest.py:
+        Modified test cases to pass in the _FileState object and fix a test that expected
+        to see the namespace error twice (now it only occurs once). No new tests because
+        existing tests cover the change in functionality.
+
</ins><span class="cx"> 2009-12-01  Kevin Ollivier  &lt;kevino@theolliviers.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Reviewed by Eric Seidel.
</span></span></pre></div>
<a id="trunkWebKitToolsScriptsmodulescpp_stylepy"></a>
<div class="modfile"><h4>Modified: trunk/WebKitTools/Scripts/modules/cpp_style.py (51618 => 51619)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKitTools/Scripts/modules/cpp_style.py        2009-12-03 00:38:45 UTC (rev 51618)
+++ trunk/WebKitTools/Scripts/modules/cpp_style.py        2009-12-03 05:08:59 UTC (rev 51619)
</span><span class="lines">@@ -1119,6 +1119,16 @@
</span><span class="cx">                   self.classinfo_stack[0].name)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+class _FileState(object):
+    def __init__(self):
+        self._did_inside_namespace_indent_warning = False
+
+    def set_did_inside_namespace_indent_warning(self):
+        self._did_inside_namespace_indent_warning = True
+
+    def did_inside_namespace_indent_warning(self):
+        return self._did_inside_namespace_indent_warning
+
</ins><span class="cx"> def check_for_non_standard_constructs(filename, clean_lines, line_number,
</span><span class="cx">                                       class_state, error):
</span><span class="cx">     &quot;&quot;&quot;Logs an error if we see certain non-ANSI constructs ignored by gcc-2.
</span><span class="lines">@@ -1675,7 +1685,7 @@
</span><span class="cx">     return ('', -1)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-def check_namespace_indentation(filename, clean_lines, line_number, file_extension, error):
</del><ins>+def check_namespace_indentation(filename, clean_lines, line_number, file_extension, file_state, error):
</ins><span class="cx">     &quot;&quot;&quot;Looks for indentation errors inside of namespaces.
</span><span class="cx"> 
</span><span class="cx">     Args:
</span><span class="lines">@@ -1683,6 +1693,8 @@
</span><span class="cx">       clean_lines: A CleansedLines instance containing the file.
</span><span class="cx">       line_number: The number of the line to check.
</span><span class="cx">       file_extension: The extension (dot not included) of the file.
</span><ins>+      file_state: A _FileState instance which maintains information about
+                  the state of things in the file.
</ins><span class="cx">       error: The function to call with any errors found.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="lines">@@ -1694,8 +1706,10 @@
</span><span class="cx"> 
</span><span class="cx">     current_indentation_level = len(namespace_match.group('namespace_indentation'))
</span><span class="cx">     if current_indentation_level &gt; 0:
</span><del>-        error(filename, line_number, 'whitespace/indent', 4,
-              'namespace should never be indented.')
</del><ins>+        # Don't warn about an indented namespace if we already warned about indented code.
+        if not file_state.did_inside_namespace_indent_warning():
+            error(filename, line_number, 'whitespace/indent', 4,
+                  'namespace should never be indented.')
</ins><span class="cx">         return
</span><span class="cx">     looking_for_semicolon = False;
</span><span class="cx">     line_offset = 0
</span><span class="lines">@@ -1706,7 +1720,8 @@
</span><span class="cx">             continue
</span><span class="cx">         if not current_indentation_level:
</span><span class="cx">             if not (in_preprocessor_directive or looking_for_semicolon):
</span><del>-                if not match(r'\S', current_line):
</del><ins>+                if not match(r'\S', current_line) and not file_state.did_inside_namespace_indent_warning():
+                    file_state.set_did_inside_namespace_indent_warning()
</ins><span class="cx">                     error(filename, line_number + line_offset, 'whitespace/indent', 4,
</span><span class="cx">                           'Code inside a namespace should not be indented.')
</span><span class="cx">             if in_preprocessor_directive or (current_line.strip()[0] == '#'): # This takes care of preprocessor directive syntax.
</span><span class="lines">@@ -2124,7 +2139,7 @@
</span><span class="cx">     return len(line)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-def check_style(filename, clean_lines, line_number, file_extension, error):
</del><ins>+def check_style(filename, clean_lines, line_number, file_extension, file_state, error):
</ins><span class="cx">     &quot;&quot;&quot;Checks rules from the 'C++ style rules' section of cppguide.html.
</span><span class="cx"> 
</span><span class="cx">     Most of these rules are hard to test (naming, comment style), but we
</span><span class="lines">@@ -2136,6 +2151,8 @@
</span><span class="cx">       clean_lines: A CleansedLines instance containing the file.
</span><span class="cx">       line_number: The number of the line to check.
</span><span class="cx">       file_extension: The extension (without the dot) of the filename.
</span><ins>+      file_state: A _FileState instance which maintains information about
+                  the state of things in the file.
</ins><span class="cx">       error: The function to call with any errors found.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="lines">@@ -2203,7 +2220,7 @@
</span><span class="cx">               'operators on the left side of the line instead of the right side.')
</span><span class="cx"> 
</span><span class="cx">     # Some more style checks
</span><del>-    check_namespace_indentation(filename, clean_lines, line_number, file_extension, error)
</del><ins>+    check_namespace_indentation(filename, clean_lines, line_number, file_extension, file_state, error)
</ins><span class="cx">     check_using_std(filename, clean_lines, line_number, error)
</span><span class="cx">     check_max_min_macros(filename, clean_lines, line_number, error)
</span><span class="cx">     check_switch_indentation(filename, clean_lines, line_number, error)
</span><span class="lines">@@ -2914,7 +2931,7 @@
</span><span class="cx"> 
</span><span class="cx"> def process_line(filename, file_extension,
</span><span class="cx">                  clean_lines, line, include_state, function_state,
</span><del>-                 class_state, error):
</del><ins>+                 class_state, file_state, error):
</ins><span class="cx">     &quot;&quot;&quot;Processes a single line in the file.
</span><span class="cx"> 
</span><span class="cx">     Args:
</span><span class="lines">@@ -2927,6 +2944,8 @@
</span><span class="cx">       function_state: A _FunctionState instance which counts function lines, etc.
</span><span class="cx">       class_state: A _ClassState instance which maintains information about
</span><span class="cx">                    the current stack of nested class declarations being parsed.
</span><ins>+      file_state: A _FileState instance which maintains information about
+                  the state of things in the file.
</ins><span class="cx">       error: A callable to which errors are reported, which takes 4 arguments:
</span><span class="cx">              filename, line number, error level, and message
</span><span class="cx"> 
</span><span class="lines">@@ -2936,7 +2955,7 @@
</span><span class="cx">     if search(r'\bNOLINT\b', raw_lines[line]):  # ignore nolint lines
</span><span class="cx">         return
</span><span class="cx">     check_for_multiline_comments_and_strings(filename, clean_lines, line, error)
</span><del>-    check_style(filename, clean_lines, line, file_extension, error)
</del><ins>+    check_style(filename, clean_lines, line, file_extension, file_state, error)
</ins><span class="cx">     check_language(filename, clean_lines, line, file_extension, include_state,
</span><span class="cx">                    error)
</span><span class="cx">     check_for_non_standard_constructs(filename, clean_lines, line,
</span><span class="lines">@@ -2961,6 +2980,7 @@
</span><span class="cx">     include_state = _IncludeState()
</span><span class="cx">     function_state = _FunctionState()
</span><span class="cx">     class_state = _ClassState()
</span><ins>+    file_state = _FileState()
</ins><span class="cx"> 
</span><span class="cx">     check_for_copyright(filename, lines, error)
</span><span class="cx"> 
</span><span class="lines">@@ -2971,7 +2991,7 @@
</span><span class="cx">     clean_lines = CleansedLines(lines)
</span><span class="cx">     for line in xrange(clean_lines.num_lines()):
</span><span class="cx">         process_line(filename, file_extension, clean_lines, line,
</span><del>-                     include_state, function_state, class_state, error)
</del><ins>+                     include_state, function_state, class_state, file_state, error)
</ins><span class="cx">     class_state.check_finished(filename, error)
</span><span class="cx"> 
</span><span class="cx">     check_for_include_what_you_use(filename, clean_lines, include_state, error)
</span></span></pre></div>
<a id="trunkWebKitToolsScriptsmodulescpp_style_unittestpy"></a>
<div class="modfile"><h4>Modified: trunk/WebKitTools/Scripts/modules/cpp_style_unittest.py (51618 => 51619)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKitTools/Scripts/modules/cpp_style_unittest.py        2009-12-03 00:38:45 UTC (rev 51618)
+++ trunk/WebKitTools/Scripts/modules/cpp_style_unittest.py        2009-12-03 05:08:59 UTC (rev 51619)
</span><span class="lines">@@ -120,9 +120,10 @@
</span><span class="cx">         function_state = cpp_style._FunctionState()
</span><span class="cx">         ext = file_name[file_name.rfind('.') + 1:]
</span><span class="cx">         class_state = cpp_style._ClassState()
</span><ins>+        file_state = cpp_style._FileState()
</ins><span class="cx">         cpp_style.process_line(file_name, ext, clean_lines, 0,
</span><span class="cx">                                include_state, function_state,
</span><del>-                               class_state, error_collector)
</del><ins>+                               class_state, file_state, error_collector)
</ins><span class="cx">         # Single-line lint tests are allowed to fail the 'unlintable function'
</span><span class="cx">         # check.
</span><span class="cx">         error_collector.remove_if_present(
</span><span class="lines">@@ -137,8 +138,9 @@
</span><span class="cx">         lines = cpp_style.CleansedLines(lines)
</span><span class="cx">         ext = file_name[file_name.rfind('.') + 1:]
</span><span class="cx">         class_state = cpp_style._ClassState()
</span><ins>+        file_state = cpp_style._FileState()
</ins><span class="cx">         for i in xrange(lines.num_lines()):
</span><del>-            cpp_style.check_style(file_name, lines, i, ext, error_collector)
</del><ins>+            cpp_style.check_style(file_name, lines, i, ext, file_state, error_collector)
</ins><span class="cx">             cpp_style.check_for_non_standard_constructs(file_name, lines, i, class_state,
</span><span class="cx">                                                         error_collector)
</span><span class="cx">         class_state.check_finished(file_name, error_collector)
</span><span class="lines">@@ -2834,9 +2836,18 @@
</span><span class="cx">             '};\n'
</span><span class="cx">             '};\n'
</span><span class="cx">             '}',
</span><del>-            ['Code inside a namespace should not be indented.  [whitespace/indent] [4]', 'namespace should never be indented.  [whitespace/indent] [4]'],
</del><ins>+            'Code inside a namespace should not be indented.  [whitespace/indent] [4]',
</ins><span class="cx">             'foo.h')
</span><span class="cx">         self.assert_multi_line_lint(
</span><ins>+            'namespace OuterNamespace {\n'
+            '    class Document {\n'
+            '    namespace InnerNamespace {\n'
+            '};\n'
+            '};\n'
+            '}',
+            'Code inside a namespace should not be indented.  [whitespace/indent] [4]',
+            'foo.h')
+        self.assert_multi_line_lint(
</ins><span class="cx">             'namespace WebCore {\n'
</span><span class="cx">             '#if 0\n'
</span><span class="cx">             '    class Document {\n'
</span></span></pre>
</div>
</div>

</body>
</html>