Avoid various capitalizations for method name
Matches methods whose names differ only in capitalization (like ProcessOrderId vs ProcessOrderID). Choose a single capitalization application-wide for readability, maintainability and consistency.
Severity goes from Medium to Critical when various capitalizations occur within the same type: not just convention, it is error-prone — clients must investigate which version to call.
Severity goes from Medium to Critical when various capitalizations occur within the same type: not just convention, it is error-prone — clients must investigate which version to call.
How to fix
Choose a single application-wide capitalization, or use method names that don't differ only by capitalization.
Debt is proportional to the number of capitalizations found (2 minimum).
Debt is proportional to the number of capitalizations found (2 minimum).
CQLinq source
This rule is written in CQLinq, C# LINQ over the NDepend code model. It ships with every new NDepend project: you can read it, adapt it, or use it as a starting point for your own custom rules.
// <Name>Avoid various capitalizations for method name</Name>
// <Id>ND2020:AvoidVariousCapitalizationsForMethodName</Id>
warnif count > 0
let lookup = JustMyCode.Methods.ToLookup(m => m.SimpleName, StringComparer.OrdinalIgnoreCase)
from grouping in lookup
where grouping.Count() > 1
let name = grouping.First().SimpleName
let method = grouping.FirstOrDefault(m => m.SimpleName != name)
where method != null
let nbCapitalizations = grouping.ToLookup(m => m.SimpleName).Count
// Increase the severity if various capitalizations are found in same class
let differentCapitalizationInSameType =
grouping.ToLookup(m => m.ParentType)
.Any(groupingPerType => groupingPerType.ToLookup(m => m.SimpleName).Count > 1)
select new {
method,
methods = grouping.Distinct(m => m.SimpleName).ToArray(),
nbCapitalizations,
Debt = (nbCapitalizations * 6).ToMinutes().ToDebt(),
Severity = differentCapitalizationInSameType ? Severity.Critical : Severity.Medium
}
//<Expl>
// Several capitalizations for this method name are used:
// *{1}*. Choose a single capitalization to improve
// overall readability, maintainability, team collaboration
// and consistency.
//</Expl>
//<Desc>
// Matches methods whose names differ only in capitalization (like
// *ProcessOrderId* vs *ProcessOrderID*). Choose a single capitalization
// application-wide for readability, maintainability and consistency.
//
// Severity goes from *Medium* to *Critical* when various capitalizations
// occur within the same type: not just convention, it is error-prone —
// clients must investigate which version to call.
//</Desc>
//<HowToFix>
// Choose a single application-wide capitalization, or use method names that
// don't differ only by capitalization.
//
// Debt is proportional to the number of capitalizations found (2 minimum).
//</HowToFix>
Open in the interactive Rules Explorer · All default rules
Naming Conventions: all 23 items
- Instance fields naming convention ND2000
- Static fields naming convention ND2001
- Interface name should begin with a 'I' ND2002
- Abstract base class should be suffixed with 'Base' ND2003
- Exception class name should be suffixed with 'Exception' ND2004
- Attribute class name should be suffixed with 'Attribute' ND2005
- Types name should begin with an Upper character ND2006
- Methods name should begin with an Upper character ND2007
- Do not name enum values 'Reserved' ND2008
- Avoid types with name too long ND2009
- Avoid methods with name too long ND2010
- Avoid fields with name too long ND2011
- Avoid having different types with same name ND2012
- Avoid prefixing type name with parent namespace name ND2013
- Avoid naming types and namespaces with the same identifier ND2014
- Don't call your method Dispose ND2015
- Methods prefixed with 'Try' should return a boolean ND2016
- Properties and fields that represent a collection of items should be named Items. ND2017
- DDD ubiquitous language check ND2018
- Avoid fields with same name in class hierarchy ND2019
- Avoid various capitalizations for method name ND2020
- Controller class name should be suffixed with 'Controller' ND2021
- Nested class members should not mask outer class' static members ND2022