avoid_non_null_assertion_operator 1.0.0 copy "avoid_non_null_assertion_operator: ^1.0.0" to clipboard
avoid_non_null_assertion_operator: ^1.0.0 copied to clipboard

A custom lint package to forbid the non-null assertion operator (!).

avoid_non_null_assertion_operator #

A custom lint package for Dart/Flutter that helps enforce safer null handling by prohibiting the use of the non-null assertion operator (!).

Features #

  • Detects and reports usage of the non-null assertion operator (!)
  • Helps enforce safer null handling practices
  • Integrates with Dart's analyzer

Getting started #

Add this to your package's pubspec.yaml file:

dev_dependencies:
  custom_lint:
  avoid_non_null_assertion_operator:

Usage #

Add the following to your analysis_options.yaml:

analyzer:
  plugins:
    - custom_lint
  errors:
    avoid_non_null_assertion_operator: error

The lint will now report errors for code like this:

String? nullable = "test";
String nonNullable = nullable!; // Error: Avoid using the non-null assertion operator (!)

Instead, use safer alternatives like:

String? nullable = "test";
String nonNullable = nullable ?? "default"; // Use null coalescing
// or
if (nullable != null) {
  String nonNullable = nullable; // Use null check
}

Additional information #

This package is designed to help maintain safer null handling practices in Dart/Flutter projects. It encourages the use of explicit null checks and null coalescing operators instead of force-unwrapping nullable values.

For more information about null safety in Dart, visit the official documentation.

0
likes
0
points
1.18k
downloads

Publisher

unverified uploader

Weekly Downloads

A custom lint package to forbid the non-null assertion operator (!).

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

analyzer, custom_lint, custom_lint_builder

More

Packages that depend on avoid_non_null_assertion_operator