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

extend INVALID_NULL_AWARE_OPERATOR for extensions on nullable #48980

Closed

Conversation

a14n
Copy link
Contributor

@a14n a14n commented May 8, 2022

Following up on dart-lang/linter#3379 (comment) to add a warning when using null aware operator with a member defined in an extension on nullable type.

extension on String? {
  bool get isNullOrEmpty {
    var self = this;
    return self == null || self.isEmpty;
  }
}

main() {
  String? s = null;
  s?.isNullOrEmpty; // WARN here
  s.isNullOrEmpty; // OK
}

@a14n
Copy link
Contributor Author

a14n commented May 8, 2022

@albertms10
Copy link
Contributor

The code block in the description contains syntax issues. One way to go may be:

extension on String? {
  bool get isNullOrEmpty => this == null || this!.isEmpty;
}

@a14n
Copy link
Contributor Author

a14n commented May 9, 2022

@albertms10 Thanks for letting me know. I updated the snippet.

@a14n a14n closed this May 10, 2022
@a14n
Copy link
Contributor Author

a14n commented May 10, 2022

Closing to migrate to linter.

@a14n a14n deleted the invalid_null_aware_operator-extension branch May 10, 2022 21:00
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

Successfully merging this pull request may close these issues.

2 participants