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.
This commit is contained in:
Josh Triplett 2023-06-22 12:41:30 -07:00
parent 3747d7f593
commit 92805672c3
2 changed files with 21 additions and 7 deletions

View File

@ -49,6 +49,27 @@ a_function_call(foo,
This makes for smaller diffs (e.g., if `a_function_call` is renamed in the above
example) and less rightward drift.
### Trailing commas
Lists should have a trailing comma when followed by a newline:
```rust
function_call(
argument,
another_argument,
);
let array = [
element,
another_element,
yet_another_element,
];
```
This makes moving code (e.g., by copy and paste) easier, and makes diffs
smaller, as appending or removing items does not require modifying another line
to add or remove a comma.
### Blank lines
Separate items and statements by either zero or one blank lines (i.e., one or

View File

@ -27,10 +27,3 @@ following principles (in rough priority order):
- ease of implementation (in Rustfmt, and in other tools/editors/code generators)
- internal consistency
- simplicity of formatting rules
## Overarching guidelines
Lists should have a trailing comma when followed by a newline, see the block
indent example above. This choice makes moving code (e.g., by copy and paste)
easier and makes smaller diffs.