Background
Currently there are different spacing conventions in the Clang Static Analyzer (CSA). Some of the user facing error messages and warnings use single space after the end of a sentence, but some of them use double spaces.
There are two type of spacing conventions:
- English spacing: removed spaces around most punctuation marks, but double-spaced after sentences, colons, and semicolons.
- French spacing: inserted spaces around most punctuation marks, but single-spaced after sentences, colons, and semicolons.
(I have learnt about this on Wikipedia: History of sentence spacing - Wikipedia)
Problem
Currently the two spacing conventions are mixed in teh CSA:
Double space in BugReporter.cpp:
C.getActivePath().push_front(
std::make_shared<PathDiagnosticControlFlowPiece>(
Start, End, "Loop condition is false. Exiting loop"));
...
...
...
C.getActivePath().push_front(
std::make_shared<PathDiagnosticControlFlowPiece>(
Start, End, "Loop condition is true. Entering loop body"));
Single space in BugReporter.cpp:
switch (S->getStmtClass()) {
default:
os << "No cases match in the switch statement. "
"Control jumps to line "
Occurence of single vs. double spaces
I have written a simple Python script to measure the occurences of single vs. double spaces in the CSA, Clang frontend, and clang-tidy. These are the numbers:
Clang Static Analyzer:
Overall numbers: single space = 107, double space = 15
From these numbers 81 in single spaces category are in help text rather than emitted
diagnostics: 64 in AnalyzerOptions.def, 15 in Checkers.td, and 2 in Analyses.def.
Emitted bug reports and notes: single space = 26, double space = 15.
Clang frontend:
Overall numbers: single space = 48, double space = 1
Form these 35 are compiler diagnostics and 13 are help text and and tool messages.
The one double space is in a user-facing file: DiagnosticSemaKinds.td:407.
Clang-tidy:
Overall numbers: single space = 33, double space = 0
Out of the 33 there are 3 cases are check diagnostics.
How do other projects work in this space?
GCC has a rule for it in its Coding Conventions, but only for its Texinfo
documentation, not for diagnostics:
Full stops that end sentences should be followed by two spaces or by end of line.
Its diagnostic guidelines do not mention sentence spacing. The only rule for messages I could find is in the contrib/check-internal-format-escaping.py lint script, which says “After a sentence there should be two spaces.” This script has to be run manually on gcc.pot.
However, it does not seem that this rule is applied consistently. I went through gcc.pot and there are mixed cases of using double and single spaces. I have not run my script on GCC, so I do not have exact numbers, but I will extend it and come back with numbers if needed.
Cppcheck does not seem to have any rules on this. The only rule around this manner is:
It's very important that warning messages are well written and with enough details.
This is in theirphilosophy.md file while their CONTRIBUTING.md file does not contain any information.
Proposed change
Since changing all double spaces to single space or the other way around does affect users I think the change should be addressed based on the discussion in this RFC. However, I would suggest that we should add more details on spacing after the discussion in this RFC to “Clang” CFE Internals Manual - Clang
This issue came up in [analyzer] Fix double space in generateMinimalDiagForBlockEdge emitted notes by benedekaibas · Pull Request #228777 · llvm/llvm-project · GitHub. If we can settle on a common agreement I will update the PR based on that. After that I would also open a PR with the agreed changes in this RFC if any.