Merge lp:~widelands-dev/widelands/codecheck_sort into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 7306
Proposed branch: lp:~widelands-dev/widelands/codecheck_sort
Merge into: lp:widelands
Diff against target: 45 lines (+41/-0)
1 file modified
cmake/codecheck/rules/include_algorithm_for_sort (+41/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands/codecheck_sort
Reviewer Review Type Date Requested Status
SirVer Approve
Review via email: mp+243651@code.launchpad.net

Commit message

Added codecheck rule to include <algorithm> when std::sort is used.

Description of the change

Added codecheck rule to include <algorithm> when std::sort is used.

Copy & paste job from the unique_ptr rule.

To post a comment you must log in.
Revision history for this message
SirVer (sirver) wrote :

lgtm.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'cmake/codecheck/rules/include_algorithm_for_sort'
2--- cmake/codecheck/rules/include_algorithm_for_sort 1970-01-01 00:00:00 +0000
3+++ cmake/codecheck/rules/include_algorithm_for_sort 2014-12-04 12:42:23 +0000
4@@ -0,0 +1,41 @@
5+#!/usr/bin/python -tt
6+
7+
8+def does_include_algorithm(lines, fn):
9+ includes_algorithm = False
10+ for lineno, line in enumerate(lines, 1):
11+ if "include <algorithm>" in line:
12+ includes_algorithm = True
13+
14+ if "std::sort" in line and not includes_algorithm:
15+ return [ (fn, lineno,
16+ "This file uses std::sort but does not include <algorithm>.") ]
17+ return []
18+
19+evaluate_matches = does_include_algorithm
20+
21+
22+#################
23+# ALLOWED TESTS #
24+#################
25+allowed = [
26+"""#include <algorithm>
27+
28+std::sort(foo, bar, baz);
29+""",
30+]
31+
32+
33+###################
34+# FORBIDDEN TESTS #
35+###################
36+forbidden = [
37+"""
38+ std::sort(foo, bar, baz);
39+""",
40+"""
41+std::sort(foo, bar, baz);
42+
43+#include <algorithm>
44+""",
45+]

Subscribers

People subscribed via source and target branches

to status/vote changes: