Title: [216000] trunk/Tools
Revision
216000
Author
[email protected]
Date
2017-04-30 16:39:51 -0700 (Sun, 30 Apr 2017)

Log Message

[Cocoa] Have check-webkit-style advise against use of [get…Class() alloc]
https://bugs.webkit.org/show_bug.cgi?id=171486

Reviewed by Sam Weinig.

* Scripts/webkitpy/style/checkers/cpp.py:
(check_soft_link_class_alloc): Added. Looks for [get…Class() alloc] and suggests
  alloc…Instance() instead.
(check_style): Invoke new check.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (215999 => 216000)


--- trunk/Tools/ChangeLog	2017-04-30 21:24:37 UTC (rev 215999)
+++ trunk/Tools/ChangeLog	2017-04-30 23:39:51 UTC (rev 216000)
@@ -1,3 +1,15 @@
+2017-04-30  Dan Bernstein  <[email protected]>
+
+        [Cocoa] Have check-webkit-style advise against use of [get…Class() alloc]
+        https://bugs.webkit.org/show_bug.cgi?id=171486
+
+        Reviewed by Sam Weinig.
+
+        * Scripts/webkitpy/style/checkers/cpp.py:
+        (check_soft_link_class_alloc): Added. Looks for [get…Class() alloc] and suggests
+          alloc…Instance() instead.
+        (check_style): Invoke new check.
+
 2017-04-30  Brady Eidson  <[email protected]>
 
         More fixing after r215991

Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py (215999 => 216000)


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2017-04-30 21:24:37 UTC (rev 215999)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2017-04-30 23:39:51 UTC (rev 216000)
@@ -2729,6 +2729,23 @@
         error(line_number, 'readability/null', 4, 'Use nullptr instead of NULL (even in *comments*).')
 
 
+def check_soft_link_class_alloc(clean_lines, line_number, error):
+    """Checks that allocating an instance of a soft-linked class uses alloc[Class]Instance.
+
+    Args:
+      clean_lines: A CleansedLines instance containing the file.
+      line_number: The number of the line to check.
+      error: The function to call with any errors found.
+    """
+
+    line = clean_lines.elided[line_number]
+
+    matched = search(r'\[get([^\s]+)Class\(\)\s+alloc\]', line)
+    if matched:
+        error(line_number, 'runtime/soft-linked-alloc', 4,
+              'Using +alloc with a soft-linked class. Use alloc%sInstance() instead.' % matched.group(1))
+
+
 def get_line_width(line):
     """Determines the width of the line in column positions.
 
@@ -2822,6 +2839,7 @@
     check_check(clean_lines, line_number, error)
     check_for_comparisons_to_zero(clean_lines, line_number, error)
     check_for_null(clean_lines, line_number, file_state, error)
+    check_soft_link_class_alloc(clean_lines, line_number, error)
     check_indentation_amount(clean_lines, line_number, error)
     check_enum_casing(clean_lines, line_number, enum_state, error)
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to