I'm working on a Swift project involving Qdeql code. Since /
is the "end loop" character and *
means "print", it's not unreasonable for /*
to be a sequence of characters that appears. This means that I have to be careful including code samples in block comments, because it'll recognize the code as a nested comment and complain about the comment not being adequately closed. (Accidentally ending a comment early, with */
, is much less of a concern based on my experience so far.) Is it possible to disable nested block comments for a project or file?
You can't disable arbitrary parts of the language grammar, without compiling a custom fork of the Swift compiler.
I wonder if there's any way to escape these. Are they still treated as comment-start blocks if they're in a markdown code block? I doubt it, but worth a shot
Nope, this still complains about an unclosed block comment:
/*
```
/*
```
*/
Wrapping examples in triple ticks using the modern comment docs syntax seems to work fine:
/// Some sample code
///
/// ```
/// /**/\-\/\// \==\/\/\/-=/ \=\/\/-=\/\/\// \/\/
/// ```
///
func doThing() {}
The main reason I want to use block comments is so that I don't have to type comment characters at the start of each line. I'm on Linux (technically WSL) for this project, and unlike Xcode, the VS Code plugin does not automatically add ///
after you hit enter.
Could this be done by a custom swift lint rule?
I don't understand how a linter/formatter could help. My problem is that a block of code like this isn't valid because Swift thinks the comment was never closed:
/**
```
-\=/*
```
*/
func foo() { ... }
Instead, I have to do this:
/**
```
-\=/*
```
*/ */
func foo() { ... }
I see. Is there an equivalent of Xcode's "command + /" to mark the selection commented/uncommented out with "//" ?
Alternatively maybe you could enclose that block in """ brackets to make it a multiline string?
Actually, I already tried making it a string. That doesn't work. Which is funny, because that defeats the whole purpose of making block comments nestable (commenting out large blocks of code without worrying about their contents).