Rules / Style / prefer-correct-type-name

prefer-correct-type-name

lint/style/prefer-correct-type-name
recommended
Same as prefer-correct-type-name · Dart Code Metrics

Flags type declarations whose name is not well-formed UpperCamelCase.

Consistent UpperCamelCase type names are a core Dart convention that keeps types visually distinct from members and values. A name is accepted only when it starts with an uppercase ASCII letter, contains no $, and — after a single leading underscore is stripped — is between 3 and 40 characters long; anything else is reported. The check covers classes, mixins, mixin classes, enums, named extensions, extension types, and type aliases. It inspects the declared name's spelling only, so it does not enforce interior capitalization such as an acronym written in all caps.

Invalid

example.dartdart
// Lowercase names should be flagged
class foo {}

// Too short (only 2 chars)
class Ab {}

// Lowercase enum
enum color { red, green }

// Too short mixin (2 chars)
mixin mx {}

// Too short typedef (2 chars)
typedef cb = void Function();

// Contains dollar sign
class Foo$Bar {}

// Too long (41 chars)
class VeryLongNameThatExceedsTheFortyCharacterLimit {}

// Extension with name that's too short
extension st on String {}

// ExtensionType with non-uppercase name
extension type val(int x) {}
Type name 'foo' should be in UpperCamelCase and between 3 and 40 characters.
1// Lowercase names should be flagged
2class foo {}
Type name 'Ab' should be in UpperCamelCase and between 3 and 40 characters.
4// Too short (only 2 chars)
5class Ab {}
Type name 'color' should be in UpperCamelCase and between 3 and 40 characters.
7// Lowercase enum
8enum color { red, green }
Type name 'mx' should be in UpperCamelCase and between 3 and 40 characters.
10// Too short mixin (2 chars)
11mixin mx {}
Type name 'cb' should be in UpperCamelCase and between 3 and 40 characters.
13// Too short typedef (2 chars)
14typedef cb = void Function();
Type name 'Foo$Bar' should be in UpperCamelCase and between 3 and 40 characters.
16// Contains dollar sign
17class Foo$Bar {}
Type name 'VeryLongNameThatExceedsTheFortyCharacterLimit' should be in UpperCamelCase and between 3 and 40 characters.
19// Too long (41 chars)
20class VeryLongNameThatExceedsTheFortyCharacterLimit {}
Type name 'st' should be in UpperCamelCase and between 3 and 40 characters.
22// Extension with name that's too short
23extension st on String {}
Type name 'val' should be in UpperCamelCase and between 3 and 40 characters.
25// ExtensionType with non-uppercase name
26extension type val(int x) {}

Valid

example.dartdart
// Standard class with UpperCamelCase
class Foo {}

// Longer descriptive name
class HttpClient {}

// Private class with underscore prefix (stripped, "Internal" is 8 chars and uppercase)
class _Internal {}

// Enum with proper case
enum Color { red, green }

// Mixin with proper case
mixin Loggable {}

// TypeAlias with proper case
typedef Callback = void Function();

// ExtensionType with proper name
extension type IntId(int value) {}

// Extension without name (should not be checked)
extension on String {}

// Extension with a proper name
extension StringX on String {}

// Edge case: exactly 3 chars (minimum)
class Foo {}

// Edge case: exactly 40 chars
class HttpClientWithVeryDetailedNameHere {}

// Private type with valid stripped name
class _HttpClientInternal {}

How to configure

Set the severity of prefer-correct-type-name in your falcon.json:

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "prefer-correct-type-name": "error"
      }
    }
  }
}