Skip to content

Commit 49e605f

Browse files
authored
Fix a bunch of clippy warnings (#7)
1 parent 6a21875 commit 49e605f

File tree

10 files changed

+41
-36
lines changed

10 files changed

+41
-36
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,9 @@ tower-sessions = "0.14.0"
4949
tracing = "0.1.41"
5050
tracing-subscriber = "0.3.19"
5151
uuid = { version = "1.17.0", features = ["serde", "v4"] }
52+
53+
[lints.clippy]
54+
# foo.clone() feels more clear than *foo for copying.
55+
clone_on_copy = "allow"
56+
# Because only idents not expressions are allowed inline, sometimes switching between the two leaves reasonable code Clippy dislikes.
57+
uninlined_format_args = "allow"

src/auth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub async fn handle_google_oauth_callback(
110110
let mut client = Client::new(
111111
server_state.config.google_apis_client_id.clone(),
112112
(*server_state.config.google_apis_client_secret).clone(),
113-
String::from(redirect_uri),
113+
redirect_uri,
114114
String::new(),
115115
String::new(),
116116
);

src/bin/pr-metadata-validator.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ async fn main() {
7272
}
7373
}
7474

75-
const COULD_NOT_MATCH_COMMENT: &'static str = r#"Your PR couldn't be matched to an assignment in this module.
75+
const COULD_NOT_MATCH_COMMENT: &str = r#"Your PR couldn't be matched to an assignment in this module.
7676
7777
Please check its title is in the correct format, and that you only have one PR per assignment.
7878
7979
If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed)."#;
8080

81-
const BAD_TITLE_COMMENT_PREFIX: &'static str = r#"Your PR's title isn't in the expected format.
81+
const BAD_TITLE_COMMENT_PREFIX: &str = r#"Your PR's title isn't in the expected format.
8282
8383
Please check its title is in the correct format, and update it.
8484
@@ -98,11 +98,11 @@ async fn validate_pr(
9898
pr_number: u64,
9999
) -> Result<ValidationResult, Error> {
100100
let course = course_schedule
101-
.with_assignments(&octocrab, github_org_name)
101+
.with_assignments(octocrab, github_org_name)
102102
.await
103103
.map_err(|err| err.context("Failed to get assignments"))?;
104104

105-
let module_prs = get_prs(&octocrab, github_org_name, module_name, false)
105+
let module_prs = get_prs(octocrab, github_org_name, module_name, false)
106106
.await
107107
.map_err(|err| err.context("Failed to get PRs"))?;
108108
let pr_in_question = module_prs

src/config.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ pub struct Config {
2121
/// Courses being tracked. Keys are things like "itp" or "sdc".
2222
/// Ideally this would be less hard-coded.
2323
/// Possible sources of truth for this are:
24+
///
2425
/// * GitHub team structure (except that lacks dates)
2526
/// * Class Planner API (except that has fiddly auth)
27+
///
2628
/// We assume the following GitHub team structure:
2729
/// ${course}-trainees contains groups of batches of trainees.
2830
/// ${course}-mentors is a group of reviewers.
@@ -56,15 +58,13 @@ impl Config {
5658
batch: &str,
5759
) -> Option<CourseScheduleWithRegisterSheetId> {
5860
if let Some(course_info) = self.courses.get(&course_name) {
59-
if let Some(course_schedule) = course_info.batches.get(batch) {
60-
Some(CourseScheduleWithRegisterSheetId {
61+
course_info.batches.get(batch).map(|course_schedule| {
62+
CourseScheduleWithRegisterSheetId {
6163
name: course_name,
6264
course_schedule: course_schedule.clone(),
6365
register_sheet_id: course_info.register_sheet_id.clone(),
64-
})
65-
} else {
66-
None
67-
}
66+
}
67+
})
6868
} else {
6969
None
7070
}

src/course.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl CourseScheduleWithRegisterSheetId {
4646
module_name.clone(),
4747
Module {
4848
sprints: module_sprint_dates
49-
.into_iter()
49+
.iter()
5050
.map(|class_dates| Sprint {
5151
assignments: vec![Assignment::Attendance {
5252
class_dates: class_dates.clone(),
@@ -108,7 +108,7 @@ impl CourseScheduleWithRegisterSheetId {
108108
.await
109109
.map_err(|err| err.context("Failed to fetch module issues"))?;
110110

111-
issues.sort_by_cached_key(|&Issue { ref title, .. }| title.clone());
111+
issues.sort_by_cached_key(|Issue { title, .. }| title.clone());
112112

113113
for issue in issues {
114114
if let Some((sprint_number, assignment)) = parse_issue(&issue)? {
@@ -201,7 +201,7 @@ fn parse_issue(issue: &Issue) -> Result<Option<(NonZeroUsize, Option<Assignment>
201201
})?;
202202
// TODO
203203
// let assignment = assignment.ok_or_else(|| Error::UserFacing(format!("Failed to parse issue {} - no submit label", html_url)))?;
204-
let assignment = assignment.or_else(|| Some(None)).unwrap();
204+
let assignment = assignment.unwrap_or(None);
205205
Ok(Some((sprint, assignment)))
206206
}
207207

@@ -303,7 +303,7 @@ impl Batch {
303303
let count = region_counts
304304
.entry(trainee.trainee.region.clone())
305305
.or_default();
306-
*count = *count + 1;
306+
*count += 1;
307307
}
308308
let mut region_counts = region_counts.into_iter().collect::<Vec<_>>();
309309
region_counts.sort_by_key(|(_region, count)| *count);
@@ -485,10 +485,10 @@ pub enum Attendance {
485485
impl Attendance {
486486
pub fn register_url(&self) -> &str {
487487
match self {
488-
Attendance::Absent { register_url } => &register_url,
489-
Attendance::OnTime { register_url } => &register_url,
490-
Attendance::Late { register_url } => &register_url,
491-
Attendance::WrongDay { register_url } => &register_url,
488+
Attendance::Absent { register_url } => register_url,
489+
Attendance::OnTime { register_url } => register_url,
490+
Attendance::Late { register_url } => register_url,
491+
Attendance::WrongDay { register_url } => register_url,
492492
}
493493
}
494494
}
@@ -506,7 +506,7 @@ pub(crate) async fn fetch_batch_metadata(
506506
let teams = all_pages("teams", octocrab, async || {
507507
octocrab
508508
.teams(github_org)
509-
.list_children(&format!("{}-trainees", course_name))
509+
.list_children(format!("{}-trainees", course_name))
510510
.send()
511511
.await
512512
})
@@ -642,11 +642,11 @@ pub async fn get_batch_with_submissions(
642642
&register_info,
643643
module_name,
644644
trainee_email.clone(),
645-
&course,
645+
course,
646646
&region,
647647
)?;
648648
let module_with_submissions = match_prs_to_assignments(
649-
&module,
649+
module,
650650
module_to_prs[&module_name].clone(),
651651
module_attendance,
652652
&region,
@@ -793,6 +793,8 @@ pub fn match_prs_to_assignments(
793793
}
794794
}
795795

796+
let number_regex = Regex::new(r"(\d+)").unwrap();
797+
796798
let mut unknown_prs = Vec::new();
797799
for pr in prs {
798800
let title_lower = pr.title.to_lowercase();
@@ -803,7 +805,6 @@ pub fn match_prs_to_assignments(
803805
let mut sprint_index = None;
804806
for title_part in title_parts {
805807
if title_part.starts_with("sprint") || title_part.starts_with("week") {
806-
let number_regex = Regex::new(r"(\d+)").unwrap();
807808
if let Some(number_match) = number_regex
808809
.captures(title_part)
809810
.and_then(|captures| captures.get(1))
@@ -837,8 +838,8 @@ pub fn match_prs_to_assignments(
837838
fn match_pr_to_assignment(
838839
pr: Pr,
839840
claimed_sprint_index: Option<usize>,
840-
assignments: &Vec<Sprint>,
841-
submissions: &mut Vec<SprintWithSubmissions>,
841+
assignments: &[Sprint],
842+
submissions: &mut [SprintWithSubmissions],
842843
unknown_prs: &mut Vec<Pr>,
843844
) {
844845
#[derive(Clone, Copy)]
@@ -902,10 +903,8 @@ fn match_pr_to_assignment(
902903
{
903904
submissions[sprint_index].submissions[assignment_index] =
904905
SubmissionState::Some(Submission::PullRequest { pull_request: pr });
905-
} else {
906-
if !pr.is_closed {
907-
unknown_prs.push(pr);
908-
}
906+
} else if !pr.is_closed {
907+
unknown_prs.push(pr);
909908
}
910909
}
911910

src/frontend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub async fn list_courses(
3838
let batch_metadata = join_all(
3939
courses
4040
.keys()
41-
.map(|course_name| fetch_batch_metadata(&octocrab, github_org.clone(), &course_name)),
41+
.map(|course_name| fetch_batch_metadata(&octocrab, github_org.clone(), course_name)),
4242
)
4343
.await
4444
.into_iter()

src/google_groups.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ pub(crate) async fn get_groups(client: &Client) -> Result<GoogleGroups, Error> {
104104
members: members
105105
.into_iter()
106106
.map(|Member { email, .. }| {
107-
Ok(EmailAddress::from_str(&email).with_context(|| {
107+
EmailAddress::from_str(&email).with_context(|| {
108108
format!(
109109
"Failed to parse group member email address {} (member of {})",
110110
email, group.email
111111
)
112-
})?)
112+
})
113113
})
114114
.collect::<Result<_, anyhow::Error>>()?,
115115
})

src/register.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ fn read_module(
126126
let cells = row.values;
127127
// Some sheets have documentation or pivot table
128128
if row_number == 0
129-
&& cells.len() >= 1
129+
&& !cells.is_empty()
130130
&& cell_string(&cells[0]).unwrap_or_default() != "Name"
131131
{
132132
continue 'sheet;
@@ -150,7 +150,7 @@ fn read_module(
150150
})
151151
.collect::<Result<Vec<_>, _>>()?;
152152
if headings
153-
!= &[
153+
!= [
154154
"Name",
155155
"Email",
156156
"Timestamp",

src/reviewer_staff_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn reviewer_staff_detail_from_sheet(
7575
);
7676

7777
let notes = match cells.get(6) {
78-
Some(cell) => cell_string(&cell).context("Failed to read reviewer notes")?,
78+
Some(cell) => cell_string(cell).context("Failed to read reviewer notes")?,
7979
None => String::new(),
8080
};
8181

src/sheets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl SheetsClient {
9090
make_redirect_uri(
9191
&self.server_state,
9292
self.original_uri,
93-
&&redirect_endpoint(&self.server_state),
93+
&redirect_endpoint(&self.server_state),
9494
GoogleScope::Sheets,
9595
)
9696
.await?,

0 commit comments

Comments
 (0)