Skip to content

Commit 9280567

Browse files
committed
style-guide: Move and expand text about trailing commas
`principles.md` includes some high-level guiding principles for formatting, but also includes a few specific formatting provisions. While those provisions apply in many places, the same holds true for other high-level guidance. Move the text about trailing commas to `README.md`, so that `principles.md` can focus on guiding principles while the top level of the style guide gives concrete formatting recommendations.
1 parent 3747d7f commit 9280567

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/doc/style-guide/src/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@ a_function_call(foo,
4949
This makes for smaller diffs (e.g., if `a_function_call` is renamed in the above
5050
example) and less rightward drift.
5151

52+
### Trailing commas
53+
54+
Lists should have a trailing comma when followed by a newline:
55+
56+
```rust
57+
function_call(
58+
argument,
59+
another_argument,
60+
);
61+
62+
let array = [
63+
element,
64+
another_element,
65+
yet_another_element,
66+
];
67+
```
68+
69+
This makes moving code (e.g., by copy and paste) easier, and makes diffs
70+
smaller, as appending or removing items does not require modifying another line
71+
to add or remove a comma.
72+
5273
### Blank lines
5374

5475
Separate items and statements by either zero or one blank lines (i.e., one or

src/doc/style-guide/src/principles.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,3 @@ following principles (in rough priority order):
2727
- ease of implementation (in Rustfmt, and in other tools/editors/code generators)
2828
- internal consistency
2929
- simplicity of formatting rules
30-
31-
32-
## Overarching guidelines
33-
34-
Lists should have a trailing comma when followed by a newline, see the block
35-
indent example above. This choice makes moving code (e.g., by copy and paste)
36-
easier and makes smaller diffs.

0 commit comments

Comments
 (0)