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

RCS1163 unused parameter error even with leading underscore #1594

Open
KoltesDigital opened this issue Dec 6, 2024 · 3 comments
Open

RCS1163 unused parameter error even with leading underscore #1594

KoltesDigital opened this issue Dec 6, 2024 · 3 comments

Comments

@KoltesDigital
Copy link

Hi,

I thought parameters starting with _ would be tolerated (i.e. would not raise an error) as of #244 / 0001c0c . There's even a test at the end of the commit!

Context: we're developing some Unity project, and it's well known for adding magic methods to do custom behaviors without explicitly implementing C# interfaces. For instance, this function would be invoked after assets have been loaded, and it needs four/five arguments, but we may not use all of them. Even with underscores, errors are raised.

error RCS1163: Unused parameter '_deletedAssets'.
...

I'm using Roslynator.Analyzers version 4.3.0. This happens both with roslynator version 0.9.3.0 and with dotnet (format) version 7.0.410.

@josefpihrt
Copy link
Collaborator

Hi,

So this MR fixes the case when parameter name consists of one or more underscores.

Parameter starting with underscore is a different case. It's definitely possible to suppress RCS1163 for this case. The question is whether is it a common convention that unused parameter's name should start with underscore. Maybe it would be better to create editorconfig option for it.

@KoltesDigital
Copy link
Author

Ha, I misread that commit. Meanwhile, I just learned that this case, variable names with only underscores, is a convention in Dart. Also I just discovered that built-in rule IDE0060 silences _, and _ followed by digits.

Roslynator wouldn't complain, but I'd do. I prefer to keep the original names around to know what they are about and why I've chosen not to use them, especially since they are all of the same type. Arguably, with a good test coverage and documentation, it may be redundant.

IMHO prefixing unused symbols with an underscore is a common convention, at least in Rust, TypeScript, Python... I even remember that with one language, actually using such a parameter triggers a linter error, because you're using a parameter that is not supposed to be used, so as to force you to drop the leading underscore.

I can't tell about adding this feature in here or in editorconfig.

@josefpihrt
Copy link
Collaborator

I thought about it and I would say that current implementation is fine as a default.

If anybody would be interested I would implement it as a opt-in, i.e. add editorconfig option that will cause that parameters whose name starts with underscore won't be reported as unused.

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

No branches or pull requests

2 participants