Skip to content

Commit 28653c7

Browse files
committed
Strip lint: prefix from mdtest diagnostics
1 parent 1d91dae commit 28653c7

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

crates/red_knot_test/src/matcher.rs

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::assertion::{Assertion, ErrorAssertion, InlineFileAssertions};
44
use crate::db::Db;
55
use crate::diagnostic::SortedDiagnostics;
66
use colored::Colorize;
7-
use ruff_db::diagnostic::{Diagnostic, DiagnosticId};
7+
use ruff_db::diagnostic::{Diagnostic, DiagnosticAsStrError, DiagnosticId};
88
use ruff_db::files::File;
99
use ruff_db::source::{line_index, source_text, SourceText};
1010
use ruff_source_file::{LineIndex, OneIndexed};
@@ -161,9 +161,14 @@ where
161161
T: Diagnostic,
162162
{
163163
fn unmatched(&self) -> String {
164+
let id = self.id();
165+
let id = id.as_str().unwrap_or_else(|error| match error {
166+
DiagnosticAsStrError::Category { name, .. } => name,
167+
});
168+
164169
maybe_add_undefined_reveal_clarification(
165170
self,
166-
format_args!(r#"[{}] "{}""#, self.id(), self.message()),
171+
format_args!(r#"[{id}] "{message}""#, message = self.message()),
167172
)
168173
}
169174
}
@@ -173,9 +178,14 @@ where
173178
T: Diagnostic,
174179
{
175180
fn unmatched_with_column(&self, column: OneIndexed) -> String {
181+
let id = self.id();
182+
let id = id.as_str().unwrap_or_else(|error| match error {
183+
DiagnosticAsStrError::Category { name, .. } => name,
184+
});
185+
176186
maybe_add_undefined_reveal_clarification(
177187
self,
178-
format_args!(r#"{column} [{}] "{}""#, self.id(), self.message()),
188+
format_args!(r#"{column} [{id}] "{message}""#, message = self.message()),
179189
)
180190
}
181191
}
@@ -464,7 +474,7 @@ mod tests {
464474
0,
465475
&[
466476
"unmatched assertion: revealed: Foo",
467-
r#"unexpected error: 1 [lint:not-revealed-type] "Revealed type is `Foo`""#,
477+
r#"unexpected error: 1 [not-revealed-type] "Revealed type is `Foo`""#,
468478
],
469479
)],
470480
);
@@ -581,7 +591,7 @@ mod tests {
581591
0,
582592
&[
583593
"used built-in `reveal_type`: add a `# revealed` assertion on this line (\
584-
original diagnostic: [lint:undefined-reveal] \"undefined reveal message\")",
594+
original diagnostic: [undefined-reveal] \"undefined reveal message\")",
585595
r#"unexpected error: [revealed-type] "Revealed type is `Literal[1]`""#,
586596
],
587597
)],
@@ -613,7 +623,7 @@ mod tests {
613623
&[
614624
"unmatched assertion: error: [something-else]",
615625
"used built-in `reveal_type`: add a `# revealed` assertion on this line (\
616-
original diagnostic: 1 [lint:undefined-reveal] \"undefined reveal message\")",
626+
original diagnostic: 1 [undefined-reveal] \"undefined reveal message\")",
617627
r#"unexpected error: 13 [revealed-type] "Revealed type is `Literal[1]`""#,
618628
],
619629
)],
@@ -658,7 +668,7 @@ mod tests {
658668
0,
659669
&[
660670
"unmatched assertion: error: [some-rule]",
661-
r#"unexpected error: 1 [lint:anything] "Any message""#,
671+
r#"unexpected error: 1 [anything] "Any message""#,
662672
],
663673
)],
664674
);
@@ -695,7 +705,7 @@ mod tests {
695705
0,
696706
&[
697707
r#"unmatched assertion: error: "contains this""#,
698-
r#"unexpected error: 1 [lint:anything] "Any message""#,
708+
r#"unexpected error: 1 [anything] "Any message""#,
699709
],
700710
)],
701711
);
@@ -732,7 +742,7 @@ mod tests {
732742
0,
733743
&[
734744
"unmatched assertion: error: 2 [rule]",
735-
r#"unexpected error: 1 [lint:rule] "Any message""#,
745+
r#"unexpected error: 1 [rule] "Any message""#,
736746
],
737747
)],
738748
);
@@ -797,7 +807,7 @@ mod tests {
797807
0,
798808
&[
799809
r#"unmatched assertion: error: 2 [some-rule] "contains this""#,
800-
r#"unexpected error: 1 [lint:some-rule] "message contains this""#,
810+
r#"unexpected error: 1 [some-rule] "message contains this""#,
801811
],
802812
)],
803813
);
@@ -820,7 +830,7 @@ mod tests {
820830
0,
821831
&[
822832
r#"unmatched assertion: error: 1 [some-rule] "contains this""#,
823-
r#"unexpected error: 1 [lint:other-rule] "message contains this""#,
833+
r#"unexpected error: 1 [other-rule] "message contains this""#,
824834
],
825835
)],
826836
);
@@ -843,7 +853,7 @@ mod tests {
843853
0,
844854
&[
845855
r#"unmatched assertion: error: 1 [some-rule] "contains this""#,
846-
r#"unexpected error: 1 [lint:some-rule] "Any message""#,
856+
r#"unexpected error: 1 [some-rule] "Any message""#,
847857
],
848858
)],
849859
);
@@ -877,9 +887,9 @@ mod tests {
877887
result,
878888
&[
879889
(1, &["unmatched assertion: error: [line-one]"]),
880-
(2, &[r#"unexpected error: [lint:line-two] "msg""#]),
890+
(2, &[r#"unexpected error: [line-two] "msg""#]),
881891
(4, &["unmatched assertion: error: [line-four]"]),
882-
(5, &[r#"unexpected error: [lint:line-five] "msg""#]),
892+
(5, &[r#"unexpected error: [line-five] "msg""#]),
883893
(6, &["unmatched assertion: error: [line-six]"]),
884894
],
885895
);
@@ -903,10 +913,7 @@ mod tests {
903913
],
904914
);
905915

906-
assert_fail(
907-
result,
908-
&[(2, &[r#"unexpected error: [lint:line-two] "msg""#])],
909-
);
916+
assert_fail(result, &[(2, &[r#"unexpected error: [line-two] "msg""#])]);
910917
}
911918

912919
#[test]
@@ -972,7 +979,7 @@ mod tests {
972979

973980
assert_fail(
974981
result,
975-
&[(3, &[r#"unexpected error: 1 [lint:third-rule] "msg""#])],
982+
&[(3, &[r#"unexpected error: 1 [third-rule] "msg""#])],
976983
);
977984
}
978985

@@ -1021,7 +1028,7 @@ mod tests {
10211028
0,
10221029
&[
10231030
"invalid assertion: no rule or message text",
1024-
r#"unexpected error: 1 [lint:some-rule] "some message""#,
1031+
r#"unexpected error: 1 [some-rule] "some message""#,
10251032
],
10261033
)],
10271034
);
@@ -1046,7 +1053,7 @@ mod tests {
10461053
0,
10471054
&[
10481055
"invalid assertion: no rule or message text",
1049-
r#"unexpected error: 1 [lint:some-rule] "some message""#,
1056+
r#"unexpected error: 1 [some-rule] "some message""#,
10501057
],
10511058
)],
10521059
);

0 commit comments

Comments
 (0)