diff options
author | Akshay <[email protected]> | 2021-10-03 12:28:19 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2021-10-03 12:28:38 +0100 |
commit | 75c3d4be13a5d5f525ee1ff8bc68e3c1ce0f7509 (patch) | |
tree | cf201840fb3f5fbe2adf4efdba046e198b8563ea | |
parent | fc6409142e68335addc65763a1733526130256b0 (diff) |
don't report fix on stderr
-rw-r--r-- | bin/src/main.rs | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/bin/src/main.rs b/bin/src/main.rs index 71cbb02..ab99aee 100644 --- a/bin/src/main.rs +++ b/bin/src/main.rs | |||
@@ -5,8 +5,8 @@ use std::{ | |||
5 | 5 | ||
6 | use anyhow::{Context, Result}; | 6 | use anyhow::{Context, Result}; |
7 | use ariadne::{ | 7 | use ariadne::{ |
8 | CharSet, Color, Config as CliConfig, Label, Report as CliReport, | 8 | CharSet, Color, Config as CliConfig, Label, LabelAttach, Report as CliReport, |
9 | ReportKind as CliReportKind, Source, LabelAttach | 9 | ReportKind as CliReportKind, Source, |
10 | }; | 10 | }; |
11 | use lib::{Report, LINTS}; | 11 | use lib::{Report, LINTS}; |
12 | use rnix::{TextRange, WalkEvent}; | 12 | use rnix::{TextRange, WalkEvent}; |
@@ -44,31 +44,21 @@ fn print_report(report: Report, file_src: &str, file_path: &Path) -> Result<()> | |||
44 | .iter() | 44 | .iter() |
45 | .fold( | 45 | .fold( |
46 | CliReport::build(CliReportKind::Warning, src_id, offset) | 46 | CliReport::build(CliReportKind::Warning, src_id, offset) |
47 | .with_config( | 47 | .with_config( |
48 | CliConfig::default() | 48 | CliConfig::default() |
49 | .with_cross_gap(true) | 49 | .with_cross_gap(true) |
50 | .with_multiline_arrows(false) | 50 | .with_multiline_arrows(false) |
51 | .with_label_attach(LabelAttach::Middle) | 51 | .with_label_attach(LabelAttach::Middle) |
52 | .with_char_set(CharSet::Unicode), | 52 | .with_char_set(CharSet::Unicode), |
53 | ) | 53 | ) |
54 | .with_message(report.note) | 54 | .with_message(report.note) |
55 | .with_code(report.code), | 55 | .with_code(report.code), |
56 | |cli_report, diagnostic| { | 56 | |cli_report, diagnostic| { |
57 | let cli_report = cli_report.with_label( | 57 | cli_report.with_label( |
58 | Label::new((src_id, range(diagnostic.at))) | 58 | Label::new((src_id, range(diagnostic.at))) |
59 | .with_message(&diagnostic.message) | 59 | .with_message(&diagnostic.message) |
60 | .with_color(Color::Magenta), | 60 | .with_color(Color::Magenta), |
61 | ); | 61 | ) |
62 | if let Some(s) = &diagnostic.suggestion { | ||
63 | let replacement_msg = format!("Try: `{}`", s.fix); | ||
64 | cli_report.with_label( | ||
65 | Label::new((src_id, range(s.at))) | ||
66 | .with_message(replacement_msg) | ||
67 | .with_color(Color::Yellow), | ||
68 | ) | ||
69 | } else { | ||
70 | cli_report | ||
71 | } | ||
72 | }, | 62 | }, |
73 | ) | 63 | ) |
74 | .finish() | 64 | .finish() |
@@ -96,6 +86,7 @@ fn _main() -> Result<()> { | |||
96 | } | 86 | } |
97 | Ok(()) | 87 | Ok(()) |
98 | } | 88 | } |
89 | |||
99 | fn main() { | 90 | fn main() { |
100 | match _main() { | 91 | match _main() { |
101 | Err(e) => eprintln!("{}", e), | 92 | Err(e) => eprintln!("{}", e), |