Skip to content

Commit

Permalink
Fix clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ssanj committed May 25, 2024
1 parent c201aa6 commit 031a27e
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quiet"
version = "0.3.8"
version = "0.3.9"
edition = "2021"
authors = ["Sanj Sahayam"]
description = "Reduce Cargo's compiler information output"
Expand Down
3 changes: 3 additions & 0 deletions qclippy
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

cargo watch -x 'clippy --message-format json-diagnostic-rendered-ansi 2>&1 | quiet --items 1 --show-warnings'
3 changes: 3 additions & 0 deletions qclippy-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

cargo watch -x 'clippy --tests --message-format json-diagnostic-rendered-ansi 2>&1 | quiet --items 1 --show-warnings'
16 changes: 8 additions & 8 deletions src/process/compiler_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::format as s;
use ansi_term::Color::Red;


#[allow(clippy::enum_variant_names)]
pub enum ItemTypes {
CompilerMessageType(CompilerMessage),
StdoutLineType(String),
Expand Down Expand Up @@ -37,17 +38,16 @@ fn get_compiler_messages() -> Vec<Result<CompilerMessageDecodingStatus, String>>
stdin()
.lock()
.lines()
.into_iter()
.map(|line_result|{
let line = line_result.unwrap();
// if it's not a JSON payload
if !&line.starts_with("{") {
if !&line.starts_with('{') {
Ok(CompilerMessageDecodingStatus::StdOutLine(line))
} else {
let process_result: Result<CompilerMessageDecodingStatus, String> =
process_compiler_message(line.as_str())
.map(|maybe_cm| {
maybe_cm.map_or_else(|| CompilerMessageDecodingStatus::Ignore, |cm| CompilerMessageDecodingStatus::DecodedCompilerMessage(cm))
maybe_cm.map_or_else(|| CompilerMessageDecodingStatus::Ignore, CompilerMessageDecodingStatus::DecodedCompilerMessage)
});

process_result
Expand All @@ -61,14 +61,14 @@ fn process_compiler_message(line: &str) -> Result<Option<CompilerMessage>, Strin
let reason =
decode_reason(line)
.map_err(|e| {
s!("******************* Failed to decode Reason from this line: {}\ncause: {}", Red.paint(line), e.to_string())
s!("******************* Failed to decode Reason from this line: {}\ncause: {}", Red.paint(line), e)
})?;

if reason.reason == "compiler-message" {
decode_compiler_message(line)
.map(|cm| Some(cm))
.map(Some)
.map_err(|e| {
s!("******************* Failed to decode CompilerMessage from this line: {}\ncause: {}", Red.paint(line), e.to_string())
s!("******************* Failed to decode CompilerMessage from this line: {}\ncause: {}", Red.paint(line), e)
})
} else {
Ok(None)
Expand All @@ -77,10 +77,10 @@ fn process_compiler_message(line: &str) -> Result<Option<CompilerMessage>, Strin


fn decode_reason(line: &str) -> serde_json::Result<Reason> {
serde_json::from_str(&line)
serde_json::from_str(line)
}


fn decode_compiler_message(line: &str) -> serde_json::Result<CompilerMessage> {
serde_json::from_str(&line)
serde_json::from_str(line)
}
3 changes: 1 addition & 2 deletions src/process/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ pub fn by_filename(file_to_show_errors_for: Option<String>, matched: Vec<Compile
.ends_with(&file_name_filter)
});

let has_matches = !filter_matches.collect::<Vec<_>>().is_empty();
has_matches
!filter_matches.collect::<Vec<_>>().is_empty()
})
.collect::<Vec<_>>()
},
Expand Down
40 changes: 20 additions & 20 deletions src/process/stdout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ fn get_stdout_lines(line_types: Vec<LineType>, filtered_out: Vec<String>) -> Vec
Some(output)
},
LineType::TestDots(line) => Some(test_run_dots_string(line.as_str())),
LineType::Finished(_) => None,
LineType::Compiling(_) => None,
LineType::Error(_) => None,
LineType::Warning(_) => None,
LineType::Finished => None,
LineType::Compiling => None,
LineType::Error => None,
LineType::Warning => None,
LineType::Running(line) => Some(test_name_string(line.as_str())),
LineType::SingleTestOk(_) => {
LineType::SingleTestOk => {
// TODO: Move to a function
let existing_success_count = test_results_buffer.get("success");
if let Some(success_count) = existing_success_count {
Expand Down Expand Up @@ -127,20 +127,20 @@ fn get_line_types(stdout_lines: Vec<String>) -> Vec<LineType> {
LineType::TestResultFailed(line)
} else if line.starts_with("test result: ok.") {
LineType::TestResultOk(line)
} else if line.split_inclusive(".").count() == line.len() {
} else if line.split_inclusive('.').count() == line.len() {
LineType::TestDots(line)
} else if line.trim().starts_with("Finished ") {
LineType::Finished(line)
LineType::Finished
} else if line.trim().starts_with("Compiling ") {
LineType::Compiling(line)
LineType::Compiling
} else if line.trim().starts_with("error: ") {
LineType::Error(line)
LineType::Error
} else if line.trim().starts_with("warning: ") {
LineType::Warning(line)
LineType::Warning
} else if line.trim().starts_with("Running ") {
LineType::Running(line)
} else if line.ends_with("... ok") {
LineType::SingleTestOk(line)
LineType::SingleTestOk
} else if line.ends_with("... FAILED") {
LineType::SingleTestFailed(line)
} else {
Expand All @@ -163,12 +163,12 @@ enum LineType {
TestResultFailed(String),
TestResultOk(String),
TestDots(String),
Finished(String),
Compiling(String),
Error(String),
Warning(String),
Finished,
Compiling,
Error,
Warning,
Running(String),
SingleTestOk(String),
SingleTestOk,
SingleTestFailed(String),
Unprocessed(String),
}
Expand Down Expand Up @@ -198,28 +198,28 @@ fn failure_line_string(line: &str, maybe_dots: Option<&str>) -> String {

fn test_failure_string(line: &str) -> String {
let failure = s!("test result: {}.", Red.paint("FAILED"));
let message = s!("{}{}", failure, line.strip_prefix("test result: FAILED.").unwrap_or_else(|| ""));
let message = s!("{}{}", failure, line.strip_prefix("test result: FAILED.").unwrap_or(""));
s!("{} {}", RGB(133, 138, 118).paint("stdout:"), message)
}


fn success_dots_string(successes: Option<&u32>) -> Option<String> {
successes
.map(|dots_count|{
let dots_str = (0 .. *dots_count).into_iter().map(|_| ".").collect::<String>();
let dots_str = (0 .. *dots_count).map(|_| ".").collect::<String>();
s!("{}", Green.paint(dots_str))
})
}


fn test_success_string(line: &str, maybe_dots: Option<&str>) -> String {
let test_result = s!("test result: {}.", Green.paint("ok"));
let message = s!("{}{}", test_result, line.strip_prefix("test result: ok.").unwrap_or_else(|| ""));
let message = s!("{}{}", test_result, line.strip_prefix("test result: ok.").unwrap_or(""));

let formatted_test_result = s!("{} {}", RGB(133, 138, 118).paint("stdout:"), message);
match maybe_dots {
Some(dots) => s!("{}\n{}", &dots, &formatted_test_result),
None => s!("{}", &formatted_test_result),
None => formatted_test_result,
}
}

Expand Down

0 comments on commit 031a27e

Please sign in to comment.