From 049f1198bb82c7690661b911fd4db78d82cc7c83 Mon Sep 17 00:00:00 2001 From: marschattha Date: Thu, 28 Nov 2024 01:56:32 +0500 Subject: [PATCH 1/3] Add missing_output_as_error to DriverDef --- qlty-check/src/executor/invocation_result.rs | 26 +++++++++++++------ .../missing_output_as_error.in/.gitignore | 4 +++ .../.qlty/qlty.toml | 15 +++++++++++ .../missing_output_as_error.in/sample.sh | 2 ++ .../cmd/check/missing_output_as_error.stderr | 3 +++ .../cmd/check/missing_output_as_error.stdout | 4 +++ .../cmd/check/missing_output_as_error.toml | 3 +++ qlty-config/src/config/plugin.rs | 3 +++ 8 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 qlty-cli/tests/cmd/check/missing_output_as_error.in/.gitignore create mode 100644 qlty-cli/tests/cmd/check/missing_output_as_error.in/.qlty/qlty.toml create mode 100644 qlty-cli/tests/cmd/check/missing_output_as_error.in/sample.sh create mode 100644 qlty-cli/tests/cmd/check/missing_output_as_error.stderr create mode 100644 qlty-cli/tests/cmd/check/missing_output_as_error.stdout create mode 100644 qlty-cli/tests/cmd/check/missing_output_as_error.toml diff --git a/qlty-check/src/executor/invocation_result.rs b/qlty-check/src/executor/invocation_result.rs index b0f4eae98..a6596f3ea 100644 --- a/qlty-check/src/executor/invocation_result.rs +++ b/qlty-check/src/executor/invocation_result.rs @@ -276,7 +276,11 @@ impl InvocationResult { self.invocation.tmpfile_contents = Some(contents); } Err(e) => { - self.invocation.parser_error = Some(e.to_string()); + if self.plan.driver.missing_output_as_error { + self.invocation.tmpfile_contents = Some("".to_string()); + } else { + self.invocation.parser_error = Some(e.to_string()); + } } } @@ -323,14 +327,20 @@ impl InvocationResult { &self.invocation.stdout }; - let file_results = self.plan.driver.parse(output, &self.plan); + if output.is_empty() && self.plan.driver.missing_output_as_error { + self.invocation.exit_result = + qlty_types::analysis::v1::ExitResult::UnknownError.into(); + self.log_error_output(); + } else { + let file_results = self.plan.driver.parse(output, &self.plan); - match file_results { - Ok(file_results) => { - self.file_results = Some(file_results); - } - Err(e) => { - self.invocation.parser_error = Some(e.to_string()); + match file_results { + Ok(file_results) => { + self.file_results = Some(file_results); + } + Err(e) => { + self.invocation.parser_error = Some(e.to_string()); + } } } } diff --git a/qlty-cli/tests/cmd/check/missing_output_as_error.in/.gitignore b/qlty-cli/tests/cmd/check/missing_output_as_error.in/.gitignore new file mode 100644 index 000000000..abbd1c70e --- /dev/null +++ b/qlty-cli/tests/cmd/check/missing_output_as_error.in/.gitignore @@ -0,0 +1,4 @@ +.qlty/results +.qlty/logs +.qlty/out +.qlty/sources diff --git a/qlty-cli/tests/cmd/check/missing_output_as_error.in/.qlty/qlty.toml b/qlty-cli/tests/cmd/check/missing_output_as_error.in/.qlty/qlty.toml new file mode 100644 index 000000000..16e0dc0b2 --- /dev/null +++ b/qlty-cli/tests/cmd/check/missing_output_as_error.in/.qlty/qlty.toml @@ -0,0 +1,15 @@ +config_version = "0" + +[plugins.definitions.exists] +file_types = ["shell"] + +[plugins.definitions.exists.drivers.lint] +prepare_script = "mkdir ${linter} && echo dir %2 > ${linter}/ls.cmd" +script = "echo \"The plugin crashed for some reason\"" +success_codes = [0] +output = "tmpfile" +missing_output_as_error = true + +[[plugin]] +name = "exists" +version = "1.0.0" diff --git a/qlty-cli/tests/cmd/check/missing_output_as_error.in/sample.sh b/qlty-cli/tests/cmd/check/missing_output_as_error.in/sample.sh new file mode 100644 index 000000000..3aa740acf --- /dev/null +++ b/qlty-cli/tests/cmd/check/missing_output_as_error.in/sample.sh @@ -0,0 +1,2 @@ +#!/bin/sh +echo "$foo" diff --git a/qlty-cli/tests/cmd/check/missing_output_as_error.stderr b/qlty-cli/tests/cmd/check/missing_output_as_error.stderr new file mode 100644 index 000000000..fb45509fd --- /dev/null +++ b/qlty-cli/tests/cmd/check/missing_output_as_error.stderr @@ -0,0 +1,3 @@ + [0/1] [..]Planning... [..]s + [1/1] [..]Analyzing all targets...[..] +❌ Lint error diff --git a/qlty-cli/tests/cmd/check/missing_output_as_error.stdout b/qlty-cli/tests/cmd/check/missing_output_as_error.stdout new file mode 100644 index 000000000..997de497d --- /dev/null +++ b/qlty-cli/tests/cmd/check/missing_output_as_error.stdout @@ -0,0 +1,4 @@ +Lint error exists: Exited with code 0 .qlty/out/invocations/invoke-[..].yaml + The plugin crashed for some reason + +Checked 1 files diff --git a/qlty-cli/tests/cmd/check/missing_output_as_error.toml b/qlty-cli/tests/cmd/check/missing_output_as_error.toml new file mode 100644 index 000000000..1e5615cbe --- /dev/null +++ b/qlty-cli/tests/cmd/check/missing_output_as_error.toml @@ -0,0 +1,3 @@ +bin.name = "qlty" +args = ["check", "--all", "--no-cache"] +status.code = 3 diff --git a/qlty-config/src/config/plugin.rs b/qlty-config/src/config/plugin.rs index 6c0bddc6f..4a87374dd 100644 --- a/qlty-config/src/config/plugin.rs +++ b/qlty-config/src/config/plugin.rs @@ -110,6 +110,9 @@ pub struct DriverDef { #[serde(default)] pub autoload_script: Option, + + #[serde(default)] + pub missing_output_as_error: bool, } fn default_driver_timeout() -> u64 { From 751be4da4d1607db8f809497f0c653423d2e20d0 Mon Sep 17 00:00:00 2001 From: marschattha Date: Thu, 28 Nov 2024 21:06:11 +0500 Subject: [PATCH 2/3] --- qlty-cli/tests/cmd/check/missing_output_as_error.in/sample.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qlty-cli/tests/cmd/check/missing_output_as_error.in/sample.sh b/qlty-cli/tests/cmd/check/missing_output_as_error.in/sample.sh index 3aa740acf..279508d8e 100644 --- a/qlty-cli/tests/cmd/check/missing_output_as_error.in/sample.sh +++ b/qlty-cli/tests/cmd/check/missing_output_as_error.in/sample.sh @@ -1,2 +1,2 @@ #!/bin/sh -echo "$foo" +echo "hi" From 0fec7aafa12f1cf60f71d0465892dc50407ed671 Mon Sep 17 00:00:00 2001 From: marschattha Date: Thu, 28 Nov 2024 21:30:15 +0500 Subject: [PATCH 3/3] fix windows test --- qlty-cli/tests/cmd/check/missing_output_as_error.stdout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qlty-cli/tests/cmd/check/missing_output_as_error.stdout b/qlty-cli/tests/cmd/check/missing_output_as_error.stdout index 997de497d..a568d64fc 100644 --- a/qlty-cli/tests/cmd/check/missing_output_as_error.stdout +++ b/qlty-cli/tests/cmd/check/missing_output_as_error.stdout @@ -1,4 +1,4 @@ Lint error exists: Exited with code 0 .qlty/out/invocations/invoke-[..].yaml - The plugin crashed for some reason +[..]The plugin crashed for some reason[..] Checked 1 files