widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #03301
[Merge] lp:~widelands-dev/widelands/codecheck_sort into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/codecheck_sort into lp:widelands.
Commit message:
Added codecheck rule to include <algorithm> when std::sort is used.
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/codecheck_sort/+merge/243651
Added codecheck rule to include <algorithm> when std::sort is used.
Copy & paste job from the unique_ptr rule.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/codecheck_sort into lp:widelands.
=== added file 'cmake/codecheck/rules/include_algorithm_for_sort'
--- cmake/codecheck/rules/include_algorithm_for_sort 1970-01-01 00:00:00 +0000
+++ cmake/codecheck/rules/include_algorithm_for_sort 2014-12-04 12:42:23 +0000
@@ -0,0 +1,41 @@
+#!/usr/bin/python -tt
+
+
+def does_include_algorithm(lines, fn):
+ includes_algorithm = False
+ for lineno, line in enumerate(lines, 1):
+ if "include <algorithm>" in line:
+ includes_algorithm = True
+
+ if "std::sort" in line and not includes_algorithm:
+ return [ (fn, lineno,
+ "This file uses std::sort but does not include <algorithm>.") ]
+ return []
+
+evaluate_matches = does_include_algorithm
+
+
+#################
+# ALLOWED TESTS #
+#################
+allowed = [
+"""#include <algorithm>
+
+std::sort(foo, bar, baz);
+""",
+]
+
+
+###################
+# FORBIDDEN TESTS #
+###################
+forbidden = [
+"""
+ std::sort(foo, bar, baz);
+""",
+"""
+std::sort(foo, bar, baz);
+
+#include <algorithm>
+""",
+]
References