Skip to content

Commit

Permalink
Skip on rustfmt::skip as well as rustfmt_skip
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed May 14, 2018
1 parent 7eb8bdb commit de950c2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
error_on_line_overflow = true
error_on_unformatted = true
9 changes: 6 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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])
}
Expand Down
10 changes: 5 additions & 5 deletions tests/target/skip.rs
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -32,15 +32,15 @@ fn issue1346() {

fn skip_on_statements() {
// Outside block
#[rustfmt_skip]
#[rustfmt::skip]
{
foo; bar;
// junk
}

{
// Inside block
#![rustfmt_skip]
#![rustfmt::skip]
foo; bar;
// junk
}
Expand Down Expand Up @@ -79,7 +79,7 @@ fn skip_on_statements() {
}

// Check that the skip attribute applies to other attributes.
#[rustfmt_skip]
#[rustfmt::skip]
#[cfg
( a , b
)]
Expand Down

0 comments on commit de950c2

Please sign in to comment.