Skip to main content
 首页 » 编程设计

c#之StyleCop 规则适用于不同的支撑风格,而不是仅仅禁用它

2024年08月12日30cloudgamer

1st,我们要清楚 bracing style is mostly taste only - 也就是说,如果一个团队决定了某种品味,我有资格质疑谁(在合理范围内)。

问题是当您使用像 StyleCop 这样的工具时(顺便说一句。实际上还有其他 C# 工具像 StyleCop 吗?我的印象是它在 C# 生态系统中相当独特?)

StyleCop,默认情况下,强制执行某种支撑样式,我发现的问题是:CurlyBracketsForMultiLineStatementsMustNotShareLine ,即它强制执行

void bla() 
{ 
  return x; 
} 

代替

void bla() { 
  return x; 
} 

但是,团队真的愿意坚持第二种风格。

我现在问自己的问题是:

  • 我能否让 Stylecop 验证其他规则,而不是 just disabling规则?
  • 偏离 StyleCop 的建议是搬起石头砸自己的脚吗?

请您参考如下方法:

感谢Patrick :

题中所指的样式多为K&R indentation style还有一个 StyleCop issue 6693用消息关闭:

Closed Aug 17, 2010 at 11:17 PM by jasonall

StyleCop does not comply with the K&R style. It would be difficult to tweak the rules to partially support this style. A better option would be for a third-party dev to create an alternate K&R ruleset.

所以根本不支持。