Skip to content

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

feat: `quiet` switch for `harper-cli lint` (#3583)

Andrew Dunbar57781448458d
diff --git a/harper-cli/src/lint.rs b/harper-cli/src/lint.rs
index e0cc731ba..83f819080 100644
--- a/harper-cli/src/lint.rs
+++ b/harper-cli/src/lint.rs
@@ -93,6 +93,7 @@ pub struct LintOptions {
pub weirpack_inputs: Vec<SingleInput>,
pub color: bool,
pub format: OutputFormat,
+ pub quiet: bool,
}
enum ReportStyle {
@@ -407,6 +408,7 @@ fn lint_one_input(
weirpack_inputs: _,
color: _,
format: _,
+ quiet: _,
} = lint_options;
let mut lint_kinds: HashMap<LintKind, usize> = HashMap::new();
@@ -526,7 +528,7 @@ fn lint_one_input(
&lint_rules,
// Reporting arguments
batch_mode,
- report_mode,
+ (report_mode, lint_options.quiet),
);
}
}
@@ -629,8 +631,10 @@ fn single_input_report(
lint_rules: &HashMap<String, usize>,
// Reporting parameters
batch_mode: bool, // If true, we are processing multiple files, which affects how we report
- report_mode: &ReportStyle,
+ report_info: (&ReportStyle, bool),
) {
+ let (report_mode, quiet) = report_info;
+
// JSON mode: all output is handled by the caller after collecting results
if matches!(report_mode, ReportStyle::Json) {
return;
@@ -667,23 +671,30 @@ fn single_input_report(
if batch_mode && longest > MAX_LINE_LEN && matches!(report_mode, ReportStyle::FullAriadne) {
report_mode = &ReportStyle::BriefCountsOnly;
- println!(
- "{}: Longest line: {longest} exceeds max line length: {MAX_LINE_LEN}",
- input.format_path()
- );
+ if !quiet {
+ println!(
+ "{}: Longest line: {longest} exceeds max line length: {MAX_LINE_LEN}",
+ input.format_path()
+ );
+ }
}
// Report the number of lints no matter what report mode we are in
- println!(
- "{}: {}",
- input.format_path(),
- match (lint_count_before, lint_count_after) {
- (0, _) => "No lints found".to_string(),
- (before, after) if before != after =>
- format!("{before} lints before overlap removal, {after} after"),
- (before, _) => format!("{before} lints"),
+ if lint_count_before == 0 {
+ if !quiet {
+ println!("{}: No lints found", input.format_path());
}
- );
+ } else {
+ println!(
+ "{}: {}",
+ input.format_path(),
+ match (lint_count_before, lint_count_after) {
+ (before, after) if before != after =>
+ format!("{before} lints before overlap removal, {after} after"),
+ (before, _) => format!("{before} lints"),
+ }
+ );
+ }
// If we are in Ariadne mode, print the report
if matches!(report_mode, ReportStyle::FullAriadne) {
diff --git a/harper-cli/src/main.rs b/harper-cli/src/main.rs
index 097afc58a..44e4a2d75 100644
--- a/harper-cli/src/main.rs
+++ b/harper-cli/src/main.rs
@@ -89,6 +89,9 @@ enum Args {
/// Output format for lint results.
#[arg(long, value_enum, default_value_t = OutputFormat::Default)]
format: OutputFormat,
+ /// Suppress informational status messages and only output actual lint errors.
+ #[arg(long)]
+ quiet: bool,
},
/// Parse a provided document and print the detected symbols.
Parse {
@@ -251,6 +254,7 @@ fn main() -> anyhow::Result<()> {
file_dict_path,
weirpacks,
format,
+ quiet,
} => {
let dialect = parse_dialect(&dialect_str)
.map_err(|e| anyhow!("Invalid dialect '{}': {}", dialect_str, e))?;
@@ -268,6 +272,7 @@ fn main() -> anyhow::Result<()> {
weirpack_inputs: weirpacks,
color,
format,
+ quiet,
},
user_dict_path,
// TODO workspace_dict_path?