Skip on rustfmt::skip as well as rustfmt_skip

This commit is contained in:
Nick Cameron 2018-05-14 16:11:55 +12:00
parent 7eb8bdbbd2
commit de950c2973
4 changed files with 14 additions and 9 deletions

@ -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

@ -0,0 +1,2 @@
error_on_line_overflow = true
error_on_unformatted = true

@ -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])
}

@ -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
)]