Skip to content

match_class_name_pattern

v1.0.0WarningConfigurableClass Naming

Flags a class, mixin, enum or extension type whose name does not match the pattern you configure.

This is the general form of use_class_prefix and use_class_suffix: those key on a base type, this one keys on the name alone. Reach for it when the convention belongs to a folder rather than to a hierarchy — every type under presentation/ ends in Page, every type under dto/ ends in Dto.

This rule is in no preset and reports nothing until you set pattern:. Every example below shows the configuration that produces it.

analysis_options.yaml
many_lints:
rules:
match_class_name_pattern:
pattern: '[A-Z][A-Za-z0-9]*Page'
include: ['lib/**/presentation/**']

The pattern must match the whole name — [A-Z][A-Za-z0-9]*Page accepts HomePage and rejects HomePageExtra.

rules:
match_class_name_pattern:
pattern: '[A-Z][A-Za-z0-9]*Page'
include: ['lib/**/presentation/**']
// Don't — lib/checkout/presentation/home.dart
class Home {} // LINT
class CheckoutScreen {} // LINT
// Do
class HomePage {}
class CheckoutPage {}
rules:
match_class_name_pattern:
pattern: 'App[A-Z][A-Za-z0-9]*'
include: ['lib/design_system/**']
// Don't
class PrimaryButton {} // LINT
// Do
class AppPrimaryButton {}

A pattern that names only the allowed characters catches the shapes a style guide usually spells out in prose:

rules:
match_class_name_pattern:
pattern: '[A-Z][A-Za-z]*'
// Don't
class Http_Client {} // LINT
class Base64Codec {} // LINT — digits are not in the pattern
// Do
class HttpClient {}

Alternation covers a layer that legitimately holds two kinds of type:

rules:
match_class_name_pattern:
pattern: '[A-Z][A-Za-z0-9]*(Dto|Response)'
include: ['lib/**/data/**']
// Don't
class User {} // LINT
// Do
class UserDto {}
class UserResponse {}

Enums, mixins and extension types are checked by the same pattern as classes:

// Don't
enum Status {} // LINT under '[A-Z][A-Za-z0-9]*Dto|Response'
// Do
enum StatusDto { active, closed }
Option Type Default Description
pattern string — A regular expression the whole name must match. Unset means the rule is silent

include and exclude are the standard per-rule path filters, and are what make a folder-scoped convention expressible at all.

One pattern per project. The rule takes a single pattern:, so two conventions in two folders need the rule listed once and scoped with include: — there is no per-entry list. Where two different shapes must coexist under one include, use alternation as above.

Whole-name matching. Page alone matches only a class named exactly Page; write [A-Za-z0-9]*Page to mean “ends in Page”.

A bad pattern is silent. An expression that does not compile is ignored rather than throwing, because a plugin cannot report a diagnostic against a YAML file. If nothing fires, check the regex in isolation first.

To disable this rule:

many_lints.yaml
rules:
match_class_name_pattern: false

To keep the rule on but skip certain paths, use per-rule exclude.