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

Linter rule request - Avoid Bang operator #4973

Closed
har5hit opened this issue May 16, 2024 · 1 comment
Closed

Linter rule request - Avoid Bang operator #4973

har5hit opened this issue May 16, 2024 · 1 comment

Comments

@har5hit
Copy link

har5hit commented May 16, 2024

Hello,

I would like to request a lint rule to avoid bang operator usage,

For ex:

String? a;
String b = a!;  // Should not be allowed

Developer should be forced to use,
String b = a ?? "default";

They can also create a scoped extension like kotlin for complex cases like,

extension ObjectExt<T> on T {
  R let<R>(R Function(T item) op) => op(this);
}

String b = a?.let((item) => "Hello $a") ?? "Hello Default";

Thank you

@lrhn lrhn transferred this issue from dart-lang/sdk May 16, 2024
@pq
Copy link
Member

pq commented May 16, 2024

Right! We've discussed something similar before and are tracking the idea in #3008.

Feel free to add any more context there.

Thanks!

@pq pq closed this as completed May 16, 2024
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