check-webkit-style false positive for [readability/naming/protected] with method...
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 May 2020 21:14:24 +0000 (21:14 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 May 2020 21:14:24 +0000 (21:14 +0000)
<https://webkit.org/b/210682>

Reviewed by Darin Adler.

* Scripts/webkitpy/style/checkers/cpp.py:
(check_identifier_name_in_declaration):
- Don't check for invalid protector name if the capitalized
  protected name is the same as the original protected name,
  indicating it's a type name.
* Scripts/webkitpy/style/checkers/cpp_unittest.py:
(WebKitStyleTest.test_names):
- Add test cases.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261415 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/style/checkers/cpp.py
Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py

index b80c20a..fc4eac9 100644 (file)
@@ -1,3 +1,19 @@
+2020-05-08  David Kilzer  <ddkilzer@apple.com>
+
+        check-webkit-style false positive for [readability/naming/protected] with method declaration
+        <https://webkit.org/b/210682>
+
+        Reviewed by Darin Adler.
+
+        * Scripts/webkitpy/style/checkers/cpp.py:
+        (check_identifier_name_in_declaration):
+        - Don't check for invalid protector name if the capitalized
+          protected name is the same as the original protected name,
+          indicating it's a type name.
+        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
+        (WebKitStyleTest.test_names):
+        - Add test cases.
+
 2020-05-08  Alex Christensen  <achristensen@webkit.org>
 
         Fix build on platforms without network framework.
index d3bb1a2..f49f2b6 100644 (file)
@@ -3725,13 +3725,15 @@ def check_identifier_name_in_declaration(filename, line_number, line, file_state
         protector_name = ref_check.group('protector_name')
         protected_name = ref_check.group('protected_name')
         cap_protected_name = protected_name[0].upper() + protected_name[1:]
-        expected_protector_name = 'protected' + cap_protected_name
-        if protected_name == 'this' and protector_name != 'protectedThis':
-            error(line_number, 'readability/naming/protected', 4, "\'" + protector_name + "\' is incorrectly named. It should be named \'protectedThis\'.")
-        elif protector_name == expected_protector_name or protector_name == 'protector':
-            return
-        else:
-            error(line_number, 'readability/naming/protected', 4, "\'" + protector_name + "\' is incorrectly named. It should be named \'protector\' or \'" + expected_protector_name + "\'.")
+        # Ignore function declarations where cap_protected_name == protected_name indicates a type name.
+        if cap_protected_name != protected_name:
+            expected_protector_name = 'protected' + cap_protected_name
+            if protected_name == 'this' and protector_name != 'protectedThis':
+                error(line_number, 'readability/naming/protected', 4, "\'" + protector_name + "\' is incorrectly named. It should be named \'protectedThis\'.")
+            elif protector_name == expected_protector_name or protector_name == 'protector':
+                return
+            else:
+                error(line_number, 'readability/naming/protected', 4, "\'" + protector_name + "\' is incorrectly named. It should be named \'protector\' or \'" + expected_protector_name + "\'.")
 
     # Basically, a declaration is a type name followed by whitespaces
     # followed by an identifier. The type name can be complicated
index 07f6130..c7ffd52 100644 (file)
@@ -5894,6 +5894,8 @@ class WebKitStyleTest(CppStyleTestBase):
         # Lines that look like a protector variable declaration but aren't.
         self.assert_lint('static RefPtr<Widget> doSomethingWith(widget);', '')
         self.assert_lint('RefPtr<Widget> create();', '')
+        self.assert_lint('Ref<GeolocationPermissionRequestProxy> createRequest(GeolocationIdentifier);', '')
+        self.assert_lint('Ref<TypeName> createSomething(OtherTypeName);', '')
 
     def test_parameter_names(self):
         # Leave meaningless variable names out of function declarations.