Proposal: Require whitespace after a comma #8598
Labels
proposal
This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
Very similar to #7399. I propose similar measures in this case.
Here's a code example:
There is a bug in this code. How easy this is to spot will depend on the font and color scheme of your editor. Imagine that you weren't informed there was a bug, and there was a lot more code above and below this.
The answer is there is no
8.45
innums
. The author typo'd a,
instead of a.
.zig-fmt
will add whitespace after commas where needed, however this does not fix the bug, it only makes it more visible.I can't say that I've personally seen this issue before in practice, but considering that
.
and,
are neighbors on the vast majority of keyboard layouts, it doesn't seem unreasonable that something like this would happen.I propose that whitespace be mandatory after a comma. Either a space or a newline. This will cause a compiler error in the above example and catch the bug before it becomes dormant. Likewise,
zig-fmt
should also error when it encounters the above code, as to not introduce the same (but more visible) footgun.Here's some examples to make the new rule clearer:
The text was updated successfully, but these errors were encountered: