Bug 174315 - check-webkit-style: cpp linter incorrectly treats colon appearing in a string argument as the start of the initializer list
Summary: check-webkit-style: cpp linter incorrectly treats colon appearing in a string...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Matt Baker
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-07-10 11:06 PDT by Matt Baker
Modified: 2022-03-01 03:14 PST (History)
4 users (show)

See Also:


Attachments
Patch (2.17 KB, patch)
2017-07-10 17:24 PDT, Matt Baker
mattbaker: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Baker 2017-07-10 11:06:36 PDT
check-webkit-style's cpp linter incorrectly treats colon appearing in a string argument as the start of the initializer list, and emits an error if whitespace rules aren't followed.

For example, running check-webkit-style on the following:

MyClass::MyClass()
    : m_foo("foo:bar")
{
}

Will output:
ERROR: Missing spaces around :  [whitespace/init] [4]

Note:
The problem is with the cpp linter regex, see Tools/Scripts/webkitpy/style/checkers/cpp.py:2043:

# match the start of initialization list
if search(r'^(?P<indentation>\s*)((explicit\s+)?[^(\s|\?)]+\([^\?]*\)\s?\:|^(\s|\?)*\:)([^\:]|\Z)[^;]*$', line):
    if search(r'[^:]\:[^\:\s]+', line):
        error(line_number, 'whitespace/init', 4,
            'Missing spaces around :')
    ...
Comment 1 Radar WebKit Bug Importer 2017-07-10 11:06:57 PDT
<rdar://problem/33216486>
Comment 2 Matt Baker 2017-07-10 17:24:51 PDT
Created attachment 315052 [details]
Patch
Comment 3 Matt Baker 2017-07-10 17:50:29 PDT
Comment on attachment 315052 [details]
Patch

r- for now.

Need to improve on this (using elided over raw_lines feels risky), and add a test case to Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py.