Skip to content

Commit

Permalink
style-guide: Move and expand text about trailing commas
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
joshtriplett committed Jun 22, 2023
1 parent 3747d7f commit 9280567
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
21 changes: 21 additions & 0 deletions src/doc/style-guide/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions src/doc/style-guide/src/principles.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 9280567

Please sign in to comment.