Resharper CLI Cleanup 正在删除 C# 显式参数名称
我的 editorconfig 中的 [*.cs] 下有此行:
resharper_redundant_explicit_positional_property_declaration_highlighting = none
但是当我运行 dotnet jb cleanupcode MySolution.sln
时,命名参数仍会被删除。这些很重要,例如在长参数列表中,我们希望在代码审查中验证我们没有传递例如电话名称,反之亦然。
关于为什么这种情况仍然会发生的任何线索吗? Resharper CLI 尊重我的 .editorconfig 文件的其余部分,例如,当我更改这些内容时,行长度和缩进大小。
我可以通过打乱参数的顺序来解决这个问题,这样 CLI 就不会认为它们是多余的,但这看起来很老套。
或者,也许有一种方法可以在声明记录时强制执行命名参数(类似于构造 JS 接口),但我还没有找到。
运行清理之前的示例代码:
var account = new Account(
Name: app.Applicant.CompanyName,
BillingStreet: app.Applicant.MailingAddress1,
Address_Unit: app.Applicant.MailingAddress2);
和之后:
var account = new Account(
app.Applicant.CompanyName,
app.Applicant.MailingAddress1,
app.Applicant.MailingAddress2);
I have this line under [*.cs] in my editorconfig:
resharper_redundant_explicit_positional_property_declaration_highlighting = none
But when I run dotnet jb cleanupcode MySolution.sln
, named parameters are still removed. These are important e.g. in a long param list where we want to verify in code review that we are not passing e.g. Name for Phone or vice versa.
Any clue on why this would still be happening? Resharper CLI is respecting the rest of my .editorconfig file, e.g. line length and indent size when I change those.
I can work around this by scrambling the order of parameters so the CLI doesn't think they're redundant, but that seems pretty hacky.
Alternatively, maybe there's a way to enforce named parameters when declaring a record (similar to constructing a JS interface), but I haven't found it.
Sample code before running cleanup:
var account = new Account(
Name: app.Applicant.CompanyName,
BillingStreet: app.Applicant.MailingAddress1,
Address_Unit: app.Applicant.MailingAddress2);
And after:
var account = new Account(
app.Applicant.CompanyName,
app.Applicant.MailingAddress1,
app.Applicant.MailingAddress2);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终需要为 Resharper 清理创建一个自定义配置文件。
(感谢 @whybird 提供相关评论)
I ended up needing to create a custom Profile for Resharper clean-up.
(Thanks to @whybird for providing the relevant comment)