From 378994b85834497a18ff9bad86dc0a33297c1f05 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Tue, 27 Nov 2018 14:04:48 +1300 Subject: [PATCH] Add a version option --- Cargo.toml | 2 +- Configurations.md | 16 ++++++++++++ Contributing.md | 25 ++++++++++--------- README.md | 2 +- src/config/mod.rs | 1 + src/config/options.rs | 7 ++++++ .../configs/combine_control_expr/false.rs | 2 +- .../configs/combine_control_expr/true.rs | 2 +- 8 files changed, 41 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2a6b07d3c214..b15fb999fcd2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ name = "rustfmt-nightly" version = "1.0.0" authors = ["Nicholas Cameron ", "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" diff --git a/Configurations.md b/Configurations.md index 4d41fe52e3d3..9b59b19acc5f 100644 --- a/Configurations.md +++ b/Configurations.md @@ -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. diff --git a/Contributing.md b/Contributing.md index bbd736ec98f5..23b3de3e8fa0 100644 --- a/Contributing.md +++ b/Contributing.md @@ -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 @@ -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 @@ -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. @@ -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. diff --git a/README.md b/README.md index 0af1a94080d9..17d5a5bd3e6f 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/config/mod.rs b/src/config/mod.rs index 84d94fada776..1aec0d5bfcd5 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -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"; diff --git a/src/config/options.rs b/src/config/options.rs index 3de24ee99bcc..ed3e87a27fd7 100644 --- a/src/config/options.rs +++ b/src/config/options.rs @@ -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 { diff --git a/tests/target/configs/combine_control_expr/false.rs b/tests/target/configs/combine_control_expr/false.rs index 81eff08660d1..b44d8e1b7758 100644 --- a/tests/target/configs/combine_control_expr/false.rs +++ b/tests/target/configs/combine_control_expr/false.rs @@ -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 diff --git a/tests/target/configs/combine_control_expr/true.rs b/tests/target/configs/combine_control_expr/true.rs index c5372c2ff376..ea7c61ef3969 100644 --- a/tests/target/configs/combine_control_expr/true.rs +++ b/tests/target/configs/combine_control_expr/true.rs @@ -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