Bug 52272 - check-webkit-style -- close_expression function doesn't work correctly.
Summary: check-webkit-style -- close_expression function doesn't work correctly.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC All
: P2 Normal
Assignee: David Levin
URL:
Keywords:
Depends on:
Blocks: 52271
  Show dependency treegraph
 
Reported: 2011-01-11 20:15 PST by David Levin
Modified: 2011-01-12 11:44 PST (History)
1 user (show)

See Also:


Attachments
Patch (9.37 KB, patch)
2011-01-11 20:18 PST, David Levin
hamaji: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Levin 2011-01-11 20:15:23 PST
See summary.
Comment 1 David Levin 2011-01-11 20:18:11 PST
Created attachment 78644 [details]
Patch
Comment 2 David Levin 2011-01-11 22:01:03 PST
Comment on attachment 78644 [details]
Patch

At least one person said this was hard to understand so I'll try to make the code easier to read.
Comment 3 Shinichiro Hamaji 2011-01-12 01:35:24 PST
Comment on attachment 78644 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=78644&action=review

No, I was so sick and my brain stopped working when I told you that I couldn't understand it. Now I feel better and I can understand this patch :) I'm sure this code is good enough to land this as is. I put some nitpicks.

> Tools/Scripts/webkitpy/style/checkers/cpp.py:817
>          end_character = ')'

How about creating the regexp string here?

if start_character == '(':
  enclosing_characeter_regexp = r'[\{\}]'
elif
  ...

> Tools/Scripts/webkitpy/style/checkers/cpp.py:829
> +    while True:

I think you used while because we start in the middle of the first line, but I'd mildly prefer for-loop:

current_column = position.column + 1
net_open = 1
for line_number in xrange(position.row, len(elided):
  line = elided[line_number][current_column:]
  while True:
     ...
  current_column = 0
return Position(len(elided), -1)

because in this way we can clearly see the iterator of the outer loop.
Comment 4 David Levin 2011-01-12 11:43:36 PST
Committed as http://trac.webkit.org/changeset/75628
Comment 5 David Levin 2011-01-12 11:44:27 PST
(In reply to comment #3)
> (From update of attachment 78644 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=78644&action=review
> 
> No, I was so sick and my brain stopped working when I told you that I couldn't understand it. Now I feel better and I can understand this patch :) I'm sure this code is good enough to land this as is. I put some nitpicks.
> 
> > Tools/Scripts/webkitpy/style/checkers/cpp.py:817
> >          end_character = ')'
> 
> How about creating the regexp string here?
> 
> if start_character == '(':
>   enclosing_characeter_regexp = r'[\{\}]'
> elif
>   ...
> 
Done.

> > Tools/Scripts/webkitpy/style/checkers/cpp.py:829
> > +    while True:
> 
> I think you used while because we start in the middle of the first line, but I'd mildly prefer for-loop:
> 
> current_column = position.column + 1
> net_open = 1
> for line_number in xrange(position.row, len(elided):
>   line = elided[line_number][current_column:]
>   while True:
>      ...
>   current_column = 0
> return Position(len(elided), -1)
> 
> because in this way we can clearly see the iterator of the outer loop.

I really like this. I did it (in a slightly modified way but basically the same idea).