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

[BUG] NUnit1018 doesn't recognize collection expression #726

Open
adaskos-signal opened this issue Apr 11, 2024 · 6 comments
Open

[BUG] NUnit1018 doesn't recognize collection expression #726

adaskos-signal opened this issue Apr 11, 2024 · 6 comments

Comments

@adaskos-signal
Copy link

In the following pseudo-code:

[TestCaseSource(typeof(MyClass), nameof(MyMethod), [1, 2, 3])]

NUnit analyzer raises an error:

The TestCaseSource provides '0' parameter(s), but the target method expects '3' parameter(s)

It seems it doesn't understand [1,2,3] as an object array.
So one needs to avoid/supress IDE0300 suggestion for those cases.

@manfred-brands
Copy link
Member

Thanks for reporting.

Object arrays didn't exist when this rule was written. My main concern is if I can add this without requiring NET 8.0 SDK or if we need different binaries depending on SDK.

@adaskos-signal
Copy link
Author

It seems CollectionExpressionSyntax was introduced in Roslyn 4.7.0. Theoretically it's still .NET Standard compatibile.

@manfred-brands
Copy link
Member

Roslyn versions are not related to SDK versions. It is part of C#12.

@adaskos-signal
Copy link
Author

All I meant is that for you to handle the new collection expression syntax, you'll have to update Microsoft.CodeAnalysis, but it doesn't require targeting a higher SDK.

@manfred-brands
Copy link
Member

Unfortunately it is not as simple.
Using NET 8 SDK to build the analyzer is not the problem. Increasing the version of that packet means that anybody using the analyzer needs to use an SDK with that version as the nuget package depends on a dll which only comes with the compiler.

When we moved to version 3 we maintained two different versions of the analyzer.

There are ways to support multiple SDKs one which I have done for another analyzer is to add an extra dll to the package for analyzers requiring later versions. Another way is to use private versions of the new types like StyleCop does.

@adaskos-signal
Copy link
Author

I read a bit about it. It's a pity it works like this. Makes life hard for those publishing analyzers if they want to keep up with the new syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants