Skip to content

match_class_name_pattern

v1.0.0WarningConfigurableClass Naming

This rule flags a class, mixin, enum or extension type whose name does not match the configured pattern.

This is the general form of use_class_prefix and use_class_suffix: a project that wants one naming shape, or wants every class in one folder to end in Page, states it once as a regular expression rather than as a list of affixes.

The pattern must match the whole name, so [A-Z][A-Za-z0-9]*Page rejects HomePageExtra. An invalid pattern is ignored rather than throwing, like every other malformed option.

Narrow it to a subtree with the per-rule include, which is where this rule earns its place:

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

This rule is in no preset.

class Home {} // with pattern '[A-Z][A-Za-z0-9]*Page'
class HomePage {}

This rule reports nothing until you set a pattern:

many_lints.yaml
rules:
match_class_name_pattern:
pattern: '[A-Z][A-Za-z0-9]*Page'
analysis_options.yaml
many_lints:
rules:
match_class_name_pattern:
pattern: '[A-Z][A-Za-z0-9]*Page'
Option Type Default Description
pattern string A regular expression the whole name must match. Unset means the rule is silent

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.