From 30445d7983f291fb8de68ab3e9043c7e742b3093 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Tue, 29 Sep 2026 20:02:14 +0200 Subject: [PATCH] feat: default to colored miette diagnostics --- .run_status.toml | 6 ++-- README.md | 5 +++- docs/development.md | 10 +++---- docs/output.md | 21 +++++++------- docs/usage.md | 14 ++++----- src/bin/john-slop.rs | 3 +- src/bin/john-slop/output.rs | 29 +++++++++++++++---- tasks.md | 9 ++++++ tests/cli.rs | 17 +++++++++++ tests/example_fixtures.rs | 5 +++- ...p_is_successful_and_names_the_command.snap | 3 +- 11 files changed, 86 insertions(+), 36 deletions(-) diff --git a/.run_status.toml b/.run_status.toml index cb4259b..bf16634 100644 --- a/.run_status.toml +++ b/.run_status.toml @@ -1,8 +1,8 @@ [last_run_clean] run_status = "Success" -lines_parsed = 335 +lines_parsed = 337 coverage = 92.16 [last_run_clean.run_duration] -secs = 34 -nanos = 910199784 +secs = 29 +nanos = 214508516 diff --git a/README.md b/README.md index bb6d4ad..4399a3a 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,6 @@ cargo install --git https://git.dandaedre.com/idle-org/john_slop \ --locked --all-features cargo run --bin john-slop -- path/to/document path/to/source-directory -cargo run --bin john-slop -- --output miette path/to/document cargo run --bin john-slop-fmt -- path/to/document cargo run --bin john-slop-fmt -- --check path/to/document cargo run --bin john-slop-lsp @@ -43,6 +42,10 @@ Formatter file mode prints transformed text without modifying the source. Use `--write` explicitly for atomic in-place replacement, or pipe editor buffers through `john-slop-fmt` over stdin/stdout. +The detector defaults to colored graphical Miette diagnostics. Select +`--output human`, `--output concise`, or `--output json` for uncolored plain or +machine-readable output. + Editors start `john-slop-lsp` over stdio. It tracks open snapshots with full document synchronization, reports configured ASCII replacements, and offers quick fixes whose result matches the formatter. See the editor guide for Helix diff --git a/docs/development.md b/docs/development.md index 528c6ca..65b9e1b 100644 --- a/docs/development.md +++ b/docs/development.md @@ -20,11 +20,11 @@ cargo audit --deny warnings cargo deny --locked check ``` -The default `fancy-diagnostics` feature enables `miette`'s rich terminal -renderer. The no-default-features test run ensures the shared library and all -binaries remain valid without that optional renderer. Focused unit and -integration tests cover domain invariants, input failures, archives, CLI exit -behavior, and feature configurations. +The default `fancy-diagnostics` feature enables the detector's colored Miette +renderer and default output mode. The no-default-features test run ensures the +shared library and all binaries remain valid with the plain fallback. Focused +unit and integration tests cover domain invariants, input failures, archives, +CLI exit behavior, and feature configurations. CI runs the executable fixture manifest and Insta CLI snapshots explicitly in addition to the full suite. `cargo-audit` rejects RustSec advisories and yanked diff --git a/docs/output.md b/docs/output.md index b9bdd69..06a8615 100644 --- a/docs/output.md +++ b/docs/output.md @@ -7,19 +7,20 @@ container, and findings are sorted by byte span and rule ID. ## Human -`--output human` is the default. Every finding is rendered as a plain -`miette` diagnostic with the source name, exact excerpt and primary span, -severity, stable rule code, message, and remediation help. A final line per -document reports the confidence score/band and advice, warning, and error -counts. The narratable renderer deliberately avoids ANSI escapes. +`--output human` renders every finding as a plain `miette` diagnostic with the +source name, exact excerpt and primary span, severity, stable rule code, +message, and remediation help. A final line per document reports the confidence +score/band and advice, warning, and error counts. The narratable renderer +deliberately avoids ANSI escapes. ## Miette -`--output miette` renders the same typed diagnostics with Miette's graphical -Unicode source annotations and a deterministic no-color theme, followed by the -same summary. This mode requires the default `fancy-diagnostics` Cargo feature; -builds made with `--no-default-features` accept the option but fall back to the -plain human renderer. +`--output miette` is the default. It renders the same typed diagnostics with +Miette's graphical Unicode source annotations and ANSI severity colors, +followed by the same summary. This mode requires the default +`fancy-diagnostics` Cargo feature; builds made with `--no-default-features` +accept the option but fall back to the plain human renderer. Select `human`, +`concise`, or `json` when ANSI escapes are not appropriate. ## Concise diff --git a/docs/usage.md b/docs/usage.md index fd07930..28e71ce 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -23,13 +23,13 @@ limits can be overridden with `--max-document-bytes`, `--max-archive-bytes`, `--max-compression-ratio`, and `--max-walk-depth`. Select output with `--output human`, `--output miette`, `--output concise`, or -`--output json`. Human mode renders plain source excerpts, exact labels, -remediation help, and a summary. Miette mode uses Unicode graphical source -annotations when the default `fancy-diagnostics` feature is enabled and falls -back to human mode without that feature. Concise mode emits stable single-line -finding and summary records. JSON mode emits one object per analyzed document -with `schema_version: 1`, summary fields, exact byte spans, and every finding. -Machine modes never emit ANSI escapes or logs on stdout. +`--output json`. Miette is the default and uses colored Unicode graphical source +annotations when the default `fancy-diagnostics` feature is enabled; it falls +back to human mode without that feature. Human mode renders uncolored plain +source excerpts, exact labels, remediation help, and a summary. Concise mode +emits stable single-line finding and summary records. JSON mode emits one object +per analyzed document with `schema_version: 1`, summary fields, exact byte spans, +and every finding. Machine modes never emit ANSI escapes or logs on stdout. Findings cover the embedded or overridden heuristic catalog and retain exact UTF-8 byte spans through every output mode. See [Output contracts](output.md) diff --git a/src/bin/john-slop.rs b/src/bin/john-slop.rs index 90fcf43..c5b419e 100644 --- a/src/bin/john-slop.rs +++ b/src/bin/john-slop.rs @@ -73,7 +73,7 @@ struct Cli { #[arg(long, value_name = "GLOB", action = clap::ArgAction::Append)] ignore: Vec, - /// Select plain human, graphical Miette, concise, or versioned JSON output. + /// Select colored graphical Miette, plain human, concise, or versioned JSON output. #[arg( long, value_enum, @@ -340,6 +340,7 @@ mod tests { assert_eq!(cli.fail_confidence, 42); assert_eq!(cli.fail_level, None); + assert_eq!(cli.output, OutputFormat::Miette); assert_eq!(cli.config_name, None); assert!(cli.command.is_none()); assert_eq!( diff --git a/src/bin/john-slop/output.rs b/src/bin/john-slop/output.rs index e65ba3e..f60caaf 100644 --- a/src/bin/john-slop/output.rs +++ b/src/bin/john-slop/output.rs @@ -11,9 +11,9 @@ use serde::Serialize; #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, ValueEnum)] pub enum OutputFormat { /// Plain source-highlighted diagnostics followed by a document summary. - #[default] Human, - /// Graphical Unicode diagnostics (falls back to plain output without the fancy feature). + /// Colored graphical Unicode diagnostics (plain fallback without the fancy feature). + #[default] Miette, /// One stable single-line record per finding plus one summary record. Concise, @@ -79,7 +79,7 @@ fn render_human(source_id: &SourceId, source: &str, analysis: &Analysis) -> Stri #[cfg(feature = "fancy-diagnostics")] fn render_miette(source_id: &SourceId, source: &str, analysis: &Analysis) -> String { let mut rendered = String::new(); - let handler = GraphicalReportHandler::new_themed(GraphicalTheme::unicode_nocolor()) + let handler = GraphicalReportHandler::new_themed(GraphicalTheme::unicode()) .without_cause_chain() .with_links(false); for finding in &analysis.findings { @@ -281,6 +281,22 @@ mod tests { assert!(!output.contains('\u{1b}')); } + #[cfg(not(feature = "fancy-diagnostics"))] + #[test] + fn miette_output_falls_back_to_plain_human_without_the_feature() { + let (source, analysis) = analysis(); + let output = render_analysis( + OutputFormat::Miette, + &SourceId::File("article.md".into()), + &source, + &analysis, + ) + .unwrap(); + + assert!(output.contains("article.md")); + assert!(!output.contains('\u{1b}')); + } + #[cfg(feature = "fancy-diagnostics")] #[test] fn miette_output_has_graphical_source_labels_and_summary() { @@ -294,11 +310,12 @@ mod tests { .unwrap(); assert!(output.contains("typography-non-ascii-hyphen")); - assert!(output.contains("╭─[article.md:")); - assert!(output.contains("╰────")); + assert!(output.contains("article.md")); + assert!(output.contains('╭')); + assert!(output.contains('╰')); assert!(output.contains("help:")); assert!(output.contains("confidence")); - assert!(!output.contains('\u{1b}')); + assert!(output.contains('\u{1b}')); } #[test] diff --git a/tasks.md b/tasks.md index b3a2b03..85e89e7 100644 --- a/tasks.md +++ b/tasks.md @@ -260,6 +260,15 @@ raised to 90%. Remaining misses are primarily hard-to-inject OS/I/O failures, malformed dependency internals, overflow guards, and asynchronous LSP error plumbing; pursuing them would add test-only seams or backend-sensitive checks. +## Milestone 9 — Terminal-first diagnostics + +- [x] Make colored graphical Miette diagnostics the detector default while + retaining explicit plain-human, concise, JSON, and no-feature fallback modes. + +Acceptance: a default detector invocation renders graphical Unicode diagnostics +with ANSI severity colors; explicit machine modes remain stable and uncolored, +and builds without `fancy-diagnostics` retain the plain human fallback. + ## Deferred by design - Statistical or model-based authorship classification. diff --git a/tests/cli.rs b/tests/cli.rs index 81e86e8..a1675c0 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -58,6 +58,23 @@ fn invalid_confidence_is_a_usage_error() { insta::assert_snapshot!(String::from_utf8(output.stderr).expect("UTF-8 stderr")); } +#[test] +fn default_output_is_colored_graphical_miette_with_a_plain_feature_fallback() { + let output = detector_with_stdin(&["--stdin"], "suspicious—dash".as_bytes()); + let stdout = String::from_utf8(output.stdout).expect("UTF-8 detector output"); + + assert!(output.status.success()); + assert!(output.stderr.is_empty()); + assert!(stdout.contains("typography-non-ascii-hyphen")); + #[cfg(feature = "fancy-diagnostics")] + { + assert!(stdout.contains('\u{1b}')); + assert!(stdout.contains('╭')); + } + #[cfg(not(feature = "fancy-diagnostics"))] + assert!(!stdout.contains('\u{1b}')); +} + #[test] fn findings_control_the_threshold_exit_code() { let directory = tempdir().expect("temp dir"); diff --git a/tests/example_fixtures.rs b/tests/example_fixtures.rs index 831542c..de8a74c 100644 --- a/tests/example_fixtures.rs +++ b/tests/example_fixtures.rs @@ -163,7 +163,10 @@ fn diagnostic_showcase_is_an_expected_threshold_failure() { assert!(stdout.contains("warning")); assert!(stdout.contains("error")); #[cfg(feature = "fancy-diagnostics")] - assert!(stdout.contains("╭─[")); + { + assert!(stdout.contains('\u{1b}')); + assert!(stdout.contains('╭')); + } } #[test] diff --git a/tests/snapshots/cli__help_is_successful_and_names_the_command.snap b/tests/snapshots/cli__help_is_successful_and_names_the_command.snap index 540eebe..88a00bb 100644 --- a/tests/snapshots/cli__help_is_successful_and_names_the_command.snap +++ b/tests/snapshots/cli__help_is_successful_and_names_the_command.snap @@ -1,6 +1,5 @@ --- source: tests/cli.rs -assertion_line: 18 expression: "String::from_utf8(output.stdout).expect(\"UTF-8 stdout\")" --- Inspect files, directories, or ZIP-based documents for low-care signals @@ -39,7 +38,7 @@ Options: --ignore Skip source paths matching a glob; may be supplied more than once --output - Select plain human, graphical Miette, concise, or versioned JSON output [default: human] + Select colored graphical Miette, plain human, concise, or versioned JSON output [default: miette] --fail-confidence Return exit code 1 when a document reaches this evidence-confidence score [default: 100] --fail-level