Title: [127036] trunk/Tools
Revision
127036
Author
dominik.rottsc...@intel.com
Date
2012-08-29 13:05:54 -0700 (Wed, 29 Aug 2012)

Log Message

Stylechecker warns about comparison to zero when comparing to 0.5
https://bugs.webkit.org/show_bug.cgi?id=94913

Reviewed by Dirk Pranke.

According to the python documentation, \W is the character group with all
non-alphanumeric characters, equivalent to [^a-zA-Z0-9_], which is equal to
to [^\w]. We need to exclude the dot "." as well, so that floating point
values do not trigger this warning. Adding a unit test that shows the problem.

* Scripts/webkitpy/style/checkers/cpp.py:
(check_for_comparisons_to_zero): Modifying the regex to not get triggered by comparing to floats.
* Scripts/webkitpy/style/checkers/cpp_unittest.py:
(WebKitStyleTest.test_null_false_zero): Unit test exposing this issue.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (127035 => 127036)


--- trunk/Tools/ChangeLog	2012-08-29 20:03:11 UTC (rev 127035)
+++ trunk/Tools/ChangeLog	2012-08-29 20:05:54 UTC (rev 127036)
@@ -1,3 +1,20 @@
+2012-08-29  Dominik Röttsches  <dominik.rottsc...@intel.com>
+
+        Stylechecker warns about comparison to zero when comparing to 0.5
+        https://bugs.webkit.org/show_bug.cgi?id=94913
+
+        Reviewed by Dirk Pranke.
+
+        According to the python documentation, \W is the character group with all
+        non-alphanumeric characters, equivalent to [^a-zA-Z0-9_], which is equal to
+        to [^\w]. We need to exclude the dot "." as well, so that floating point
+        values do not trigger this warning. Adding a unit test that shows the problem.
+
+        * Scripts/webkitpy/style/checkers/cpp.py:
+        (check_for_comparisons_to_zero): Modifying the regex to not get triggered by comparing to floats.
+        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
+        (WebKitStyleTest.test_null_false_zero): Unit test exposing this issue.
+
 2012-08-29  Jon Lee  <jon...@apple.com>
 
         WTR build fixes.

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


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2012-08-29 20:03:11 UTC (rev 127035)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2012-08-29 20:05:54 UTC (rev 127036)
@@ -2425,7 +2425,7 @@
     line = clean_lines.elided[line_number]
 
     # Include NULL here so that users don't have to convert NULL to 0 first and then get this error.
-    if search(r'[=!]=\s*(NULL|0|true|false)\W', line) or search(r'\W(NULL|0|true|false)\s*[=!]=', line):
+    if search(r'[=!]=\s*(NULL|0|true|false)[^\w.]', line) or search(r'[^\w.](NULL|0|true|false)\s*[=!]=', line):
         if not search('LIKELY', line) and not search('UNLIKELY', line):
             error(line_number, 'readability/comparison_to_zero', 5,
                   'Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.')

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


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py	2012-08-29 20:03:11 UTC (rev 127035)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py	2012-08-29 20:05:54 UTC (rev 127036)
@@ -4376,6 +4376,12 @@
             'if (UNLIKELY(foo == 0))',
             '')
         self.assert_lint(
+            'if ((a - b) == 0.5)',
+            '')
+        self.assert_lint(
+            'if (0.5 == (a - b))',
+            '')
+        self.assert_lint(
             'if (LIKELY(foo == NULL))',
             'Use 0 instead of NULL.  [readability/null] [5]')
         self.assert_lint(
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to