Title: [239476] trunk/Tools
Revision
239476
Author
[email protected]
Date
2018-12-20 16:38:25 -0800 (Thu, 20 Dec 2018)

Log Message

Add style script rule to check for uses of std::optional<>
https://bugs.webkit.org/show_bug.cgi?id=192931

Reviewed by Tim Horton.

* Scripts/webkitpy/style/checkers/cpp.py:
(check_wtf_optional):
(check_style):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (239475 => 239476)


--- trunk/Tools/ChangeLog	2018-12-21 00:27:50 UTC (rev 239475)
+++ trunk/Tools/ChangeLog	2018-12-21 00:38:25 UTC (rev 239476)
@@ -1,3 +1,14 @@
+2018-12-20  Chris Dumez  <[email protected]>
+
+        Add style script rule to check for uses of std::optional<>
+        https://bugs.webkit.org/show_bug.cgi?id=192931
+
+        Reviewed by Tim Horton.
+
+        * Scripts/webkitpy/style/checkers/cpp.py:
+        (check_wtf_optional):
+        (check_style):
+
 2018-12-20  Jiewen Tan  <[email protected]>
 
         [WebAuthN] Add a runtime flag for local authenticator

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


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2018-12-21 00:27:50 UTC (rev 239475)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2018-12-21 00:38:25 UTC (rev 239476)
@@ -2378,6 +2378,26 @@
     error(line_number, 'runtime/wtf_move', 4, "Use 'WTFMove()' instead of 'std::move()'.")
 
 
+def check_wtf_optional(clean_lines, line_number, file_state, error):
+    """Looks for use of 'std::optional<>' which should be replaced with 'WTF::Optional<>'.
+
+    Args:
+      clean_lines: A CleansedLines instance containing the file.
+      line_number: The number of the line to check.
+      file_state: A _FileState instance which maintains information about
+                  the state of things in the file.
+      error: The function to call with any errors found.
+    """
+
+    line = clean_lines.elided[line_number]  # Get rid of comments and strings.
+
+    using_std_optional = search(r'\boptional\s*\<', line)
+    if not using_std_optional:
+        return
+
+    error(line_number, 'runtime/wtf_optional', 4, "Use 'WTF::Optional<>' instead of 'std::optional<>'.")
+
+
 def check_ctype_functions(clean_lines, line_number, file_state, error):
     """Looks for use of the standard functions in ctype.h and suggest they be replaced
        by use of equivilent ones in <wtf/ASCIICType.h>?.
@@ -2915,6 +2935,7 @@
     check_using_namespace(clean_lines, line_number, file_extension, error)
     check_max_min_macros(clean_lines, line_number, file_state, error)
     check_wtf_move(clean_lines, line_number, file_state, error)
+    check_wtf_optional(clean_lines, line_number, file_state, error)
     check_ctype_functions(clean_lines, line_number, file_state, error)
     check_switch_indentation(clean_lines, line_number, error)
     check_braces(clean_lines, line_number, file_state, error)
@@ -4038,6 +4059,7 @@
         'runtime/threadsafe_fn',
         'runtime/unsigned',
         'runtime/virtual',
+        'runtime/wtf_optional',
         'runtime/wtf_move',
         'security/assertion',
         'security/printf',

Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py (239475 => 239476)


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py	2018-12-21 00:27:50 UTC (rev 239475)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py	2018-12-21 00:38:25 UTC (rev 239476)
@@ -5081,6 +5081,29 @@
             "  [runtime/wtf_move] [4]",
             'foo.mm')
 
+    def test_wtf_optional(self):
+        self.assert_lint(
+             'Optional<int> a;',
+             '',
+             'foo.cpp')
+
+        self.assert_lint(
+             'WTF::Optional<int> a;',
+             '',
+             'foo.cpp')
+
+        self.assert_lint(
+            'std::optional<int> a;',
+            "Use 'WTF::Optional<>' instead of 'std::optional<>'."
+            "  [runtime/wtf_optional] [4]",
+            'foo.cpp')
+
+        self.assert_lint(
+            'optional<int> a;',
+            "Use 'WTF::Optional<>' instead of 'std::optional<>'."
+            "  [runtime/wtf_optional] [4]",
+            'foo.cpp')
+
     def test_ctype_fucntion(self):
         self.assert_lint(
             'int i = isascii(8);',
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to