public RuleResult CheckType(TypeDefinition type) { // rule applies only to enums - but not enums marked with [Flags] attribute if (!type.IsEnum || type.IsFlags ()) return RuleResult.DoesNotApply; // rule applies if (!IsPlural (type.Name)) return RuleResult.Success; Runner.Report (type, Severity.Medium, Confidence.Normal); return RuleResult.Failure; }
public RuleResult CheckType(TypeDefinition type) { // rule applies only to enums with [Flags] attribute if (!type.IsFlags ()) return RuleResult.DoesNotApply; // rule applies if (IsPlural (type.Name)) return RuleResult.Success; // Confidence == Normal because valid names may end with 's' Runner.Report (type, Severity.Low, Confidence.Normal); return RuleResult.Failure; }
public RuleResult CheckType (TypeDefinition type) { // rule apply only on [Flags] (this takes care of checking for enums) if (!type.IsFlags ()) return RuleResult.DoesNotApply; // rule applies! FieldDefinition field = GetZeroValueField (type); if (field == null) return RuleResult.Success; // it's less likely an error if the field is named "None" Severity s = field.Name == "None" ? Severity.Medium : Severity.High; Runner.Report (field, s, Confidence.Total); return RuleResult.Failure; }
public RuleResult CheckType (TypeDefinition type) { // rule apply only on enums if (!type.IsEnum) return RuleResult.DoesNotApply; // rule doesn't apply on [Flags] if (type.IsFlags ()) return RuleResult.DoesNotApply; // rule applies! FieldDefinition field = GetZeroValueField (type); if (field != null) return RuleResult.Success; Runner.Report (type, Severity.Low, Confidence.Total); return RuleResult.Failure; }
public RuleResult CheckType (TypeDefinition type) { if (!type.IsEnum) return RuleResult.DoesNotApply; if (type.IsFlags ()) return RuleResult.DoesNotApply; GetValues (type); if (values.Count < 3) return RuleResult.Success; #if DEBUG Log.WriteLine (this); Log.WriteLine (this, "------------------------------------"); Log.WriteLine (this, type.FullName); Log.WriteLine (this, "values: {0}", string.Join (" ", (from x in values select x.ToString ("X4")).ToArray ())); #endif int numFlags = 0; int numMasks = 0; foreach (ulong value in values) { if (IsPowerOfTwo (value)) ++numFlags; else if (IsBitmask (value)) ++numMasks; } Log.WriteLine (this, "numFlags: {0}", numFlags); Log.WriteLine (this, "numMasks: {0}", numMasks); // The enum is bad if all of the values are powers of two or composed // of defined powers of two, if (numFlags + numMasks == values.Count) { values.Sort (); // sometimes enums are all sequential but not in order int numSequential = CountSequential (); Log.WriteLine (this, "numSequential: {0}", numSequential); // and there are not too many sequential values (so we don't // complain about stuff like 1, 2, 3, 4, 5, 6). if (numSequential < 3) { Confidence confidence = values.Count >= 4 && numMasks == 0 ? Confidence.High : Confidence.Normal; Runner.Report (type, Severity.Medium, confidence); } } return Runner.CurrentRuleResult; }