equatable_lint_x 0.4.3 copy "equatable_lint_x: ^0.4.3" to clipboard
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 these dev_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 get or dart pub get in 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 all fields to existing equatable props sample

Add field to equatable props

Add field to existing equatable props sample

Create equatable props with all fields

Create equatable props with all fields sample

Create equatable props with single field

Create equatable props with single field sample

always_call_super_props_when_overriding_equatable_props fixes #

Call super in overridden equatable props

Call super in overridden equatable props sample

All the assists #

Make class extend Equatable #

Make class extend Equatable sample

Make class use EquatableMixin #

Make class use EquatableMixin sample

0
likes
150
points
246
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

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.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

analysis_server_plugin, analyzer, analyzer_plugin, collection

More

Packages that depend on equatable_lint_x