Skip to content

Commit

Permalink
revise: reports a non-zero exit code when an error is encountered
Browse files Browse the repository at this point in the history
  • Loading branch information
claymcleod committed Dec 18, 2023
1 parent 7ce5d52 commit fbed0bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ pub struct Args {

pub fn lint(args: Args) -> anyhow::Result<()> {
let (config, writer) = get_display_config(&args);
Ok(
sprocket::file::Repository::try_new(args.paths, args.extensions)?
.report_concerns(config, writer)?,
)

if sprocket::file::Repository::try_new(args.paths, args.extensions)?
.report_concerns(config, writer)?
{
std::process::exit(1);
}

Ok(())
}

fn get_display_config(args: &Args) -> (Config, StandardStream) {
Expand Down
13 changes: 10 additions & 3 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use codespan_reporting::files::SimpleFiles;
use codespan_reporting::term::termcolor::StandardStream;
use codespan_reporting::term::Config;
use indexmap::IndexMap;
use wdl::core::Concern;

use crate::report::Reporter;

Expand Down Expand Up @@ -247,20 +248,26 @@ impl Repository {
///
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
pub fn report_concerns(&self, config: Config, writer: StandardStream) -> Result<()> {
pub fn report_concerns(&self, config: Config, writer: StandardStream) -> Result<bool> {
let mut reporter = Reporter::new(config, writer, &self.sources);
let mut reported_error = false;

for (file_name, handle) in self.handles.iter() {
let document = self.parse(file_name)?;

if let Some(concerns) = document.into_concerns() {
for concern in concerns.into_inner() {
reporter.report_concern(concern, *handle);
reporter.report_concern(&concern, *handle);

match concern {
Concern::ParseError(_) | Concern::ValidationFailure(_) => reported_error = true,
_ => {}
}
}
}
}

Ok(())
Ok(reported_error)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<'a> Reporter<'a> {
}

/// Reports a concern to the terminal.
pub(crate) fn report_concern(&mut self, concern: Concern, handle: usize) {
pub(crate) fn report_concern(&mut self, concern: &Concern, handle: usize) {
let diagnostic = match concern {
Concern::LintWarning(warning) => {
let mut diagnostic = Diagnostic::warning()
Expand Down

0 comments on commit fbed0bd

Please sign in to comment.