Type name is not PascalCase

ID

vbnet.maintainability.naming_class

Severity

info

Remediation Complexity

trivial

Remediation Risk

medium

Remediation Effort

low

Resource

Naming

Language

VB.NET

Description

Reports a Class, Structure, Interface or Module declaration whose name does not match PascalCase, that is ^[A-Z][A-Za-z0-9]*$ - names beginning in lower case such as customerRepository or iShipper, and names using separators such as Order_Line. Digits are accepted inside a name, so Point3D is not reported, and a generic type is judged on its own name rather than on its type parameters, so Repository(Of TEntity) is not reported either. This is a convention rule and is reported at informational severity.

Rationale

Capitalization is what lets a reader tell what kind of thing a name refers to without going to look up its declaration, and .NET has one convention for this that every framework and library already follows: PascalCase for types, an I prefix for interfaces, camelCase for parameters and locals. A type whose name starts in lower case reads as a variable in the place it matters most, the declaration - Dim repo As customerRepository looks like a copy-paste error - and once one file departs from the convention every name in the codebase has to be checked rather than recognised. Type names also cross assembly boundaries and become part of the public surface, so the cost of fixing this only ever grows: renaming after release breaks every consumer, while renaming at declaration time costs one refactoring.

The following code illustrates the pattern detected by this rule:

Namespace Ordering

    ' BAD: camelCase type name.
    ' FLAGGED: Type name is not PascalCase
    Public Class customerRepository
        Public Function Find(ByVal id As Integer) As Object
            Return Nothing
        End Function

Remediation

Rename the type to PascalCase - an initial capital letter, each subsequent word capitalized, no underscores or other separators: customerRepository becomes CustomerRepository, Order_Line becomes OrderLine, and invoiceHelpers becomes InvoiceHelpers. Interfaces additionally take a capital I prefix followed by a PascalCase name, so iShipper becomes IShipper. Treat acronyms as words and capitalize only their first letter when they are three letters or longer, as in XmlReader rather than XMLReader, while two-letter acronyms stay fully upper case, as in IOStream. Use the rename refactoring in the IDE so that every reference, including those in designer and generated files, is updated in the same step.

Configuration

This detector does not need any configuration.