match_class_name_pattern
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.
many_lints: rules: match_class_name_pattern: pattern: '[A-Z][A-Za-z0-9]*Page' include: ['lib/**/presentation/**']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.
Examples
Section titled “Examples”Require a suffix inside one folder
Section titled “Require a suffix inside one folder”rules: match_class_name_pattern: pattern: '[A-Z][A-Za-z0-9]*Page' include: ['lib/**/presentation/**']// Don't — lib/checkout/presentation/home.dartclass Home {} // LINTclass CheckoutScreen {} // LINT
// Doclass HomePage {}class CheckoutPage {}Require a prefix
Section titled “Require a prefix”rules: match_class_name_pattern: pattern: 'App[A-Z][A-Za-z0-9]*' include: ['lib/design_system/**']// Don'tclass PrimaryButton {} // LINT
// Doclass AppPrimaryButton {}Reject underscores and digits anywhere
Section titled “Reject underscores and digits anywhere”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'tclass Http_Client {} // LINTclass Base64Codec {} // LINT — digits are not in the pattern
// Doclass HttpClient {}Allow one of several shapes
Section titled “Allow one of several shapes”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'tclass User {} // LINT
// Doclass UserDto {}class UserResponse {}Enums, mixins and extension types are checked by the same pattern as classes:
// Don'tenum Status {} // LINT under '[A-Z][A-Za-z0-9]*Dto|Response'
// Doenum StatusDto { active, closed }Options
Section titled “Options”| 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.
Known limitations
Section titled “Known limitations”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.
Turning this rule off
Section titled “Turning this rule off”To disable this rule:
rules: match_class_name_pattern: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”prefer_correct_type_name— Keep type names within a sensible length and correctly capitalised.use_class_prefix— Require a name prefix for classes deriving from a configured type.use_class_suffix— Require a name suffix for classes deriving from a configured type.prefer_correct_identifier_length— Keep identifier length within bounds.