Skip to main content

add-copy-with

added in: 1.2.0
⚙️

Warns when a class that matches the config does not declare a copyWith method.

⚙️ Config

Set class-name-pattern (default is none) to configure the list of class names that need to declare a copyWith method.

Set file-name-pattern (default is none) to configure the list of file names with classes that need to declare a copyWith method.

dart_code_metrics:
...
rules:
...
- add-copy-with:
class-name-pattern: State$
file-name-pattern: '.model.dart'
note

This rule requires configuration in order to highlight any issues.

Example

❌ Bad:

// LINT
class SomeState {
final String value;

const SomeState({required this.value});
}

✅ Good:

class SomeState {
final String value;

const SomeState({required this.value});

SomeState copyWith({String value}) => SomeState(value: value ?? this.value);
}