Skip to content

Linter rule request - Avoid Bang operator #59476

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

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

Linter rule request - Avoid Bang operator #59476

har5hit opened this issue May 16, 2024 · 1 comment
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead.

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 #58535.

Feel free to add any more context there.

Thanks!

@pq pq closed this as completed May 16, 2024
@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 20, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead.
Projects
None yet
Development

No branches or pull requests

3 participants