【问题标题】:Implement Coding Guidelines using Resharper使用 Resharper 实施编码指南
【发布时间】:2017-05-23 12:13:18
【问题描述】:

在我的项目中,我们需要为 Web Api 遵循一些编码标准。 有什么方法可以在 Resharper 中配置这些指令?我正在使用 Resharper Ultimate 版本。我们也可以这样配置 resharper,如果不遵循这些指令,它会抛出错误并显示建议。

该指南包含以下常见说明:

Use Camel case in Payload
    Use camel case for the data elements in the payload.    Eg:firstName,lastName                                                                                                                                                 
Use lowercase in Endpoints
    Use only lower case when defining the endpoints.                
    Eg:  GET \api\v1\customers\{CustomerID}\rewards                                                                

Use hyphen for compound words in Endpoints
    Use hyphen for compound words in Endpoints.                 
    Eg: GET \api\v1\customers\{CustomerId}\order-history    

Use Nouns not verbs 
    Noun based endpoint should be used rather than verb based endpoint for CRUD operations.                                              
    Eg:     GET \api\v1\\customers, GET \api\v1\customers\{CustomerID}                                                        
            GET \api\v1\GetAllCustomers

Use verb followed by noun in case of certain functions.                                    
    Eg: PUT \api\v1\customers\{CustomerID}\send-email

【问题讨论】:

  • 感谢大家的快速回复。但我需要更多的定制。例如如果有人将端点定义为大写字母 [Route("Seller/Search/{Page}/{PageSize}")] 那么它应该抛出错误并建议使用 [Route("seller/search/{page}/{ pageSize}")]

标签: c# resharper configure


【解决方案1】:

如果您在 Visual-Studio 中从 Resharper 中打开“选项”菜单,则可以配置此类内容。如果您滚动到选项列表的底部,您可以为每种支持的语言找到不同的节点。例如,您可以在那里配置大写、小写或大括号布局。屏幕截图显示了 C# 的一些约定。

我不知道为此启用错误通知的方法。但是有一个快捷方式将您配置的样式用于整个文件(在我的情况下为 Strg+E+F)。因此,如果有人没有使用您的约定并且您打开了他的课程,您只需按下组合并且文档被样式化。也许这也可以通过 Jenkins 或 sth 集成到 Build-Processes 中。但我还没试过。

如果您转到 Resharper->Manage Options,您可以将新设置导出到文件。您的同事可以像导出设置一样导入此设置。

【讨论】:

    【解决方案2】:

    我相信您正在寻找 StyleCop 及其 Resharper 插件。 StyleCop“分析 C# 源代码以强制执行一组样式和一致性规则”,包括您可以自己编写的规则。

    https://github.com/StyleCop

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-23
    • 2022-11-18
    • 2015-01-10
    • 2021-01-26
    • 1970-01-01
    • 2015-08-10
    相关资源
    最近更新 更多