Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid_non_null_assertion support IMap from FIC package as valid #165

Open
hectorAguero opened this issue Apr 22, 2024 · 2 comments
Open

Comments

@hectorAguero
Copy link

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
Copy link
Collaborator

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

@hectorAguero
Copy link
Author

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']!);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants