Skip to content

Commit 88aa023

Browse files
committed
Add new filter to the sanity checker to check for plain wxFAIL macros
wxFAIL is for the lazy programmer. Most of the time it can be replaced with an appropriate wxCHECK() macro, making the code even more readable. Okay, I admit there are cases it is valid to use wxFAIL, but even in these cases one should use wxFAIL_MSG() instead, to give an explanation on what went wrong at first sight.
1 parent 98fb9f2 commit 88aa023

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/utils/scripts/sanity

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,10 @@ class WxFailUsage < SanityCheck
239239
def initialize
240240
super
241241

242-
@name = "WxFailUsagesy"
242+
@name = "WxFailUsage"
243243
@title = "Always failing wxASSERT()"
244244
@type = "Good Practice"
245-
@desc = "Use wxFAIL instead of an always failing wxASSERT()."
245+
@desc = "Use wxFAIL_MSG() instead of an always failing wxASSERT()."
246246
end
247247

248248
def parse_file(file, lines)
@@ -257,6 +257,31 @@ end
257257

258258

259259

260+
class NoMoreWxFail < SanityCheck
261+
def initialize
262+
super
263+
264+
@name = "NoMoreWxFail"
265+
@title = "wxFAIL needs an explanation"
266+
@type = "Good Practice"
267+
@desc = "Use wxFAIL_MSG() instead of wxFAIL to provide a description of what happened. "
268+
@desc += "Or even better, use one of the wxCHECK*() or wxASSERT*() macros if applicable. "
269+
@desc += "An assertion of type 'wxAssertFailure' without description does not say much, "
270+
@desc += "please provide a short explanation of what went wrong."
271+
end
272+
273+
def parse_file(file, lines)
274+
results = lines.select do |line|
275+
line.text =~ /\bwxFAIL\b/ and not
276+
line.text =~ /\/\/\s*wxFAIL\b/
277+
end
278+
279+
add_results( file, results )
280+
end
281+
end
282+
283+
284+
260285
class PassByValue < SanityCheck
261286
def initialize
262287
super
@@ -664,6 +689,7 @@ filterList.push InlinedIfTrue.new
664689
filterList.push LoopOnConstant.new
665690
filterList.push MissingImplementation.new
666691
filterList.push WxFailUsage.new
692+
filterList.push NoMoreWxFail.new
667693

668694

669695
# Sort enabled filters by type and name. The reason why this is done here is

0 commit comments

Comments
 (0)