From a36ae839fec34d745c9a9781b4ca7fcb691dd142 Mon Sep 17 00:00:00 2001 From: thatrichman Date: Mon, 9 Dec 2024 22:30:27 -0500 Subject: [PATCH] fix: address stylistic comments from PR (#191) --- Cargo.toml | 1 + wdl-lint/Cargo.toml | 5 +++-- wdl-lint/src/rules/shellcheck.rs | 18 +++++++++--------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4998b185..c06ac77c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,7 @@ parking_lot = "0.12.3" path-clean = "1.0.1" petgraph = "0.6.5" pretty_assertions = "1.4.0" +rand = "0.8.5" rayon = "1.10.0" regex = "1.11.1" reqwest = { version = "0.12.5", default-features = false, features = ["rustls-tls", "http2", "charset"] } diff --git a/wdl-lint/Cargo.toml b/wdl-lint/Cargo.toml index 2f247637..438af688 100644 --- a/wdl-lint/Cargo.toml +++ b/wdl-lint/Cargo.toml @@ -13,12 +13,13 @@ readme = "../README.md" [dependencies] wdl-ast = { path = "../wdl-ast", version = "0.9.0" } +anyhow = { workspace = true } convert_case = { workspace = true } indexmap = { workspace = true } +rand = { workspace = true } rowan = { workspace = true } -serde_json = { workspace = true } -anyhow = { workspace = true } serde = { workspace = true } +serde_json = { workspace = true } [dev-dependencies] codespan-reporting = { workspace = true } diff --git a/wdl-lint/src/rules/shellcheck.rs b/wdl-lint/src/rules/shellcheck.rs index d82af7bc..43b155a8 100644 --- a/wdl-lint/src/rules/shellcheck.rs +++ b/wdl-lint/src/rules/shellcheck.rs @@ -1,4 +1,4 @@ -//! A lint rule for checking mixed indentation in command text. +//! A lint rule for running shellcheck against command sections. use std::collections::HashMap; use std::collections::HashSet; use std::io::Write; @@ -63,7 +63,7 @@ const ID: &str = "CommandSectionShellCheck"; /// /// The file and fix fields are ommitted as we have no use for them. #[derive(Clone, Debug, Deserialize)] -struct ShellCheckComment { +struct ShellCheckDiagnostic { /// line number comment starts on pub line: usize, /// line number comment ends on @@ -82,11 +82,11 @@ struct ShellCheckComment { pub message: String, } -/// Run shellcheck +/// Run shellcheck on a command. /// /// writes command text to stdin of shellcheck process -/// and returns parsed ShellCheckComments -fn run_shellcheck(command: &str) -> Result> { +/// and returns parsed `ShellCheckDiagnostic`s +fn run_shellcheck(command: &str) -> Result> { let mut sc_proc = process::Command::new(SHELLCHECK_BIN) .args([ "-s", @@ -117,7 +117,7 @@ fn run_shellcheck(command: &str) -> Result> { // any checked files result in comments // so cannot check with status.success() match output.status.code() { - Some(0) | Some(1) => serde_json::from_slice::>(&output.stdout) + Some(0) | Some(1) => serde_json::from_slice::>(&output.stdout) .context("deserializing STDOUT from `shellcheck` process"), Some(code) => bail!("unexpected `shellcheck` exit code: {}", code), None => bail!("the `shellcheck` process appears to have been interrupted"), @@ -138,10 +138,10 @@ impl Rule for ShellCheckRule { } fn explanation(&self) -> &'static str { - "ShellCheck is a static analysis tool and linter for sh / bash. \ + "ShellCheck (https://shellcheck.net) is a static analysis tool and linter for sh / bash. \ The lints provided by ShellCheck help prevent common errors and \ pitfalls in your scripts. Following its recommendations will increase \ - the robustness of your command blocks." + the robustness of your command sections." } fn tags(&self) -> TagSet { @@ -370,7 +370,7 @@ impl Visitor for ShellCheckRule { let command_keyword = support::token(section.syntax(), SyntaxKind::CommandKeyword) .expect("should have a command keyword token"); state.exceptable_add( - Diagnostic::error("running `shellcheck` on command block") + Diagnostic::error("running `shellcheck` on command section") .with_label(e.to_string(), command_keyword.text_range().to_span()) .with_rule(ID) .with_fix("address reported error."),