I’m using C# 12 collection expressions to pass in a collection of items to a constructor:
// Pass an empty collection as an argument
var cache = new CustomFormatCache([]);
The primary constructor signature is:
public class CustomFormatCache(IEnumerable<TrashIdMapping> mappings) {...}
The analysis warning I get puts a yellow-squiggly under the semicolon, as shown in the screenshot below:
My expectation is that this warning is not presented, because this is clearly not an empty statement. I suspect the SonarLint plugin doesn’t know how to parse collection expressions.
Hi @voidpointer!
We support .Net 8 and C# 12 syntax starting from version 9.3 of the analyzer.
SonarLint for IntelliJ recently embedded this version on release 10.1.0.77128.
Can you please try again with the latest plugin version?
Hi, sorry for the delay.
So I started looking into this and it appears not to be on our side.
The rule implementation is trivial and it’s raising for every EmptyStatementSyntax.
Looking at the syntax with the current Roslyn main branch on Sharplab there is no EmptyStatement that could trigger our rule. Instead, with a less recent version suddenly an EmptyStatement appears after the LocalDeclarationStatement. This might explain why the rule was raising in your instance.
Are you using the latest version of the .Net 8 SDK from November 14?