WiseTechGlobal / WTG.Analyzers

Analyzers from WiseTech Global to enforce our styles, behaviours, and prevent common mistakes.
Other
15 stars 3 forks source link

Relax WTG3103 for comma separated items. #181

Closed brian-reichle closed 1 year ago

brian-reichle commented 2 years ago

The following triggers WTG3103, apparently because the trailing comma is considered to be part of the broader list rather than the ISpanFormattable case itself.

return item switch
{
    null => builder,
#if NET6_0_OR_GREATER
    ISpanFormattable spanFormattable => builder.AppendSpanFormattableValue(formatProvider, spanFormattable, format),
#endif
    IFormattable formattable => builder.AppendFormattableValue(formatProvider, formattable, format),
    _ => builder.Append(item.ToString()),
};

Array initializers and enums have the same issue.

var bob = new[]
{
    "A",
#if NET6_0_OR_GREATER
    "B",
#endif
    "C",
};
enum MetaSyntaticVariable
{
    A,
#if NET6_0_OR_GREATER
    B,
#endif
    C,
}

Perhaps we should relax WTG3103 when dealing with comma separated lists and treat the comma as part of the preceding item.

yaakov-h commented 2 years ago

Sounds good to me.