From de950c2973e20be37159952ded06a8d8aeff261d Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Mon, 14 May 2018 16:11:55 +1200 Subject: [PATCH] Skip on `rustfmt::skip` as well as `rustfmt_skip` --- README.md | 2 +- rustfmt.toml | 2 ++ src/utils.rs | 9 ++++++--- tests/target/skip.rs | 10 +++++----- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6dc437fd27f..b5a4bc7bbc5 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,7 @@ See [Configurations.md](Configurations.md) for details. * For things you do not want rustfmt to mangle, use one of ```rust - #[rustfmt_skip] // requires nightly and #![feature(custom_attribute)] in crate root + #[rustfmt::skip] // requires nightly Rust and #![feature(tool_attributes)] in crate root #[cfg_attr(rustfmt, rustfmt_skip)] // works in stable ``` * When you run rustfmt, place a file named `rustfmt.toml` or `.rustfmt.toml` in diff --git a/rustfmt.toml b/rustfmt.toml index e69de29bb2d..9b935b0a287 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -0,0 +1,2 @@ +error_on_line_overflow = true +error_on_unformatted = true diff --git a/src/utils.rs b/src/utils.rs index ca8a7ad7814..2556fa2c97f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -22,8 +22,8 @@ use config::Color; use rewrite::RewriteContext; use shape::Shape; -// When we get scoped annotations, we should have rustfmt::skip. -const SKIP_ANNOTATION: &str = "rustfmt_skip"; +const DEPR_SKIP_ANNOTATION: &str = "rustfmt_skip"; +const SKIP_ANNOTATION: &str = "rustfmt::skip"; // Computes the length of a string's last line, minus offset. pub fn extra_offset(text: &str, shape: Shape) -> usize { @@ -212,7 +212,10 @@ pub fn last_line_extendable(s: &str) -> bool { #[inline] fn is_skip(meta_item: &MetaItem) -> bool { match meta_item.node { - MetaItemKind::Word => meta_item.name() == SKIP_ANNOTATION, + MetaItemKind::Word => { + let path_str = meta_item.ident.to_string(); + path_str == SKIP_ANNOTATION || path_str == DEPR_SKIP_ANNOTATION + } MetaItemKind::List(ref l) => { meta_item.name() == "cfg_attr" && l.len() == 2 && is_skip_nested(&l[1]) } diff --git a/tests/target/skip.rs b/tests/target/skip.rs index 11d1d69e91a..ee2094151cf 100644 --- a/tests/target/skip.rs +++ b/tests/target/skip.rs @@ -1,10 +1,10 @@ // Test the skip attribute works -#[rustfmt_skip] +#[rustfmt::skip] fn foo() { badly; formatted; stuff ; } -#[rustfmt_skip] +#[rustfmt::skip] trait Foo { fn foo( @@ -32,7 +32,7 @@ fn issue1346() { fn skip_on_statements() { // Outside block - #[rustfmt_skip] + #[rustfmt::skip] { foo; bar; // junk @@ -40,7 +40,7 @@ fn skip_on_statements() { { // Inside block - #![rustfmt_skip] + #![rustfmt::skip] foo; bar; // junk } @@ -79,7 +79,7 @@ fn skip_on_statements() { } // Check that the skip attribute applies to other attributes. -#[rustfmt_skip] +#[rustfmt::skip] #[cfg ( a , b )]