mirror of
https://github.com/denoland/deno.git
synced 2024-12-28 01:59:06 -05:00
refactor(lint): show hint for lint errors (#8016)
This commit adds formatting of optional "hint" that can be present in lint diagnostic.
This commit is contained in:
parent
b33e8d5d42
commit
8f9da368f7
2 changed files with 21 additions and 6 deletions
25
cli/lint.rs
25
cli/lint.rs
|
@ -222,6 +222,7 @@ impl LintReporter for PrettyLintReporter {
|
|||
&pretty_message,
|
||||
&source_lines,
|
||||
d.range.clone(),
|
||||
d.hint.as_ref(),
|
||||
&fmt_errors::format_location(&JsStackFrame::from_location(
|
||||
Some(d.filename.clone()),
|
||||
Some(d.range.start.line as i64),
|
||||
|
@ -256,6 +257,7 @@ pub fn format_diagnostic(
|
|||
message_line: &str,
|
||||
source_lines: &[&str],
|
||||
range: deno_lint::diagnostic::Range,
|
||||
maybe_hint: Option<&String>,
|
||||
formatted_location: &str,
|
||||
) -> String {
|
||||
let mut lines = vec![];
|
||||
|
@ -284,12 +286,23 @@ pub fn format_diagnostic(
|
|||
}
|
||||
}
|
||||
|
||||
format!(
|
||||
"{}\n{}\n at {}",
|
||||
message_line,
|
||||
lines.join("\n"),
|
||||
formatted_location
|
||||
)
|
||||
if let Some(hint) = maybe_hint {
|
||||
format!(
|
||||
"{}\n{}\n at {}\n\n {} {}",
|
||||
message_line,
|
||||
lines.join("\n"),
|
||||
formatted_location,
|
||||
colors::gray("hint:"),
|
||||
hint,
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"{}\n{}\n at {}",
|
||||
message_line,
|
||||
lines.join("\n"),
|
||||
formatted_location
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
^^^^^^^^^^^^^^^^^^^
|
||||
at [WILDCARD]file1.js:1:0
|
||||
|
||||
hint: [WILDCARD]
|
||||
|
||||
(no-empty) Empty block statement
|
||||
while (false) {}
|
||||
^^
|
||||
|
|
Loading…
Reference in a new issue