dotnet / dotnet/roslynator

Suggestion: string.Format without arguments

Open
#520 0 comments 0 reactions 0 assignees View on GitHub
Area-Analyzers Feature Request
Dominant language
C#
Stars
3.5k
Forks
294
Avg merge
2h 30m
Merged PRs (30d)
4

Description

Since the `string.Format` method allows for an arbitrary number of format arguments it also accepts 0. However in case one provides zero arguments this is likely a mistake:

string.Format("some-text here")

->

"some-text here"

The code is not really identical, so I'm not sure if it's generally useful.

For example `string.Format` removes double curly braces `string.Format("{{0}}") == "{0}"` and throws on *any* placeholder `string.Format("{0}") == new FormatException`, but in most cases a `string.Format` without arguments is likely an oversight or a downright bug.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.