← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~hjd/widelands/empty_codecheck into lp:widelands

 

Hans Joachim Desserud has proposed merging lp:~hjd/widelands/empty_codecheck into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~hjd/widelands/empty_codecheck/+merge/225760

Adds a code rule to prefer checking of !a.empty() rather than a.size() > 0. (Rather inspired by the existing testing_not_size check)

If you run the test suite for codechecks, two tests for do_not_use_printf will fail, though they did so before my change too and have not been affected by my addition.
-- 
https://code.launchpad.net/~hjd/widelands/empty_codecheck/+merge/225760
Your team Widelands Developers is requested to review the proposed merge of lp:~hjd/widelands/empty_codecheck into lp:widelands.
=== added file 'cmake/codecheck/rules/testing_size_greater_than_zero'
--- cmake/codecheck/rules/testing_size_greater_than_zero	1970-01-01 00:00:00 +0000
+++ cmake/codecheck/rules/testing_size_greater_than_zero	2014-07-06 17:40:25 +0000
@@ -0,0 +1,24 @@
+#!/usr/bin/python
+
+
+"""
+For standard containers and similar, do not use "something.size() > 0" to check
+whether it contains something. Just use "!something.empty()".
+"""
+
+error_msg = "Do not use a.size() to check for emptiness, use a.empty() instead."
+
+regexp=r""" *[a-zA-Z_][a-zA-Z_0-9]* *(\.|->) *size *\(\) *> *0 *"""
+
+forbidden = [
+    '	something.size() > 0',
+    '	something. size() > 0',
+    '	something.size()  >  0  ',
+    '	!(something.size() > 0)',
+    '	something.size() > 0 && something_else',
+]
+
+allowed = [
+    '	!something.empty();',
+    '	something.size() > 2;',
+]