Skip to content

Commit

Permalink
various improvements to src
Browse files Browse the repository at this point in the history
  • Loading branch information
2bndy5 committed Jan 2, 2025
1 parent d5d5e8a commit 8f4d364
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 35 deletions.
8 changes: 4 additions & 4 deletions cpp-linter/src/clang_tools/clang_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ pub fn run_clang_format(
.to_str()
.unwrap_or_default(),
cmd.get_args()
.map(|a| a.to_str().unwrap())
.collect::<Vec<&str>>()
.map(|a| a.to_string_lossy())
.collect::<Vec<_>>()
.join(" ")
),
));
Expand All @@ -153,8 +153,8 @@ pub fn run_clang_format(
"Running \"{} {}\"",
cmd.get_program().to_string_lossy(),
cmd.get_args()
.map(|x| x.to_str().unwrap())
.collect::<Vec<&str>>()
.map(|x| x.to_string_lossy())
.collect::<Vec<_>>()
.join(" ")
),
));
Expand Down
24 changes: 13 additions & 11 deletions cpp-linter/src/clang_tools/clang_tidy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,17 @@ pub fn run_clang_tidy(
let file_name = file.name.to_string_lossy().to_string();
if clang_params.lines_changed_only != LinesChangedOnly::Off {
let ranges = file.get_ranges(&clang_params.lines_changed_only);
let filter = format!(
"[{{\"name\":{:?},\"lines\":{:?}}}]",
&file_name.replace('/', if OS == "windows" { "\\" } else { "/" }),
ranges
.iter()
.map(|r| [r.start(), r.end()])
.collect::<Vec<_>>()
);
cmd.args(["--line-filter", filter.as_str()]);
if !ranges.is_empty() {
let filter = format!(
"[{{\"name\":{:?},\"lines\":{:?}}}]",
&file_name.replace('/', if OS == "windows" { "\\" } else { "/" }),
ranges
.iter()
.map(|r| [r.start(), r.end()])
.collect::<Vec<_>>()
);
cmd.args(["--line-filter", filter.as_str()]);
}
}
let mut original_content = None;
if clang_params.tidy_review {
Expand All @@ -294,8 +296,8 @@ pub fn run_clang_tidy(
"Running \"{} {}\"",
cmd.get_program().to_string_lossy(),
cmd.get_args()
.map(|x| x.to_str().unwrap())
.collect::<Vec<&str>>()
.map(|x| x.to_string_lossy())
.collect::<Vec<_>>()
.join(" ")
),
));
Expand Down
5 changes: 2 additions & 3 deletions cpp-linter/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,13 @@ pub fn convert_extra_arg_val(args: &ArgMatches) -> Vec<String> {
let mut val = args.get_many::<String>("extra-arg").unwrap_or_default();
if val.len() == 1 {
// specified once; split and return result
return val
.next()
val.next()
.unwrap()
.trim_matches('\'')
.trim_matches('"')
.split(' ')
.map(|i| i.to_string())
.collect();
.collect()
} else {
// specified multiple times; just return
val.map(|i| i.to_string()).collect()
Expand Down
7 changes: 6 additions & 1 deletion cpp-linter/src/common_fs/file_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,15 @@ impl FileFilter {
let glob_matched =
glob_match(pattern, file_name.to_string_lossy().to_string().as_str());
let pat = PathBuf::from(&pattern);
if glob_matched
if pattern.as_str() == "./"
|| glob_matched
|| (pat.is_file() && file_name == pat)
|| (pat.is_dir() && file_name.starts_with(pat))
{
log::debug!(
"file {file_name:?} is in {}ignored with domain {pattern:?}.",
if is_ignored { "" } else { "not " }
);
return true;
}
}
Expand Down
11 changes: 4 additions & 7 deletions cpp-linter/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,10 @@ pub fn parse_diff(diff: &git2::Diff, file_filter: &FileFilter) -> Vec<FileObj> {
for file_idx in 0..diff.deltas().count() {
let diff_delta = diff.get_delta(file_idx).unwrap();
let file_path = diff_delta.new_file().path().unwrap().to_path_buf();
if [
git2::Delta::Added,
git2::Delta::Modified,
git2::Delta::Renamed,
]
.contains(&diff_delta.status())
&& file_filter.is_source_or_ignored(&file_path)
if matches!(
diff_delta.status(),
git2::Delta::Added | git2::Delta::Modified | git2::Delta::Renamed,
) && file_filter.is_source_or_ignored(&file_path)
{
let (added_lines, diff_chunks) =
parse_patch(&Patch::from_diff(diff, file_idx).unwrap().unwrap());
Expand Down
4 changes: 2 additions & 2 deletions cpp-linter/src/rest_api/github/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl RestApiClient for GithubApiClient {
self.post_annotations(files, feedback_inputs.style.as_str());
}
if feedback_inputs.step_summary {
comment = Some(self.make_comment(
comment = Some(Self::make_comment(
files,
format_checks_failed,
tidy_checks_failed,
Expand All @@ -259,7 +259,7 @@ impl RestApiClient for GithubApiClient {
if feedback_inputs.thread_comments != ThreadComments::Off {
// post thread comment for PR or push event
if comment.as_ref().is_some_and(|c| c.len() > 65535) || comment.is_none() {
comment = Some(self.make_comment(
comment = Some(Self::make_comment(
files,
format_checks_failed,
tidy_checks_failed,
Expand Down
2 changes: 2 additions & 0 deletions cpp-linter/src/rest_api/github/serde_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub struct GithubChangedFile {
pub previous_filename: Option<String>,
/// The individual patch that describes the file's changes.
pub patch: Option<String>,
/// The number of changes to the file contents.
pub changes: i64,
}

/// A structure for deserializing a Push event's changed files.
Expand Down
1 change: 0 additions & 1 deletion cpp-linter/src/rest_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ pub trait RestApiClient {
/// Returns the markdown comment as a string as well as the total count of
/// `format_checks_failed` and `tidy_checks_failed` (in respective order).
fn make_comment(
&self,
files: &[Arc<Mutex<FileObj>>],
format_checks_failed: u64,
tidy_checks_failed: u64,
Expand Down
8 changes: 2 additions & 6 deletions cpp-linter/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,8 @@ pub async fn run_main(args: Vec<String>) -> Result<()> {
.post_feedback(&arc_files, user_inputs, clang_versions)
.await?;
rest_api_client.end_log_group();
if env::var("PRE_COMMIT").is_ok_and(|v| v == "1") {
if checks_failed > 1 {
return Err(anyhow!("Some checks did not pass"));
} else {
return Ok(());
}
if env::var("PRE_COMMIT").is_ok_and(|v| v == "1") && checks_failed > 1 {
return Err(anyhow!("Some checks did not pass"));
}
Ok(())
}
Expand Down

0 comments on commit 8f4d364

Please sign in to comment.