equatable_lint 0.1.1 copy "equatable_lint: ^0.1.1" to clipboard
equatable_lint: ^0.1.1 copied to clipboard

outdated

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.

example/lib/main.dart

// ignore_for_file: avoid_field_initializers_in_const_classes, overridden_fields
import 'package:equatable/equatable.dart';

class ExampleA extends Equatable {
  const ExampleA({this.exampleA});

  // A lint will appear here because exampleA is not in not in props
  final String? exampleA;

  @override
  List<Object?> get props => [];
}

class ExtendExampleA1 extends ExampleA {
  const ExtendExampleA1({this.extendExampleA});

  // A lint will appear here because extendExampleA is not in not in props
  final String? extendExampleA;

  @override
  List<Object?> get props => super.props..addAll([]);
}

class ExtendExampleA2 extends ExampleA {
  const ExtendExampleA2({this.extendExampleA});

  // A lint will appear here because extendExampleA is not in not in props
  final String? extendExampleA;

  // No lint appear here because this is a getter
  bool get test => false;

  @override
  // A lint will appear here because props doesn't call super.props
  // So it doesn't count fields defined in ExampleA class
  List<Object?> get props => [];
}

class ExtendExampleA3 extends ExampleA {
  const ExtendExampleA3();
}

class ExampleB extends Equatable {
  ExampleB({this.exampleB});

  // A lint will appear here because exampleB is not in not in props
  final String? exampleB;

  @override
  late final List<Object?> props = [];
}

class ExtendExampleB extends ExampleB {
  ExtendExampleB({this.extendExampleB});

  // A lint will appear here because extendExampleB is not in not in props
  final String? extendExampleB;

  @override
  late final List<Object?> props = super.props..addAll([]);
}

abstract class ExampleC extends Equatable {
  const ExampleC();
}

// A lint will appear here because ExtendExampleC does not override props field
class ExtendExampleC extends ExampleC {
  const ExtendExampleC({this.extendExampleC});

  final String? extendExampleC;
}

abstract class ExampleD extends Equatable {
  const ExampleD({this.exampleD});

  final String? exampleD;

  @override
  List<Object?> get props => [exampleD];
}

// A lint will appear here because ExtendExampleD does not override props field
class ExtendExampleD extends ExampleD {
  const ExtendExampleD({this.extendExampleD});

  final String? extendExampleD;

  bool get test => false;
}
7
likes
0
points
1.31k
downloads

Publisher

verified publisherbam.tech

Weekly Downloads

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.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

analyzer, analyzer_plugin, collection, custom_lint_builder, equatable, source_gen

More

Packages that depend on equatable_lint