Skip to main content

add-copy-with

added in: 1.2.0
warning
⚙️

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

Use class-name-pattern configuration, to filter class names that need to declare a copyWith method.

Use file-name-pattern configuration, to filter file names with classes that need to declare a copyWith method.

⚙️ Config example

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

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);
}