diff options
author | Jesse Jones <jesjones@mono-cvs.ximian.com> | 2009-08-13 20:58:21 +0400 |
---|---|---|
committer | Jesse Jones <jesjones@mono-cvs.ximian.com> | 2009-08-13 20:58:21 +0400 |
commit | 3f925f728e35d545781d3c4f1c1cf401e0cc31c2 (patch) | |
tree | a5ca93fa74d6d404646abe587dd40ffac9c90f07 | |
parent | 04fadbb295820f5b2107eb40b7808d7cc6c94246 (diff) |
Edited the descriptions for
AvoidLackOfCohesionOfMethodsRule
ConsiderUsingStopwatchRule
AvoidDeepInheritanceTreeRule
AvoidComplexMethodsRule.
svn path=/trunk/mono-tools/; revision=139859
5 files changed, 82 insertions, 30 deletions
diff --git a/gendarme/rules/Gendarme.Rules.Maintainability/AvoidComplexMethodsRule.cs b/gendarme/rules/Gendarme.Rules.Maintainability/AvoidComplexMethodsRule.cs index 68a5ace1..7a7f4131 100644 --- a/gendarme/rules/Gendarme.Rules.Maintainability/AvoidComplexMethodsRule.cs +++ b/gendarme/rules/Gendarme.Rules.Maintainability/AvoidComplexMethodsRule.cs @@ -28,6 +28,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using Mono.Cecil; using Mono.Cecil.Cil; @@ -37,27 +38,27 @@ using Gendarme.Framework.Rocks; namespace Gendarme.Rules.Maintainability { - // TODO: Is this really configureable? It would be nice if this rule did check anonymous methods. - /// <summary> - /// This rule compute the cyclomatic complexity (CC) for every method and reports any method + /// This rule computes the cyclomatic complexity (CC) for every method and reports any method /// with a CC over 25 (this limit is configurable). Large CC value often indicate complex /// code that is hard to understand and maintain. It's likely that breaking the - /// method into several methods would help readability. This rule won't report any defects + /// method into several methods will help readability. This rule won't report any defects /// on code generated by the compiler or by tools. /// </summary> /// <remarks>This rule is available since Gendarme 2.0</remarks> - [Problem ("Methods with a cyclomatic complexity equal or greater than 25 are harder to understand and maintain.")] + [Problem ("Methods with a large cyclomatic complexity are hard to understand and maintain.")] [Solution ("Simplify the method using refactors like Extract Method.")] [FxCopCompatibility ("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] public class AvoidComplexMethodsRule : Rule, IMethodRule { - + // defaults match fxcop rule http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1575061&SiteID=1 // so people using both tools should not see conflicting results + private const int DefaultSuccessThreshold = 25; + public AvoidComplexMethodsRule () { - SuccessThreshold = 25; + SuccessThreshold = DefaultSuccessThreshold; } public override void Initialize (IRunner runner) @@ -73,12 +74,29 @@ namespace Gendarme.Rules.Maintainability { HighThreshold = SuccessThreshold * 4; } + /// <summary>The cyclomatic complexity at which defects begin to be reported.</summary> + /// <remarks>This defaults to 25 and larger values will mean fewer reported defects.</remarks> + [DefaultValue (DefaultSuccessThreshold)] + [Description ("The cyclomatic complexity at which defects are reported.")] public int SuccessThreshold { get; set; } + /// <summary>Methods with cyclomatic complexity less than this will be reported as low severity.</summary> + /// <remarks>If left as zero then the rule will initialize it to 2*SuccessThreshold.</remarks> + [DefaultValue (0)] + [Description ("Methods with cyclomatic complexity less than this will be reported as low severity.")] public int LowThreshold { get; set; } + /// <summary>Methods with cyclomatic complexity less than this (but higher than LowThreshold) will be reported as medium severity.</summary> + /// <remarks>If left as zero then the rule will initialize it to 3*SuccessThreshold.</remarks> + [DefaultValue (0)] + [Description ("Methods with cyclomatic complexity less than this will be reported as medium severity.")] public int MediumThreshold { get; set; } + /// <summary>Methods with cyclomatic complexity less than this (but higher than MediumThreshold) will be reported as high severity.</summary> + /// <remarks>Methods with cyclomatic complexity greater than this will be reported as critical severity. + /// If left as zero then the rule will initialize it to 4*SuccessThreshold.</remarks> + [DefaultValue (0)] + [Description ("Methods with cyclomatic complexity less than this will be reported as high severity.")] public int HighThreshold { get; set; } diff --git a/gendarme/rules/Gendarme.Rules.Maintainability/AvoidDeepInheritanceTreeRule.cs b/gendarme/rules/Gendarme.Rules.Maintainability/AvoidDeepInheritanceTreeRule.cs index 6e9993ff..a0e2af8b 100644 --- a/gendarme/rules/Gendarme.Rules.Maintainability/AvoidDeepInheritanceTreeRule.cs +++ b/gendarme/rules/Gendarme.Rules.Maintainability/AvoidDeepInheritanceTreeRule.cs @@ -27,6 +27,7 @@ // using System; +using System.ComponentModel; using Mono.Cecil; @@ -35,13 +36,10 @@ using Gendarme.Framework.Rocks; namespace Gendarme.Rules.Maintainability { - // TODO: Afaict it is not possible to configure the MaximumDepth or CountExternalDepth - // properties. - /// <summary> /// This rule will fire if a type has (by default) more than four base classes defined /// within the assembly set being analyzed. Optionally it will also count base - /// classes defined outside the assembly set. + /// classes defined outside the assembly set being analyzed. /// </summary> /// <remarks>This rule is available since Gendarme 2.0</remarks> @@ -50,17 +48,27 @@ namespace Gendarme.Rules.Maintainability { [FxCopCompatibility ("Microsoft.Maintainability", "CA1501:AvoidExcessiveInheritance")] public class AvoidDeepInheritanceTreeRule : Rule, ITypeRule { + /// <summary>Classes with more base classes than this will result in a defect.</summary> + /// <remarks>Defaults to 4.</remarks> + [DefaultValue (DefaultMaximumDepth)] + [Description ("Classes with more base classes than this will result in a defect.")] public int MaximumDepth { get { return maximumDepth; } set { maximumDepth = value; } } - private int maximumDepth = 4; + private const int DefaultMaximumDepth = 4; + private int maximumDepth = DefaultMaximumDepth; + /// <summary>If true the rule will count base classes defined outside the assemblies being analyzed.</summary> + /// <remarks>Defaults to false.</remarks> + [DefaultValue (DefaultCountExternalDepth)] + [Description ("If true the rule will count base classes defined outside the assemblies being analyzed.")] public bool CountExternalDepth { get { return countExternalDepth; } set { countExternalDepth = value; } } - private bool countExternalDepth = false; + private const bool DefaultCountExternalDepth = false; + private bool countExternalDepth = DefaultCountExternalDepth; private Severity GetSeverity (int depth) diff --git a/gendarme/rules/Gendarme.Rules.Maintainability/AvoidLackOfCohesionOfMethodsRule.cs b/gendarme/rules/Gendarme.Rules.Maintainability/AvoidLackOfCohesionOfMethodsRule.cs index b87425e8..a8746749 100644 --- a/gendarme/rules/Gendarme.Rules.Maintainability/AvoidLackOfCohesionOfMethodsRule.cs +++ b/gendarme/rules/Gendarme.Rules.Maintainability/AvoidLackOfCohesionOfMethodsRule.cs @@ -28,6 +28,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using Mono.Cecil; using Mono.Cecil.Cil; @@ -37,12 +38,10 @@ using Gendarme.Framework.Rocks; namespace Gendarme.Rules.Maintainability { - // TODO: The summary says that the threshold can be configured. Is this true? If so how? - /// <summary> /// This rule checks every type for lack of cohesion between the fields and the methods. Low cohesion is often /// a sign that a type is doing too many, different and unrelated things. The cohesion score is given for each defect - /// (higher is better) and the success threshold can be configured. + /// (higher is better). /// </summary> /// <remarks>This rule is available since Gendarme 2.0</remarks> @@ -50,12 +49,17 @@ namespace Gendarme.Rules.Maintainability { [Solution ("You can apply the Extract Class or Extract Subclass refactoring.")] public class AvoidLackOfCohesionOfMethodsRule : Rule, ITypeRule { - private double successCoh = 0.5; - private double lowCoh = 0.4; - private double medCoh = 0.2; - private int method_minimum_count = 2;//set at 2 to remove 'uninteresting' types - private int field_minimum_count = 1;//set at 1 to remove 'uninteresting' types - //this shouldn't be set to another value than MinimumMethodCount/2 + private const double DefaultSuccessCoh = 0.5; + private const double DefaultLowCoh = 0.4; + private const double DefaultMediumCoh = 0.2; + private const int DefaultMethodMinimumCount = 2; // set at 2 to remove 'uninteresting' types + private const int DefaultFieldMinimumCount = 1; // set at 1 to remove 'uninteresting' types (this shouldn't be set to a value other than MinimumMethodCount/2) + + private double successCoh = DefaultSuccessCoh; + private double lowCoh = DefaultLowCoh; + private double medCoh = DefaultMediumCoh; + private int method_minimum_count = DefaultMethodMinimumCount; + private int field_minimum_count = DefaultFieldMinimumCount; private Dictionary<FieldReference, int> F = new Dictionary<FieldReference, int>(); private List<FieldReference> Fset = new List<FieldReference>(); @@ -150,24 +154,40 @@ namespace Gendarme.Rules.Maintainability { } + /// <summary>Cohesion values lower than this will result in a defect.</summary> + /// <remarks>Defaults to 0.5.</remarks> + [DefaultValue (DefaultSuccessCoh)] + [Description ("Cohesion values lower than this will result in a defect.")] public double SuccessLowerLimit { get { return successCoh; } set { successCoh = value; } } + /// <summary>Defects with cohesion values greater than this will be reported at low severity.</summary> + /// <remarks>Defaults to 0.4.</remarks> + [DefaultValue (DefaultLowCoh)] + [Description ("Defects with cohesion values greater than this will be reported at low severity.")] public double LowSeverityLowerLimit { get { return lowCoh; } set { lowCoh = value; } } + /// <summary>Defects with cohesion values greater than (but less than LowSeverityLowerLimit) this will be reported at medium severity.</summary> + /// <remarks>Defaults to 0.2.</remarks> + [DefaultValue (DefaultMediumCoh)] + [Description ("Defects with cohesion values greater than (but less than LowSeverityLowerLimit) this will be reported at medium severity.")] public double MediumSeverityLowerLimit { get { return medCoh; } set { medCoh = value; } } + /// <summary>The minimum number of methods a class must have to be checked.</summary> + /// <remarks>Defaults to 2.</remarks> + [DefaultValue (DefaultMethodMinimumCount)] + [Description ("The minimum number of methods a class must have to be checked.")] public int MinimumMethodCount { get { return method_minimum_count; } @@ -178,6 +198,10 @@ namespace Gendarme.Rules.Maintainability { } } + /// <summary>The minimum number of fields a class must have to be checked.</summary> + /// <remarks>Defaults to 1.</remarks> + [DefaultValue (DefaultFieldMinimumCount)] + [Description ("The minimum number of fields a class must have to be checked.")] public int MinimumFieldCount { get { return field_minimum_count; } diff --git a/gendarme/rules/Gendarme.Rules.Maintainability/ChangeLog b/gendarme/rules/Gendarme.Rules.Maintainability/ChangeLog index e92e4147..7c1b5a65 100644 --- a/gendarme/rules/Gendarme.Rules.Maintainability/ChangeLog +++ b/gendarme/rules/Gendarme.Rules.Maintainability/ChangeLog @@ -1,3 +1,9 @@ +2009-08-13 Jesse Jones <jesjones@mindspring.com> + + * AvoidLackOfCohesionOfMethodsRule.cs, ConsiderUsingStopwatchRule.cs, + AvoidDeepInheritanceTreeRule.cs, AvoidComplexMethodsRule.cs: + Edited the rule descriptions. + 2009-07-04 Jesse Jones <jesjones@mindspring.com> * *Rule.cs: Edited most of the rule descriptions. diff --git a/gendarme/rules/Gendarme.Rules.Maintainability/ConsiderUsingStopwatchRule.cs b/gendarme/rules/Gendarme.Rules.Maintainability/ConsiderUsingStopwatchRule.cs index d2fa971b..8360204c 100644 --- a/gendarme/rules/Gendarme.Rules.Maintainability/ConsiderUsingStopwatchRule.cs +++ b/gendarme/rules/Gendarme.Rules.Maintainability/ConsiderUsingStopwatchRule.cs @@ -40,17 +40,13 @@ using Mono.Cecil.Cil; namespace Gendarme.Rules.Maintainability { - // TODO: I think StopWatch is also more accurate than DateTime (at least on .NET). The - // precision of DateTime is 100-nanosecond which is quite high, but I suspect that the - // accuracy is not anywhere near that high. OTOH StopWatch will use QueryPerformanceFrequency - // which is very accurate. - /// <summary> /// This rule checks methods for cases where a <c>System.Diagnostics.Stopwatch</c> could be /// used instead of using <c>System.DateTime</c> to compute the time required for an action. - /// This does not affect execution nor performance (much) but it improves source - /// code readability. This rule only applies to assemblies compiled with the - /// .NET framework version 2.0 (or later). + /// Stopwatch is preferred because it better expresses the intent of the code and because (on + /// some platforms at least) StopWatch is accurate to roughly the microsecond whereas + /// DateTime.Now is only accurate to 16 milliseconds or so. This rule only applies to assemblies + /// compiled with the .NET framework version 2.0 (or later). /// </summary> /// <example> /// Bad example: |