Skip to content

Commit e0cb62a

Browse files
rchen152meta-codesync[bot]
authored andcommitted
Show hidden warning/info counts in check summary line
Summary: When --min-severity filters out warnings or info messages, the summary line now shows how many were hidden. This would have prevented a confusing situation in which it looked like pyrefly was broken (python/typing#2229) because the latest version shows "INFO 0 errors" on the deprecation conformance tests. Now we'll show "INFO 0 errors (12 warnings not shown)". Reviewed By: grievejia Differential Revision: D98951337 fbshipit-source-id: df8a22ea57e191e6e5850b6e47eef8c7ee7381bb
1 parent 66965e3 commit e0cb62a

2 files changed

Lines changed: 41 additions & 10 deletions

File tree

pyrefly/lib/commands/check.rs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ impl CheckArgs {
10011001
} else {
10021002
(errors.directives, errors.ordinary)
10031003
};
1004-
let mut ordinary_errors: Vec<_> = if let Some(only) = &self.output.only {
1004+
let ordinary_errors: Vec<_> = if let Some(only) = &self.output.only {
10051005
let only = only.iter().collect::<SmallSet<_>>();
10061006
let filtered: Vec<_> = unused_ignore_errors
10071007
.ordinary
@@ -1037,7 +1037,9 @@ impl CheckArgs {
10371037
// Filter by minimum severity. Directives are not subject to this
10381038
// filter — they are merged separately in the output step below.
10391039
let min_severity = self.output.min_severity.unwrap_or(Severity::Error);
1040-
ordinary_errors.retain(|e| e.severity() >= min_severity);
1040+
let (ordinary_errors, hidden_errors): (Vec<_>, Vec<_>) = ordinary_errors
1041+
.into_iter()
1042+
.partition(|e| e.severity() >= min_severity);
10411043

10421044
// We update the baseline file if requested, after reporting any new
10431045
// errors using the old baseline. Directives are structurally excluded
@@ -1103,15 +1105,35 @@ impl CheckArgs {
11031105

11041106
if self.output.summary != Summary::None {
11051107
let suppress_count = errors.suppressed.len();
1106-
if suppress_count == 0 {
1107-
info!("{}", count(ordinary_errors_count, "error"))
1108+
let mut parts = vec![count(ordinary_errors_count, "error")];
1109+
if suppress_count > 0 {
1110+
parts.push(format!("{} suppressed", number_thousands(suppress_count)));
1111+
}
1112+
if !hidden_errors.is_empty() {
1113+
let mut hidden_warnings = 0;
1114+
let mut hidden_info = 0;
1115+
for e in hidden_errors {
1116+
match e.severity() {
1117+
Severity::Error => panic!("Error-level findings can never be hidden"),
1118+
Severity::Warn => hidden_warnings += 1,
1119+
Severity::Info => hidden_info += 1,
1120+
Severity::Ignore => {}
1121+
}
1122+
}
1123+
let mut hidden_parts = Vec::new();
1124+
if hidden_warnings > 0 {
1125+
hidden_parts.push(count(hidden_warnings, "warning"));
1126+
}
1127+
if hidden_info > 0 {
1128+
hidden_parts.push(count(hidden_info, "info message"));
1129+
}
1130+
parts.push(format!("{} not shown", hidden_parts.join(" and ")));
1131+
}
1132+
if parts.len() == 1 {
1133+
info!("{}", parts[0]);
11081134
} else {
1109-
info!(
1110-
"{} ({} suppressed)",
1111-
count(ordinary_errors_count, "error"),
1112-
number_thousands(suppress_count)
1113-
)
1114-
};
1135+
info!("{} ({})", parts[0], parts[1..].join(", "));
1136+
}
11151137
}
11161138
if self.output.summary == Summary::Full {
11171139
let user_handles: HashSet<&Handle> = handles.iter().collect();

test/basic.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,12 @@ $ python3 -m venv $TMPDIR/venv && \
8686
INFO 0 errors* (glob)
8787
[0]
8888
```
89+
90+
## We show how many warnings are hidden
91+
92+
```scrut {output_stream: stderr}
93+
$ echo "x: str = 0" > $TMPDIR/test.py && \
94+
> $PYREFLY check $TMPDIR/test.py --warn=bad-assignment
95+
INFO 0 errors (1 warning not shown)* (glob)
96+
[0]
97+
```

0 commit comments

Comments
 (0)