equatable_lint_x 0.4.3
equatable_lint_x: ^0.4.3 copied to clipboard
This is a set of rules to make classes using Equatable more maintainable. We make sure your class use all its fields for comparaison even those of its ancestor if necessary.
equatable_lint_x #
This package used the analysis_server_plugin package.
Table of content #
Setup local #
- In your
pubspec.yaml, add thesedev_dependencies:
dev_dependencies:
equatable_lint_x:
- In your
analysis_options.yaml, add this plugin:
plugins:
equatable_lint_x:
# Optional : Disable unwanted rules
plugins:
equatable_lint_x:
diagnostics:
always_call_super_props_when_overriding_equatable_props: false
-
Run
flutter pub getordart pub getin your package. -
Possibly restart your IDE.
Setup CI #
You will see the errors with the usualflutter analyze or dart analyze commands.
To ignore a lint #
To ignore one of this plugin rule, you need to add the plugin name before the lint code like this:
// ignore: equatable_lint_x/some_code
// ignore_for_file: equatable_lint_x/some_code
All the lints #
missing_field_in_equatable_props #
Class extending Equatable should put every fields 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 => [];
}
Class using EquatableMixin should put every fields into equatable props
Good:
class MyClass with EquatableMixin {
const MyClass({this.myField});
final String? myField;
@override
List<Object?> get props => [myField];
}
Bad:
class MyClass with EquatableMixin {
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];
}
All the lints' fixes #
missing_field_in_equatable_props fixes #
Add all fields to equatable props

Add field to equatable props

Create equatable props with all fields

Create equatable props with single field

always_call_super_props_when_overriding_equatable_props fixes #
Call super in overridden equatable props

All the assists #
Make class extend Equatable #

Make class use EquatableMixin #
