Search code examples
configurationrider

Jetbrains Rider can you change "Comment with line comment" to use 4 slashes instead of 2?


We are using Jetbrains Rider to do our .Net C# projects. If I have a code block that I'm currently working on and want to try something else, I usually just comment out the lines, using the "Comment with line comment" shortcut.

This changes the marked area, adding double slahes in front of the code lines, like so:

before:
var contact1 = new Contact();
var contact2 = new Contact();

after shortcut was used
// var contact1 = new Contact();
// var contact2 = new Contact();

This however gives me a violation of SA1515 saying: Single-line comment should be preceded by blank line AND Single-line comments should not be followed by blank line (on line 2,3,4 etc)

There is a hack to cirkumvent that rule however, being adding 4 slashes instead of 2 and the validator will ignore the violation. This would give the following outcome of the same shortcut:

//// var contact1 = new Contact();
//// var contact2 = new Contact();

Does anybody know if and where Rider can be modified, so Rider will add 4 slashes instead, when using "Comment with line comment" shortcut?

I tried googling the issue, but I could not find a solution. It seems VSCode can handle this though, but we are not using VSCode at work.


Solution

  • No, it's not possible to use //// instead of //, which makes sense (at least to me 🙂) as the C# language spec explicitly says (see here):

    C# supports two different forms of comments. Single line comments start with // and end at the end of that line of code. Multiline comments start with /* and end with */.

    I'd recommend adjusting your StyleCop rules, either via .DotSettings or .editorconfig.