Skip to content

Commit 7efe928

Browse files
committed
Review feedback
1 parent 1f36e8b commit 7efe928

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

crates/ty_python_semantic/src/suppression.rs

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1+
use smallvec::{SmallVec, smallvec};
2+
use std::error::Error;
3+
use std::fmt;
4+
use std::fmt::Formatter;
5+
use std::fmt::Write as _;
6+
use thiserror::Error;
7+
18
use crate::diagnostic::DiagnosticGuard;
29
use crate::lint::{GetLintError, Level, LintMetadata, LintRegistry, LintStatus};
310
use crate::types::TypeCheckDiagnostics;
411
use crate::{Db, declare_lint, lint::LintId};
12+
513
use ruff_db::diagnostic::{
6-
Annotation, Diagnostic, DiagnosticId, IntoDiagnosticMessage, Severity, Span, SubDiagnostic,
7-
SubDiagnosticSeverity,
14+
Annotation, Diagnostic, DiagnosticId, IntoDiagnosticMessage, Severity, Span,
815
};
916
use ruff_db::{files::File, parsed::parsed_module, source::source_text};
1017
use ruff_diagnostics::{Edit, Fix};
1118
use ruff_python_parser::TokenKind;
1219
use ruff_python_trivia::Cursor;
1320
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};
14-
use smallvec::{SmallVec, smallvec};
15-
use std::error::Error;
16-
use std::fmt;
17-
use std::fmt::Formatter;
18-
use thiserror::Error;
1921

2022
declare_lint! {
2123
/// ## What it does
@@ -186,8 +188,6 @@ fn check_invalid_suppression(context: &mut CheckSuppressionsContext) {
186188
///
187189
/// Does nothing if the [`UNUSED_IGNORE_COMMENT`] rule is disabled.
188190
fn check_unused_suppressions(context: &mut CheckSuppressionsContext) {
189-
use std::fmt::Write as _;
190-
191191
if context.is_lint_disabled(&UNUSED_IGNORE_COMMENT) {
192192
return;
193193
}
@@ -333,15 +333,9 @@ fn check_unused_suppressions(context: &mut CheckSuppressionsContext) {
333333
diag.set_fix(Fix::safe_edit(Edit::range_deletion(fix_range)));
334334

335335
if unused_codes.is_empty() {
336-
diag.sub(SubDiagnostic::new(
337-
SubDiagnosticSeverity::Help,
338-
"Remove the unused suppression code",
339-
));
336+
diag.help("Remove the unused suppression code");
340337
} else {
341-
diag.sub(SubDiagnostic::new(
342-
SubDiagnosticSeverity::Help,
343-
"Remove the unused suppression codes",
344-
));
338+
diag.help("Remove the unused suppression codes");
345339
}
346340
}
347341

@@ -377,10 +371,7 @@ fn check_unused_suppressions(context: &mut CheckSuppressionsContext) {
377371
.unwrap()
378372
.push_tag(ruff_db::diagnostic::DiagnosticTag::Unnecessary);
379373
diag.set_fix(remove_comment_fix(suppression, &source));
380-
diag.sub(SubDiagnostic::new(
381-
SubDiagnosticSeverity::Help,
382-
"Remove the unused suppression comment",
383-
));
374+
diag.help("Remove the unused suppression comment");
384375
}
385376
}
386377

@@ -1087,10 +1078,7 @@ fn remove_comment_fix(suppression: &Suppression, source: &str) -> Fix {
10871078
if !after_comment.starts_with(['\n', '\r']) {
10881079
// For example: `# ty: ignore # fmt: off`
10891080
// Don't remove the trailing whitespace up to the `ty: ignore` comment
1090-
return Fix::safe_edit(Edit::range_deletion(TextRange::new(
1091-
comment_start,
1092-
suppression.comment_range.end(),
1093-
)));
1081+
return Fix::safe_edit(Edit::range_deletion(suppression.comment_range));
10941082
}
10951083

10961084
// Remove any leading whitespace before the comment
@@ -1109,7 +1097,7 @@ fn remove_comment_fix(suppression: &Suppression, source: &str) -> Fix {
11091097

11101098
Fix::safe_edit(Edit::range_deletion(TextRange::new(
11111099
comment_start - leading_len,
1112-
suppression.comment_range.end(),
1100+
comment_end,
11131101
)))
11141102
}
11151103

0 commit comments

Comments
 (0)