dart-lang / linter

Linter for Dart.
https://dart.dev/tools/linter-rules
BSD 3-Clause "New" or "Revised" License
628 stars 172 forks source link

`use_is_even_rather_than_modulo` false positive on constant asserts #4958

Closed Branvier closed 1 month ago

Branvier commented 1 month ago

Describe the quick-fix The linter tell me to use .inEven, although I can't in this scenario. I'd have to remove the const from Widget constructor for that.

Examples

class PartnersCarousel extends StatefulWidget {
  const PartnersCarousel({
    super.key,
    required this.itemsPerPage,
    required this.partners,
  })
// LINT: use_is_even_rather_than_modulo
  : assert(itemsPerPage % 2 == 0, 'itemsPerPage must be even');
  final int itemsPerPage;
  final List<Partner> partners;

  @override
  State<PartnersCarousel> createState() => _PartnersCarouselState();
}

Additional context isEven can't be used in "const" contexts and therefore should not be recommended in these situations.

bwilkerson commented 1 month ago

Duplicate of #4915.

This was recently fixed, though it will take time for the fix to appear in a dev or stable build.

arthurbcd commented 1 month ago

Great work as always! Thanks.