solid-software / solid_lints

🟧 Lints for Dart and Flutter based on software industry standards and best practices.
Other
36 stars 17 forks source link

avoid_non_null_assertion support IMap from FIC package as valid #165

Open hectorAguero opened 7 months ago

hectorAguero commented 7 months ago

Hi, currently using https://pub.dev/packages/fast_immutable_collections and with these lint give a warning for every IMap call.

Is feasible to add the exception? or maybe add the possibility to add valid types in the yaml file or disable the warning at all.

The warning is "Avoid using the bang operator. It may result in runtime exceptions."

illia-romanenko commented 7 months ago

Hi @hectorAguero, please provide an example of your code that fails. Thanks!

hectorAguero commented 7 months ago

I did find I can return a mutable map to avoid the lint message, but is more like a workaround

import 'dart:developer';
import 'package:fast_immutable_collections/fast_immutable_collections.dart';

void main() {
  /// Map<String, String> map
  final map = {'key': 'value'};

  /// IMap<String, String> immutableMap
  final immutableMap = map.lock;

  /// IMap<String, String> otherImmutableMap
  final otherImmutableMap = IMap(const {"key": 'value'});

  // Works fine, doesn't show any lint message:
  log(map['key']!);
  // Shows: avoid using the bang operator. It may result in runtime exceptions.
  log(immutableMap['key']!);
  log(otherImmutableMap['key']!);

  // Workaround to avoid the lint message:
  log(immutableMap.unlock['key']!);
  log(otherImmutableMap.unlock['key']!);
}