refactor(lints): Create emitted_source helper function

This commit is contained in:
Scott Schafer 2025-08-18 21:37:44 -06:00
parent 01a270f402
commit 5ac9eb0a58
No known key found for this signature in database

View File

@ -307,6 +307,10 @@ impl Lint {
.map(|(_, (l, r, _))| (l, r)) .map(|(_, (l, r, _))| (l, r))
.unwrap() .unwrap()
} }
fn emitted_source(&self, lint_level: LintLevel, reason: LintLevelReason) -> String {
format!("`cargo::{}` is set to `{lint_level}` {reason}", self.name,)
}
} }
#[derive(Copy, Clone, Debug, PartialEq)] #[derive(Copy, Clone, Debug, PartialEq)]
@ -449,10 +453,7 @@ pub fn check_im_a_teapot(
} }
let level = lint_level.to_diagnostic_level(); let level = lint_level.to_diagnostic_level();
let manifest_path = rel_cwd_manifest_path(path, gctx); let manifest_path = rel_cwd_manifest_path(path, gctx);
let emitted_reason = format!( let emitted_reason = IM_A_TEAPOT.emitted_source(lint_level, reason);
"`cargo::{}` is set to `{lint_level}` {reason}",
IM_A_TEAPOT.name
);
let key_span = get_span(manifest.document(), &["package", "im-a-teapot"], false).unwrap(); let key_span = get_span(manifest.document(), &["package", "im-a-teapot"], false).unwrap();
let value_span = get_span(manifest.document(), &["package", "im-a-teapot"], true).unwrap(); let value_span = get_span(manifest.document(), &["package", "im-a-teapot"], true).unwrap();
@ -581,10 +582,7 @@ fn output_unknown_lints(
}; };
if emitted_source.is_none() { if emitted_source.is_none() {
emitted_source = Some(format!( emitted_source = Some(UNKNOWN_LINTS.emitted_source(lint_level, reason));
"`cargo::{}` is set to `{lint_level}` {reason}",
UNKNOWN_LINTS.name
));
message = message.footer(Level::Note.title(emitted_source.as_ref().unwrap())); message = message.footer(Level::Note.title(emitted_source.as_ref().unwrap()));
} }