Rule Description Example KPI
core.CallAndMessage Check for logical errors for function calls and Objective-C message expressions (e.g., uninitialized arguments, null function pointers) struct S { int x; }; void f(struct S s); void test() { struct S s; f(s); // warn: passed-by-value arg contain uninitialized data } Accuracy
osx.cocoa.MissingSuperCall Warn about Objective-C methods that lack a necessary call to super @interface Test : UIViewController @end @implementation test – (void)viewDidLoad {} // warn @end Accuracy
osx.cocoa.NSError Check usage of NSError** parameters @interface A : NSObject – (void)foo:(NSError **)error; @end @implementation A – (void)foo:(NSError **)error { // warn: method accepting NSError** should have a non-void // return value } @end Understandability
osx.cocoa.ObjCGenerics Check for type errors when using Objective-C generics NSMutableArray *names = [NSMutableArray array]; NSMutableArray *birthDates = names; // Warning: Conversion from value of type ‘NSDate *’ // to incompatible type ‘NSString *’ [birthDates addObject: [NSDate date]]; Accuracy
alpha.clone.CloneChecker Experimental: Reports similar pieces of code. void log(); int max(int a, int b) { // warn log(); if (a > b) return a; return b; } int maxClone(int x, int y) { // similar code here log(); if (x > y) return x; return y; } Maintainability
alpha.core.BoolAssignment Experimental: Warn about assigning non-{0,1} values to Boolean variables void test() { BOOL b = -1; // warn } Maintainability
alpha.core.Conversion Experimental: Loss of sign/precision in implicit conversions void test(unsigned U, signed S) { if (S > 10) { if (U < S) { } } if (S < -10) { if (U < S) { // warn (loss of sign) } } } Accuracy
alpha.core.DynamicTypeChecker Experimental: Check for cases where the dynamic and the static type of an object are unrelated. id date = [NSDate date]; // Warning: Object has a dynamic type ‘NSDate *’ which is // incompatible with static type ‘NSNumber *'” NSNumber *number = date; [number doubleValue]; Maintainability
alpha.core.TestAfterDivZero Experimental: Check for division by variable that is later compared against 0. Either the comparison is useless or there is division by zero. void test(int x) { var = 77 / x; if (x == 0) { } // warn } Robustness
alpha.deadcode.UnreachableCode Experimental: Check unreachable code int test() { int x = 1; while(x); return x; // warn } Maintainability
alpha.osx.cocoa.DirectIvarAssignment Experimental: Check for direct assignments to instance variables @interface MyClass : NSObject {} @property (readonly) id A; – (void) foo; @end @implementation MyClass – (void) foo { _A = 0; // warn } @end Maintainability
alpha.osx.cocoa.DirectIvarAssignmentForAnnotatedFunctions Experimental: Check for direct assignments to instance variables in the methods annotated with objc_no_direct_instance_variable_assignment @interface MyClass : NSObject {} @property (readonly) id A; – (void) fAnnotated __attribute__(( annotate(“objc_no_direct_instance_variable_assignment”))); – (void) fNotAnnotated; @end @implementation MyClass – (void) fAnnotated { _A = 0; // warn } – (void Maintainability
alpha.osx.cocoa.InstanceVariableInvalidation Experimental: Check that the invalidatable instance variables are invalidated in the methods annotated with objc_instance_variable_invalidator @protocol Invalidation – (void) invalidate __attribute__((annotate(“objc_instance_variable_invalidator”))); @end @interface InvalidationImpObj : NSObject @end @interface SubclassInvalidationImpObj : InvalidationImpObj { Invalidat Maintainability
alpha.osx.cocoa.localizability.PluralMisuseChecker Experimental: Warns against using one vs. many plural pattern in code when generating localized strings. NSString *reminderText = NSLocalizedString(@”None”, @”Indicates no reminders”); if (reminderCount == 1) { // Warning: Plural cases are not supported accross all languages. // Use a .stringsdict file instead reminderText = NSLocalizedString(@”1 Reminder”, @”Indicates single reminder”); } else if (reminderCount >= 2) { // Warning: Plural cases are not supported accross all languages. // Use a .stringsdict file instead reminderText = [NSString stringWithFormat: NSLocalizedString(@”%@ Reminders”, @”Indicates multiple reminders”), reminderCount]; } Maintainability
alpha.osx.cocoa.MissingInvalidationMethod Experimental: Check that the invalidation methods are present in classes that contain invalidatable instance variables @protocol Invalidation – (void)invalidate __attribute__((annotate(“objc_instance_variable_invalidator”))); @end @interface NeedInvalidation : NSObject @end @interface MissingInvalidationMethodDecl : NSObject { NeedInvalidation *V Resource Utilization