Skip to content

Commit

Permalink
fix: handle skip_macro_invocations from config file
Browse files Browse the repository at this point in the history
  • Loading branch information
calebcartwright committed Jul 5, 2023
1 parent d9a0992 commit 11fac26
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/config/macro_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use itertools::Itertools;
use std::{fmt, str};

use serde::{Deserialize, Serialize};
use serde::{Deserialize, Deserializer, Serialize};
use serde_json as json;
use thiserror::Error;

Expand All @@ -30,12 +30,22 @@ impl From<MacroName> for String {
}

/// Defines a selector to match against a macro.
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd, Deserialize, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd, Serialize)]
pub enum MacroSelector {
Name(MacroName),
All,
}

impl<'de> Deserialize<'de> for MacroSelector {
fn deserialize<D>(de: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let s = String::deserialize(de)?;
std::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
}
}

impl fmt::Display for MacroSelector {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down
1 change: 1 addition & 0 deletions tests/config/issue-5816.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
skip_macro_invocations=["*", "println"]
9 changes: 9 additions & 0 deletions tests/source/skip_macro_invocations/config_file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// rustfmt-unstable: true
// rustfmt-config: issue-5816.toml

fn main() {
println!( "Hello, world!");
let x =
7
;
}
7 changes: 7 additions & 0 deletions tests/target/skip_macro_invocations/config_file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// rustfmt-unstable: true
// rustfmt-config: issue-5816.toml

fn main() {
println!( "Hello, world!");
let x = 7;
}

0 comments on commit 11fac26

Please sign in to comment.