Bug 32597 - Check one space before end of line comments
Summary: Check one space before end of line comments
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-15 23:41 PST by Fumitoshi Ukai
Modified: 2009-12-18 09:55 PST (History)
6 users (show)

See Also:


Attachments
Check one space before end of line comments. (14.08 KB, patch)
2009-12-15 23:44 PST, Fumitoshi Ukai
no flags Details | Formatted Diff | Diff
Check one space before end of line comments. (19.11 KB, patch)
2009-12-17 01:01 PST, Fumitoshi Ukai
no flags Details | Formatted Diff | Diff
Check one space before end of line comments. (19.51 KB, patch)
2009-12-17 20:51 PST, Fumitoshi Ukai
no flags Details | Formatted Diff | Diff
Check one space before end of line comments. (19.68 KB, patch)
2009-12-17 23:04 PST, Fumitoshi Ukai
levin: review+
levin: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fumitoshi Ukai 2009-12-15 23:41:52 PST
check-webkit-style should check one space before end of line comments.
Comment 1 Fumitoshi Ukai 2009-12-15 23:44:36 PST
Created attachment 44946 [details]
Check one space before end of line comments.
Comment 2 WebKit Review Bot 2009-12-15 23:47:47 PST
style-queue ran check-webkit-style on attachment 44946 [details] without any errors.
Comment 3 Adam Barth 2009-12-16 00:02:27 PST
Why are these warning off by default?  They seem like awesomesauce.
Comment 4 Fumitoshi Ukai 2009-12-16 00:11:07 PST
(In reply to comment #3)
> Why are these warning off by default?  They seem like awesomesauce.

These warning is off by default in cpp_style.py, but enabled by default in check-webkit-style (by cpp_style.use_webkit_styles() overriding _DEFAULT_FILTERS)
Comment 5 Eric Seidel (no email) 2009-12-16 13:24:11 PST
I don't see what the distinction is.  cpp_style.py is fully forked from its original chromium/google origins, so I'm not sure why running cpp_style.py should be different from running run-webkit-tests.
Comment 6 Fumitoshi Ukai 2009-12-16 16:52:47 PST
(In reply to comment #5)
> I don't see what the distinction is.  cpp_style.py is fully forked from its
> original chromium/google origins, so I'm not sure why running cpp_style.py
> should be different from running run-webkit-tests.

Hmm, so we don't need use_webkit_styles() and should have webkit style defaults in _DEFAULT_FILTERS?
Should we fix the code instead of adding new error categories?(e.g. fix whitespace/comments rather than adding whitespace/webkit_comments)
Comment 7 David Levin 2009-12-16 17:22:23 PST
(In reply to comment #6)
> (In reply to comment #5)
> > I don't see what the distinction is.  cpp_style.py is fully forked from its
> > original chromium/google origins, so I'm not sure why running cpp_style.py
> > should be different from running run-webkit-tests.
> 
> Hmm, so we don't need use_webkit_styles() and should have webkit style defaults
> in _DEFAULT_FILTERS?

Maybe so.

> Should we fix the code instead of adding new error categories?(e.g. fix
> whitespace/comments rather than adding whitespace/webkit_comments)

Yes. (That fix possibly could be just replacing it with what you did -- I haven't had a chance to review but was planning to look later tonight -- along with the worker/websocket patch).
Comment 8 Chris Jerdonek 2009-12-16 18:11:56 PST
(In reply to comment #6)

> Hmm, so we don't need use_webkit_styles() and should have webkit style defaults
> in _DEFAULT_FILTERS?

You should update since check-webkit-style changed since your patch.

My thinking is that the webkit default filter rules formerly in use_webkit_styles() should move from cpp_style.py to the check-webkit-style executable, and they should be passed in as a parameter to a function in cpp_style.py.  That's the direction I'm moving in:

https://bugs.webkit.org/show_bug.cgi?id=32592

I also think we should phase out the _DEFAULT_FILTERS global variable (now called _DEFAULT_FILTER_RULES), but we can't do that quite yet since the unit tests use it if I remember right.
Comment 9 Fumitoshi Ukai 2009-12-16 19:19:44 PST
(In reply to comment #8)
> (In reply to comment #6)
> 
> > Hmm, so we don't need use_webkit_styles() and should have webkit style defaults
> > in _DEFAULT_FILTERS?
> 
> You should update since check-webkit-style changed since your patch.
> 
> My thinking is that the webkit default filter rules formerly in
> use_webkit_styles() should move from cpp_style.py to the check-webkit-style
> executable, and they should be passed in as a parameter to a function in
> cpp_style.py.  That's the direction I'm moving in:

It sounds different direction as Eric and David said.
I think we'll remove use_webkit_styles() and make check-webkit-style act as the same way as cpp_style.py by default.
If we pass filters in use_webkit_styles() from check-webkit-style to cpp_style.py, then it means cpp_style.py works differently from check-webkit-style unless we pass the same filters, doesn't it?

> 
> https://bugs.webkit.org/show_bug.cgi?id=32592
> 
> I also think we should phase out the _DEFAULT_FILTERS global variable (now
> called _DEFAULT_FILTER_RULES), but we can't do that quite yet since the unit
> tests use it if I remember right.

We use change semantics of some error categories and/or _DEFAULT_FILTERS, we need to update unittest as well.
(That's why I preserved default error categories in cpp_style.py in the first patch.)
Comment 10 Chris Jerdonek 2009-12-16 20:06:59 PST
(In reply to comment #9)

> If we pass filters in use_webkit_styles() from check-webkit-style to
> cpp_style.py, then it means cpp_style.py works differently from
> check-webkit-style unless we pass the same filters, doesn't it?

No, because cpp_style.py will never be running as an executable.  If you look at the recent changes, we also removed the main() function from cpp_style.py.  The file cpp_style.py will just be providing functionality for the command-line script check-webkit-style to call.

You can read the discussion here for more background:

https://bugs.webkit.org/show_bug.cgi?id=32538
Comment 11 Fumitoshi Ukai 2009-12-17 01:01:00 PST
Created attachment 45043 [details]
Check one space before end of line comments.
Comment 12 WebKit Review Bot 2009-12-17 01:03:12 PST
style-queue ran check-webkit-style on attachment 45043 [details] without any errors.
Comment 13 Shinichiro Hamaji 2009-12-17 08:28:54 PST
Comment on attachment 45043 [details]
Check one space before end of line comments.

Some comments... First of all, indent level should be 4, not 2.

> @@ -874,8 +872,7 @@ def get_header_guard_cpp_variable(filename):
>  
>      """
>  
> -    fileinfo = FileInfo(filename)
> -    return sub(r'[-./\s]', '_', fileinfo.repository_name()).upper() + '_'
> +    return sub(r'[-./\s]', '_', os.path.basename(filename))

We don't need to replace '/' anymore?

> @@ -1362,31 +1363,6 @@ class CppStyleTest(CppStyleTestBase):
>          self.assert_multi_line_lint('#endif\n    );',
>                                      '')
>  
> -    def test_two_spaces_between_code_and_comments(self):
> -        self.assert_lint('} // namespace foo',
> -                         'At least two spaces is best between code and comments'
> -                         '  [whitespace/comments] [2]')
> -        self.assert_lint('}// namespace foo',
> -                         'At least two spaces is best between code and comments'
> -                         '  [whitespace/comments] [2]')
> -        self.assert_lint('printf("foo"); // Outside quotes.',
> -                         'At least two spaces is best between code and comments'
> -                         '  [whitespace/comments] [2]')
> -        self.assert_lint('int i = 0;  // Having two spaces is fine.', '')
> -        self.assert_lint('int i = 0;   // Having three spaces is OK.', '')
> -        self.assert_lint('// Top level comment', '')
> -        self.assert_lint('    // Line starts with four spaces.', '')
> -        self.assert_lint('foo();\n'
> -                         '{ // A scope is opening.', '')
> -        self.assert_lint('    foo();\n'
> -                         '    { // An indented scope is opening.', '')
> -        self.assert_lint('if (foo) { // not a pure scope; comment is too close!',
> -                         'At least two spaces is best between code and comments'
> -                         '  [whitespace/comments] [2]')
> -        self.assert_lint('printf("// In quotes.")', '')
> -        self.assert_lint('printf("\\"%s // In quotes.")', '')
> -        self.assert_lint('printf("%s", "// In quotes.")', '')
> -

I don't want to remove this test. They look good. Especially, I think we want to have a testcase for a comment in a string literal.
Comment 14 David Levin 2009-12-17 10:05:34 PST
Comment on attachment 45043 [details]
Check one space before end of line comments.

Shinichiro did a fine job of reviewing this patch.

r- for the removed test cases that Shinichiro noted.

One small additional comment below.

> diff --git a/WebKitTools/Scripts/modules/cpp_style.py b/WebKitTools/Scripts/modules/cpp_style.py
> +                and ((line[comment_position-1] not in string.whitespace)
> +                     or (line[comment_position-2] in string.whitespace)))):

I know this was a problem before but since you are changing these lines please add spaces around the "-".
Comment 15 Fumitoshi Ukai 2009-12-17 20:51:16 PST
Created attachment 45123 [details]
Check one space before end of line comments.
Comment 16 WebKit Review Bot 2009-12-17 20:53:50 PST
style-queue ran check-webkit-style on attachment 45123 [details] without any errors.
Comment 17 Shinichiro Hamaji 2009-12-17 22:01:34 PST
Thanks for the fixes. Looks good. It seems there are actually two changes in this patch (one space before comment and header guard). It would be better to update the ChangeLog to mention both?
Comment 18 Fumitoshi Ukai 2009-12-17 23:04:18 PST
Created attachment 45127 [details]
Check one space before end of line comments.
Comment 19 WebKit Review Bot 2009-12-17 23:05:52 PST
style-queue ran check-webkit-style on attachment 45127 [details] without any errors.
Comment 20 David Levin 2009-12-18 08:01:35 PST
Comment on attachment 45127 [details]
Check one space before end of line comments.

Thanks!

Minor nit to consider fixing when landing this below.

> diff --git a/WebKitTools/Scripts/modules/cpp_style_unittest.py b/WebKitTools/Scripts/modules/cpp_style_unittest.py
> +    def test_comments(self):
> +        # comment at the begining line is ok.

typo: begining
s/comment/A comment/
s/line/of a line/
Comment 21 Fumitoshi Ukai 2009-12-18 09:55:31 PST
Committed r52318: <http://trac.webkit.org/changeset/52318>