Line-continuation backslash at the end of a // comment
ID |
objectivec.correctness.line_splicing_in_comment |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Preprocessor |
Language |
Objective-C |
Description
Reports a // comment whose last character is a backslash, so the line splices into the next one and the following line is swallowed by the comment. A backslash elsewhere in the comment, a backslash ending a line of code, and a backslash inside a /* */ block comment are not reported.
Rationale
Line splicing happens before comments are recognised, so the comment does not end at the newline: the next line becomes part of it and never compiles. The deleted line is usually a statement that looks perfectly present in the editor, and nothing warns, so the loss shows up as behaviour that is simply missing rather than as an error.
The following code illustrates the pattern detected by this rule:
@implementation Splice
- (void)configure {
// FLAGGED: Line-continuation backslash at the end of a // comment
// disable the retry path for now \
[self reload];
}
/*
* a block comment ending a line with \
* is not spliced, because the comment does not end at the newline
*/
@end
Remediation
Remove the trailing backslash, or move it away from the end of the line. If the comment really does need to run over several lines, start each line with its own //, or use a /* */ block comment.