Skip to content

Commit 20db821

Browse files
committed
various improvements to src
1 parent 05eacc1 commit 20db821

File tree

9 files changed

+35
-35
lines changed

9 files changed

+35
-35
lines changed

cpp-linter/src/clang_tools/clang_format.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ pub fn run_clang_format(
135135
.to_str()
136136
.unwrap_or_default(),
137137
cmd.get_args()
138-
.map(|a| a.to_str().unwrap())
139-
.collect::<Vec<&str>>()
138+
.map(|a| a.to_string_lossy())
139+
.collect::<Vec<_>>()
140140
.join(" ")
141141
),
142142
));
@@ -153,8 +153,8 @@ pub fn run_clang_format(
153153
"Running \"{} {}\"",
154154
cmd.get_program().to_string_lossy(),
155155
cmd.get_args()
156-
.map(|x| x.to_str().unwrap())
157-
.collect::<Vec<&str>>()
156+
.map(|x| x.to_string_lossy())
157+
.collect::<Vec<_>>()
158158
.join(" ")
159159
),
160160
));

cpp-linter/src/clang_tools/clang_tidy.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,17 @@ pub fn run_clang_tidy(
264264
let file_name = file.name.to_string_lossy().to_string();
265265
if clang_params.lines_changed_only != LinesChangedOnly::Off {
266266
let ranges = file.get_ranges(&clang_params.lines_changed_only);
267-
let filter = format!(
268-
"[{{\"name\":{:?},\"lines\":{:?}}}]",
269-
&file_name.replace('/', if OS == "windows" { "\\" } else { "/" }),
270-
ranges
271-
.iter()
272-
.map(|r| [r.start(), r.end()])
273-
.collect::<Vec<_>>()
274-
);
275-
cmd.args(["--line-filter", filter.as_str()]);
267+
if !ranges.is_empty() {
268+
let filter = format!(
269+
"[{{\"name\":{:?},\"lines\":{:?}}}]",
270+
&file_name.replace('/', if OS == "windows" { "\\" } else { "/" }),
271+
ranges
272+
.iter()
273+
.map(|r| [r.start(), r.end()])
274+
.collect::<Vec<_>>()
275+
);
276+
cmd.args(["--line-filter", filter.as_str()]);
277+
}
276278
}
277279
let mut original_content = None;
278280
if clang_params.tidy_review {
@@ -294,8 +296,8 @@ pub fn run_clang_tidy(
294296
"Running \"{} {}\"",
295297
cmd.get_program().to_string_lossy(),
296298
cmd.get_args()
297-
.map(|x| x.to_str().unwrap())
298-
.collect::<Vec<&str>>()
299+
.map(|x| x.to_string_lossy())
300+
.collect::<Vec<_>>()
299301
.join(" ")
300302
),
301303
));

cpp-linter/src/cli/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -390,14 +390,13 @@ pub fn convert_extra_arg_val(args: &ArgMatches) -> Vec<String> {
390390
let mut val = args.get_many::<String>("extra-arg").unwrap_or_default();
391391
if val.len() == 1 {
392392
// specified once; split and return result
393-
return val
394-
.next()
393+
val.next()
395394
.unwrap()
396395
.trim_matches('\'')
397396
.trim_matches('"')
398397
.split(' ')
399398
.map(|i| i.to_string())
400-
.collect();
399+
.collect()
401400
} else {
402401
// specified multiple times; just return
403402
val.map(|i| i.to_string()).collect()

cpp-linter/src/common_fs/file_filter.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,15 @@ impl FileFilter {
105105
let glob_matched =
106106
glob_match(pattern, file_name.to_string_lossy().to_string().as_str());
107107
let pat = PathBuf::from(&pattern);
108-
if glob_matched
108+
if pattern.as_str() == "./"
109+
|| glob_matched
109110
|| (pat.is_file() && file_name == pat)
110111
|| (pat.is_dir() && file_name.starts_with(pat))
111112
{
113+
log::debug!(
114+
"file {file_name:?} is in {}ignored with domain {pattern:?}.",
115+
if is_ignored { "" } else { "not " }
116+
);
112117
return true;
113118
}
114119
}

cpp-linter/src/git.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,10 @@ pub fn parse_diff(diff: &git2::Diff, file_filter: &FileFilter) -> Vec<FileObj> {
105105
for file_idx in 0..diff.deltas().count() {
106106
let diff_delta = diff.get_delta(file_idx).unwrap();
107107
let file_path = diff_delta.new_file().path().unwrap().to_path_buf();
108-
if [
109-
git2::Delta::Added,
110-
git2::Delta::Modified,
111-
git2::Delta::Renamed,
112-
]
113-
.contains(&diff_delta.status())
114-
&& file_filter.is_source_or_ignored(&file_path)
108+
if matches!(
109+
diff_delta.status(),
110+
git2::Delta::Added | git2::Delta::Modified | git2::Delta::Renamed,
111+
) && file_filter.is_source_or_ignored(&file_path)
115112
{
116113
let (added_lines, diff_chunks) =
117114
parse_patch(&Patch::from_diff(diff, file_idx).unwrap().unwrap());

cpp-linter/src/rest_api/github/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl RestApiClient for GithubApiClient {
241241
self.post_annotations(files, feedback_inputs.style.as_str());
242242
}
243243
if feedback_inputs.step_summary {
244-
comment = Some(self.make_comment(
244+
comment = Some(Self::make_comment(
245245
files,
246246
format_checks_failed,
247247
tidy_checks_failed,
@@ -259,7 +259,7 @@ impl RestApiClient for GithubApiClient {
259259
if feedback_inputs.thread_comments != ThreadComments::Off {
260260
// post thread comment for PR or push event
261261
if comment.as_ref().is_some_and(|c| c.len() > 65535) || comment.is_none() {
262-
comment = Some(self.make_comment(
262+
comment = Some(Self::make_comment(
263263
files,
264264
format_checks_failed,
265265
tidy_checks_failed,

cpp-linter/src/rest_api/github/serde_structs.rs

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ pub struct GithubChangedFile {
4949
pub previous_filename: Option<String>,
5050
/// The individual patch that describes the file's changes.
5151
pub patch: Option<String>,
52+
/// The number of changes to the file contents.
53+
pub changes: i64,
5254
}
5355

5456
/// A structure for deserializing a Push event's changed files.

cpp-linter/src/rest_api/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ pub trait RestApiClient {
230230
/// Returns the markdown comment as a string as well as the total count of
231231
/// `format_checks_failed` and `tidy_checks_failed` (in respective order).
232232
fn make_comment(
233-
&self,
234233
files: &[Arc<Mutex<FileObj>>],
235234
format_checks_failed: u64,
236235
tidy_checks_failed: u64,

cpp-linter/src/run.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,8 @@ pub async fn run_main(args: Vec<String>) -> Result<()> {
147147
.post_feedback(&arc_files, user_inputs, clang_versions)
148148
.await?;
149149
rest_api_client.end_log_group();
150-
if env::var("PRE_COMMIT").is_ok_and(|v| v == "1") {
151-
if checks_failed > 1 {
152-
return Err(anyhow!("Some checks did not pass"));
153-
} else {
154-
return Ok(());
155-
}
150+
if env::var("PRE_COMMIT").is_ok_and(|v| v == "1") && checks_failed > 1 {
151+
return Err(anyhow!("Some checks did not pass"));
156152
}
157153
Ok(())
158154
}

0 commit comments

Comments
 (0)