Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarcho committed Oct 6, 2023
1 parent a260a61 commit dd38171
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub struct Config {
pub filter_exact: bool,
/// Prefix added to all diagnostic code matchers. Note this will make it impossible
/// match codes which do not contain this prefix.
pub diagnostic_code_prefix: Option<String>,
pub diagnostic_code_prefix: String,
}

impl Config {
Expand Down Expand Up @@ -106,7 +106,7 @@ impl Config {
list: false,
run_only_ignored: false,
filter_exact: false,
diagnostic_code_prefix: None,
diagnostic_code_prefix: String::new(),
}
}

Expand Down
34 changes: 12 additions & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,6 @@ fn check_test_result(
config,
revision,
comments,
config.diagnostic_code_prefix.as_deref(),
)?;
if errors.is_empty() {
Ok(command)
Expand Down Expand Up @@ -1065,7 +1064,6 @@ fn check_annotations(
config: &Config,
revision: &str,
comments: &Comments,
diagnostic_code_prefix: Option<&str>,
) -> Result<(), Errored> {
let error_patterns = comments
.for_revision(revision)
Expand Down Expand Up @@ -1125,21 +1123,14 @@ fn check_annotations(
}
}
ErrorMatchKind::Code(code) => {
let found = if let Some(prefix) = diagnostic_code_prefix {
msgs.iter().position(|msg| {
msg.level == Level::Error
&& msg
.code
.as_ref()
.and_then(|code| code.strip_prefix(prefix))
.is_some_and(|msg| *msg == **code)
})
} else {
msgs.iter().position(|msg| {
msg.level == Level::Error
&& msg.code.as_ref().is_some_and(|msg| *msg == **code)
})
};
let found = msgs.iter().position(|msg| {
msg.level == Level::Error
&& msg
.code
.as_ref()
.and_then(|code| code.strip_prefix(&config.diagnostic_code_prefix))
.is_some_and(|msg| *msg == **code)
});

if let Some(found) = found {
msgs.remove(found);
Expand All @@ -1155,11 +1146,10 @@ fn check_annotations(
expected_line: Some(line),
},
ErrorMatchKind::Code(code) => Error::CodeNotFound {
code: if let Some(prefix) = diagnostic_code_prefix {
Spanned::new(format!("{prefix}{}", **code), code.span())
} else {
code.clone()
},
code: Spanned::new(
format!("{}{}", config.diagnostic_code_prefix, **code),
code.span(),
),
expected_line: Some(line),
},
});
Expand Down
18 changes: 4 additions & 14 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ fn main() {
&config,
"",
&comments,
None,
)
.unwrap();
match &errors[..] {
Expand Down Expand Up @@ -84,7 +83,6 @@ fn main() {
&config,
"",
&comments,
None,
)
.unwrap();
match &errors[..] {
Expand Down Expand Up @@ -113,7 +111,6 @@ fn main() {
&config,
"",
&comments,
None,
)
.unwrap();
match &errors[..] {
Expand Down Expand Up @@ -146,7 +143,6 @@ fn main() {
&config,
"",
&comments,
None,
)
.unwrap();
match &errors[..] {
Expand Down Expand Up @@ -189,7 +185,6 @@ fn main() {
&config,
"",
&comments,
None,
)
.unwrap();
match &errors[..] {
Expand Down Expand Up @@ -235,7 +230,6 @@ fn main() {
&config,
"",
&comments,
None,
)
.unwrap();
match &errors[..] {
Expand Down Expand Up @@ -293,7 +287,6 @@ fn main() {
&config,
"",
&comments,
None,
)
.unwrap();
match &errors[..] {
Expand Down Expand Up @@ -362,7 +355,6 @@ fn main() {
&config,
"",
&comments,
None,
)
.unwrap();
match &errors[..] {
Expand Down Expand Up @@ -401,7 +393,6 @@ fn main() {
&config,
"",
&comments,
None,
)
.unwrap();
match &errors[..] {
Expand Down Expand Up @@ -432,7 +423,6 @@ fn main() {
&config,
"",
&comments,
None,
)
.unwrap();
match &errors[..] {
Expand Down Expand Up @@ -464,7 +454,6 @@ fn main() {
&config,
"",
&comments,
None,
)
.unwrap();
match &errors[..] {
Expand All @@ -482,7 +471,10 @@ fn main() {
}
";
let comments = Comments::parse(s).unwrap();
let config = config();
let config = Config {
diagnostic_code_prefix: "prefix::".into(),
..config()
};
{
let messages = vec![
vec![],
Expand All @@ -504,7 +496,6 @@ fn main() {
&config,
"",
&comments,
Some("prefix::"),
)
.unwrap();
match &errors[..] {
Expand Down Expand Up @@ -535,7 +526,6 @@ fn main() {
&config,
"",
&comments,
Some("prefix::"),
)
.unwrap();
match &errors[..] {
Expand Down

0 comments on commit dd38171

Please sign in to comment.