Skip to content

CA2241 should respect new StringSyntaxAttribute.CompositeFormat #6012

@stephentoub

Description

@stephentoub

Analyzer

Diagnostic ID: CA2241

Describe the improvement

"CA2241: Provide correct arguments to formatting methods" has a hardcoded list of methods that accept a composite format string. But in .NET 7, the new StringSyntaxAttribute exists and includes a StringSyntaxAttribute.CompositeFormat, which has been used to annotate many string parameters that are expected to be passed a composite format string. CA2241 should ideally apply to any parameter that accepts such a format string, at least in terms of validating the correctness of the syntax of the string.

Describe suggestions on how to achieve the rule

For any method invocation, look at the parameters to see if any is attributed with [StringSyntax(StringSyntaxAttribute.CompositeFormat)], and if it is, validate that the argument being passed for that parameter is correctly formed (as it does today for the hardcoded list).

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions