Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

feat: `harper-cli lint` shows priorities and lets lint overlap removal be turned off (#2435)

Andrew Dunbarbec5ab3eb341
diff --git a/harper-cli/src/lint.rs b/harper-cli/src/lint.rs
index 556e8d065..c760e4c10 100644
--- a/harper-cli/src/lint.rs
+++ b/harper-cli/src/lint.rs
@@ -52,6 +52,7 @@ pub struct LintOptions {
pub count: bool,
pub ignore: Option<Vec<String>>,
pub only: Option<Vec<String>>,
+ pub keep_overlapping_lints: bool,
pub dialect: Dialect,
}
enum ReportStyle {
@@ -95,6 +96,7 @@ pub fn lint(
ref mut ignore,
ref mut only,
dialect,
+ ..
} = lint_options;
// Zero or more inputs, default to stdin if not provided
@@ -273,6 +275,7 @@ fn lint_one_input(
count: _,
ignore,
only,
+ keep_overlapping_lints,
dialect,
} = lint_options;
@@ -312,7 +315,9 @@ fn lint_one_input(
// Lint counts, for brief reporting
let lint_count_before = named_lints.values().map(|v| v.len()).sum::<usize>();
- remove_overlaps_map(&mut named_lints);
+ if !keep_overlapping_lints {
+ remove_overlaps_map(&mut named_lints);
+ }
let lint_count_after = named_lints.values().map(|v| v.len()).sum::<usize>();
// Extract the lint kinds and rules etc. for reporting
@@ -473,9 +478,14 @@ fn single_input_report(
report_builder = report_builder.with_label(
Label::new((&input_identifier, lint.span.into()))
.with_message(format!(
- "{}: {}",
+ "{} {}: {}",
format_args!("[{}::{}]", lint.lint_kind, rule_name)
.fg(ariadne::Color::Rgb(r, g, b)),
+ format_args!("(pri {})", lint.priority).fg(ariadne::Color::Rgb(
+ (r as f32 * 0.66) as u8,
+ (g as f32 * 0.66) as u8,
+ (b as f32 * 0.66) as u8
+ )),
lint.message
))
.with_color(primary_color),
diff --git a/harper-cli/src/main.rs b/harper-cli/src/main.rs
index c68d24a91..41c37d5f6 100644
--- a/harper-cli/src/main.rs
+++ b/harper-cli/src/main.rs
@@ -59,6 +59,9 @@ enum Args {
/// If omitted, `harper-cli` will run every rule.
#[arg(long, value_delimiter = ',')]
only: Option<Vec<String>>,
+ /// Overlapping lints are removed by default. This option disables that behavior.
+ #[arg(short = 'o', long)]
+ keep_overlapping_lints: bool,
/// Specify the dialect.
#[arg(short, long, default_value = Dialect::American.to_string())]
dialect: Dialect,
@@ -198,6 +201,7 @@ fn main() -> anyhow::Result<()> {
count,
ignore,
only,
+ keep_overlapping_lints,
dialect,
user_dict_path,
// TODO workspace_dict_path?
@@ -211,6 +215,7 @@ fn main() -> anyhow::Result<()> {
count,
ignore,
only,
+ keep_overlapping_lints,
dialect,
},
user_dict_path,