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

Unused format string literals (string interpolation) #13651

Open
alice-i-cecile opened this issue Nov 4, 2024 · 1 comment
Open

Unused format string literals (string interpolation) #13651

alice-i-cecile opened this issue Nov 4, 2024 · 1 comment
Labels
A-lint Area: New lints

Comments

@alice-i-cecile
Copy link

What it does

When the user attempts to use {}, {:?} or similar invocations, we should expect them to actually have a value. Warn the user when no value is provided and "{}" or the like would actually be printed.

Inspired by bevyengine/bevy#16228

Advantage

These errors are likely an oversight, and they should either be removed or the correct value added.

Drawbacks

It will make it harder to draw strange ASCII faces in your error messages.

Example

            .expect("Component id: {:?}, already has an on_add hook")

Could be written as:

            .expect("Component already has an on_add hook")
@alice-i-cecile alice-i-cecile added the A-lint Area: New lints label Nov 4, 2024
@Piturnah
Copy link

Piturnah commented Nov 4, 2024

The problem here, as I understand it, is that expect takes a &str, not a format string. So you actually couldn't supply a value.

In my opinion, a lint should be added for &str literals which include format-string syntax (like {:?}) to make sure the user actually intended the literal string "{:?}" or whether they thought they were in a format string and forgot a value.

Hopefully it's clear what I mean...

Edit: consider -- if a value was supposed to be provided, then it would be a compile fail, rather than something for the linter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

2 participants