NSubstitute.Analyzers icon indicating copy to clipboard operation
NSubstitute.Analyzers copied to clipboard

Respect VS naming styles when introducing substitute

Open cieciurm opened this issue 2 years ago • 3 comments

Hello,

Thanks for your work on the Analyzer, it's a great package!

I wanted to start using it at work, but I found one issue with the introduce substitute code refactoring. Is it possible to respect the VS naming preferences, f.e. to create the substitutes with underscore prefix? I'm using this approach.

If no, perhaps the .editorconfig could be used?

I would be very happy to work on this improvement, just wanted to confirm first if it's technically feasible :)

Thanks

cieciurm avatar Dec 05 '22 20:12 cieciurm

Just to follow up, I have checked the behavior using .editorconfig.

So, I've added .editorconfig to a project with the following rules:

[*.{cs,vb}]
dotnet_naming_rule.private_members_with_underscore.symbols  = private_fields
dotnet_naming_rule.private_members_with_underscore.style    = prefix_underscore
dotnet_naming_rule.private_members_with_underscore.severity = suggestion

dotnet_naming_symbols.private_fields.applicable_kinds           = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
dotnet_naming_symbols.private_fields.required_modifiers         = readonly

dotnet_naming_style.prefix_underscore.capitalization = camel_case
dotnet_naming_style.prefix_underscore.required_prefix = _

It's been detected by VS:

image

But still the introduced substitutes names are not starting with an underscore.

cieciurm avatar Dec 11 '22 15:12 cieciurm

Hi @cieciurm

Thanks for your work on the Analyzer, it's a great package!

Glad you like it

Is it possible to respect the VS naming preferences, f.e. to create the substitutes with underscore prefix?

Not possible at the moment, related Roslyn API was not made public yet

https://github.com/dotnet/roslyn/issues/31655 https://github.com/JosefPihrt/Roslynator/issues/473#issuecomment-445164565 https://github.com/dotnet/roslyn/issues/22884#issuecomment-445173009

tpodolak avatar Dec 11 '22 17:12 tpodolak

Thanks a lot for the explanation and the links

cieciurm avatar Dec 12 '22 06:12 cieciurm