Skip to content

Commit

Permalink
Add a version option
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Nov 27, 2018
1 parent 4609252 commit 378994b
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name = "rustfmt-nightly"
version = "1.0.0"
authors = ["Nicholas Cameron <[email protected]>", "The Rustfmt developers"]
description = "Tool to find and fix Rust formatting issues"
repository = "https://github.com/rust-lang-nursery/rustfmt"
repository = "https://github.com/rust-lang/rustfmt"
readme = "README.md"
license = "Apache-2.0/MIT"
build = "build.rs"
Expand Down
16 changes: 16 additions & 0 deletions Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2367,6 +2367,22 @@ If you want to format code that requires edition 2018, add the following to your
edition = "2018"
```

## `version`

Which version of the formatting rules to use. `Version::One` is backwards-compatible
with Rustfmt 1.0. Other versions are only backwards compatible within a major
version number.

- **Default value**: `One`
- **Possible values**: `One`, `Two`
- **Stable**: No

### Example

```toml
version = "Two"
```

## `normalize_doc_attributes`

Convert `#![doc]` and `#[doc]` attributes to `//!` and `///` doc comments.
Expand Down
25 changes: 13 additions & 12 deletions Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

There are many ways to contribute to Rustfmt. This document lays out what they
are and has information for how to get started. If you have any questions about
contributing or need help with anything, please ping nrc on irc, #rust-dev-tools
on irc.mozilla.org is probably the best channel. Feel free to also ask questions
contributing or need help with anything, please ask in the WG-Rustfmt channel
on [Discord](https://discordapp.com/invite/rust-lang). Feel free to also ask questions
on issues, or file new issues specifically to get help.

All contributors are expected to follow our [Code of
Expand All @@ -14,14 +14,6 @@ Conduct](CODE_OF_CONDUCT.md).
It would be really useful to have people use rustfmt on their projects and file
issues where it does something you don't expect.

A really useful thing to do that on a crate from the Rust repo. If it does
something unexpected, file an issue; if not, make a PR to the Rust repo with the
reformatted code. We hope to get the whole repo consistently rustfmt'ed and to
replace `make tidy` with rustfmt as a medium-term goal. Issues with stack traces
for bugs and/or minimal test cases are especially useful.

See this [blog post](http://ncameron.org/blog/rustfmt-ing-rust/) for more details.


## Create test cases

Expand Down Expand Up @@ -66,11 +58,14 @@ example, the `issue-1111.rs` test file is configured by the file

## Debugging

Some `rewrite_*` methods use the `debug!` macro for printing useful information. These messages can be printed by using the environment variable `RUST_LOG=rustfmt=DEBUG`. These traces can be helpful in understanding which part of the code was used and get a better grasp on the execution flow.
Some `rewrite_*` methods use the `debug!` macro for printing useful information.
These messages can be printed by using the environment variable `RUST_LOG=rustfmt=DEBUG`.
These traces can be helpful in understanding which part of the code was used
and get a better grasp on the execution flow.

## Hack!

Here are some [good starting issues](https://github.com/rust-lang-nursery/rustfmt/issues?q=is%3Aopen+is%3Aissue+label%3Agood-first-issue).
Here are some [good starting issues](https://github.com/rust-lang/rustfmt/issues?q=is%3Aopen+is%3Aissue+label%3Agood-first-issue).

If you've found areas which need polish and don't have issues, please submit a
PR, don't feel there needs to be an issue.
Expand All @@ -86,6 +81,12 @@ Talking of tests, if you add a new feature or fix a bug, please also add a test.
It's really easy, see above for details. Please run `cargo test` before
submitting a PR to ensure your patch passes all tests, it's pretty quick.

Rustfmt is post-1.0 and within major version releases we strive for backwards
compatibility (at least when using the default options). That means any code
which changes Rustfmt's output must be guarded by either an option or a version
check. The latter is implemented as an option called `option`. See the section on
[configuration](#Configuration) below.

Please try to avoid leaving `TODO`s in the code. There are a few around, but I
wish there weren't. You can leave `FIXME`s, preferably with an issue number.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# rustfmt [![Build Status](https://travis-ci.org/rust-lang-nursery/rustfmt.svg)](https://travis-ci.org/rust-lang-nursery/rustfmt) [![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-lang-nursery/rustfmt?svg=true)](https://ci.appveyor.com/project/nrc/rustfmt) [![crates.io](https://img.shields.io/crates/v/rustfmt-nightly.svg)](https://crates.io/crates/rustfmt-nightly) [![Travis Configuration Status](https://img.shields.io/travis/davidalber/rustfmt-travis.svg?label=travis%20example)](https://travis-ci.org/davidalber/rustfmt-travis)
# rustfmt [![Build Status](https://travis-ci.org/rust-lang/rustfmt.svg)](https://travis-ci.org/rust-lang/rustfmt) [![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-lang/rustfmt?svg=true)](https://ci.appveyor.com/project/nrc/rustfmt) [![crates.io](https://img.shields.io/crates/v/rustfmt-nightly.svg)](https://crates.io/crates/rustfmt-nightly) [![Travis Configuration Status](https://img.shields.io/travis/davidalber/rustfmt-travis.svg?label=travis%20example)](https://travis-ci.org/davidalber/rustfmt-travis)

A tool for formatting Rust code according to style guidelines.

Expand Down
1 change: 1 addition & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ create_config! {
blank_lines_lower_bound: usize, 0, false,
"Minimum number of blank lines which must be put between items";
edition: Edition, Edition::Edition2015, true, "The edition of the parser (RFC 2052)";
version: Version, Version::One, false, "Version of formatting rules";

// Options that can change the source code beyond whitespace/blocks (somewhat linty things)
merge_derives: bool, true, true, "Merge multiple `#[derive(...)]` into a single one";
Expand Down
7 changes: 7 additions & 0 deletions src/config/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,13 @@ configuration_option_enum! { Color:
Auto,
}

configuration_option_enum! { Version:
// 1.x.y
One,
// 2.x.y
Two,
}

impl Color {
/// Whether we should use a coloured terminal.
pub fn use_colored_tty(self) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion tests/target/configs/combine_control_expr/false.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// rustfmt-indent_style: Block
// rustfmt-combine_control_expr: false
// Combining openings and closings. See https://github.com/rust-lang-nursery/fmt-rfcs/issues/61.
// Combining openings and closings. See https://github.com/rust-lang/fmt-rfcs/issues/61.

fn main() {
// Call
Expand Down
2 changes: 1 addition & 1 deletion tests/target/configs/combine_control_expr/true.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// rustfmt-indent_style: Block
// rustfmt-combine_control_expr: true
// Combining openings and closings. See https://github.com/rust-lang-nursery/fmt-rfcs/issues/61.
// Combining openings and closings. See https://github.com/rust-lang/fmt-rfcs/issues/61.

fn main() {
// Call
Expand Down

0 comments on commit 378994b

Please sign in to comment.