equatable_custom_lint 1.0.1
equatable_custom_lint: ^1.0.1 copied to clipboard
This is a set of rules to make classes using Equatable more maintainable. We make sure here that every fields in an Equatable class is linked to the Equatable props getter.
equatable_custom_lint #
This package is based on a fork from the equatable_lint_ultimate which is a fork of equatable_lint package
This package used the custom_lint package
Sponsored by The Code Brothers #
Table of content #
Setup local #
- In your
pubspec.yaml
, add thesedev_dependencies
:
dev_dependencies:
custom_lint:
equatable_custom_lint:
- In your
analysis_options.yaml
, add this plugin :
analyzer:
plugins:
- custom_lint
# Optional : Disable unwanted rules
custom_lint:
rules:
- always_call_super_props_when_overriding_equatable_props: false
-
Run
flutter pub get
ordart pub get
in your package -
Possibly restart your IDE
Setup CI #
flutter analyze
or dart analyze
don't use this custom rule when checking your code
If you want to analyze your code with this rule in your CI, add a step that run flutter pub run custom_lint
or dart run custom_lint
All the lints #
missing_field_in_equatable_props #
Class extending Equatable should put every field into equatable props
Good:
class MyClass extends Equatable {
const MyClass({this.myField});
final String? myField;
@override
List<Object?> get props => [myField];
}
Bad:
class MyClass extends Equatable {
const MyClass({this.myField});
final String? myField;
@override
List<Object?> get props => [];
}
always_call_super_props_when_overriding_equatable_props #
Should always call super when overriding equatable props
Good:
class MyClass extends RandomClassExtendingEquatable {
const MyClass({this.newField});
final String? newField;
@override
List<Object?> get props => super.props..addAll([newField]);
}
Bad:
class MyClass extends RandomClassExtendingEquatable {
const MyClass({this.newField});
final String? newField;
@override
List<Object?> get props => [newField];
}