-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Lint on unnecessary {} in string interpolation (Style Guide - Proposed) #57149
Comments
I wouldn't want this. IMHO the curly braces improve the visibility that the string contains an interpolated part. |
@zoechi: I'm on the fence about this one myself. @munificent is the reporter... Perhaps Bob cares to elaborate on the rationale? |
I see a decent amount of Dart code that uses Not needing them in Dart is a nice feature that makes the strings shorter and less jumbled up with punctuation. A linter can help make sure users know this is even an option. I don't find code harder to read when it leaves off the curlies—all of my IDEs and text editors will highlight interpolation in a different color anyway, which is more helpful than some extra punctuation. |
I definitely do remove |
I usually also don't have complex expressions but I often change between values which need a prefix and which don't, during development (just use the I don't care how others do it but I wouldn't want an analyzer or linter bothering me about this. |
Hopefully, the linter will be able to do this for you eventually. :) |
Removing would probably be easy, but adding? |
Great conversation! A few thoughts.
Incidentally, I took a quick crack at implementing this rule and wrote a corresponding test. I did this mainly to prove out that I could get things running from end to end. Anyway, comments and additional test cases are most welcome. |
Fixed as of e7c35b3 |
Is there any way to remove this lint warning permanently in Android Studio? |
@dark-chocolate lints need to be enabled explicitly in |
Thanks @zoechi , it worked. |
Migrated from dartbug.com/22025:
If the interpolated expression is just a simple identifier (and the string after the interpolation is not alphanumeric), then the {} are not needed. Given:
"Hi, ${name}!"
The linter should suggest:
"Hi, $name!"
The text was updated successfully, but these errors were encountered: