Skip to content

proposal: null_aware_followed_by_null_assert #57134

@srawlins

Description

@srawlins

null_aware_followed_by_null_assert

Description

This one is a little odd, but I've seen a few cases. In code like this:

    foobarDateRange = (foobarDateRange
          .clampSomething(Something.VALUE)!
          .applySomething()
          ?.clampToSomething(Something.OTHER_VALUE)!)!;

It's a bit hard to follow the parens and bangs, but that last line essentially has ?.foo(bar)! in it. I don't think there is ever any reason to have a null-aware method call or null aware property access (or chain of these) followed by a null-assert. It fails in the same way as !.foo(bar), with a more-or-equally informative stack trace, and is more readable.

Kind

Readability

Bad Examples

a.b?.c!;
a.b?.c()!;
a.b?.c.d().e!;

Not sure if this needs to be careful around cascades...

Good Examples

Add a few examples that demonstrate a “good” adoption of this lint’s principle.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packagelinter-lint-proposallinter-status-pendingtype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions