How to get Visual Studio quick comments to add a space after the double slash to avoid SA1005?

空扰寡人 提交于 2019-12-08 15:53:58

问题


In Visual Studio, I have a block of code. I highlight it and use Ctrl+k+c to comment out the block. That adds "//" at the start of every line I highlighted. I then try to submit my code... and I run into StyleCop rule "SA1005" that requires all // to be followed by a space or be changed to ////. I would really like to modify Visual Studio so that ctrl+k+c adds "// ". I have not found any extensions or options that make that happen. Does anyone know of a way to do that change (short of writing my own new VS extension)?


回答1:


Co-worker tells me that you can also just hit Ctrl+K+C Ctrl+K+C (that is, apply commenting twice), and it will do ////code. That will pass style cop. Do the uncomment shortcut key twice to undo. Apparently, StyleCop doesn't care if there's a space after four slashes, only after two slashes.

Seems some people really like this rule behavior. People will comment out code with a single set of // if they are playing around with stuff but do not want to forget and check it in that way. SA will fail and the code will not go in. Once you really mean to comment out of the code and check it in then you comment it out again and you are good to go. This, they claim, has saved many from a bad check-in.




回答2:


You don't need to write your own VS extension, there is already plugin GhostDoc that we are offering - you are welcome to use the free version - and it will generate StyleCop compliant XML Comment templates (which you can tweak too). GhostDoc also generate the comments on triple-slash (///) just like the VS does.



来源:https://stackoverflow.com/questions/28567114/how-to-get-visual-studio-quick-comments-to-add-a-space-after-the-double-slash-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!