Skip to content

Commit dbf8aa1

Browse files
committed
Merge branch 'auto-clippy'
2 parents d70ce9f + bd101f2 commit dbf8aa1

File tree

83 files changed

+325
-360
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+325
-360
lines changed

Diff for: Makefile

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Rejected for now, and why
2+
# -D clippy::default-trait-access - sometimes makes imports necessary, just for a default value. It's good for more explicit typing though.
3+
# -D clippy::range-plus-one - useful, but caused too many false positives as we use range types directly quite a lot
4+
CLIPPY_FLAGS = \
5+
-D clippy::uninlined_format_args \
6+
-D clippy::unnested-or-patterns \
7+
-D clippy::explicit-iter-loop \
8+
-D clippy::map-unwrap-or
19

210
help: ## Display this help
311
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
@@ -51,10 +59,16 @@ doc: ## Run cargo doc on all crates
5159
RUSTDOCFLAGS="-D warnings" cargo doc --features=max,lean,small --all --no-deps
5260

5361
clippy: ## Run cargo clippy on all crates
54-
cargo clippy --all --tests --examples
55-
cargo clippy --all --no-default-features --features small
56-
cargo clippy --all --no-default-features --features max-pure
57-
cargo clippy --all --no-default-features --features lean-async --tests
62+
cargo clippy --all --tests --examples -- $(CLIPPY_FLAGS)
63+
cargo clippy --all --no-default-features --features small -- $(CLIPPY_FLAGS)
64+
cargo clippy --all --no-default-features --features max-pure -- $(CLIPPY_FLAGS)
65+
cargo clippy --all --no-default-features --features lean-async --tests -- $(CLIPPY_FLAGS)
66+
67+
fix-clippy: ## Run cargo clippy on all crates, fixing what can be fixed
68+
cargo clippy --fix --all --tests --examples -- $(CLIPPY_FLAGS)
69+
cargo clippy --fix --allow-dirty --all --no-default-features --features small -- $(CLIPPY_FLAGS)
70+
cargo clippy --fix --allow-dirty --all --no-default-features --features max-pure -- $(CLIPPY_FLAGS)
71+
cargo clippy --fix --allow-dirty --all --no-default-features --features lean-async --tests -- $(CLIPPY_FLAGS)
5872

5973
check-msrv: ## run cargo msrv to validate the current msrv requirements, similar to what CI does
6074
cd gix && cargo check --package gix --no-default-features --features async-network-client,max-performance
@@ -342,4 +356,3 @@ fmt: ## run nightly rustfmt for its extra features, but check that it won't upse
342356

343357
try-publish-all: ## Dry-run publish all crates in the currently set version if they are not published yet.
344358
(cd cargo-smart-release && cargo build --bin cargo-smart-release) && cargo-smart-release/target/debug/cargo-smart-release smart-release gitoxide
345-

Diff for: cargo-smart-release/src/changelog/parse.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,10 @@ impl ChangeLog {
7979
}),
8080
}
8181

82-
let insert_sorted_at_pos = sections
83-
.first()
84-
.map(|s| match s {
85-
Section::Verbatim { .. } => 1,
86-
Section::Release { .. } => 0,
87-
})
88-
.unwrap_or(0);
82+
let insert_sorted_at_pos = sections.first().map_or(0, |s| match s {
83+
Section::Verbatim { .. } => 1,
84+
Section::Release { .. } => 0,
85+
});
8986
let mut non_release_sections = Vec::new();
9087
let mut release_sections = Vec::new();
9188
for section in sections {
@@ -362,7 +359,7 @@ fn parse_id_fallback_to_user_message(
362359
.messages
363360
.push(section::segment::conventional::Message::Generated {
364361
id,
365-
title: lines.next().map(|l| l.trim()).unwrap_or("").to_owned(),
362+
title: lines.next().map_or("", |l| l.trim()).to_owned(),
366363
body: lines
367364
.map(|l| {
368365
match l
@@ -437,10 +434,12 @@ fn track_unknown_event(unknown_event: Event<'_>, unknown: &mut String) {
437434
| Event::Code(text)
438435
| Event::Text(text)
439436
| Event::FootnoteReference(text)
440-
| Event::Start(Tag::FootnoteDefinition(text))
441-
| Event::Start(Tag::CodeBlock(pulldown_cmark::CodeBlockKind::Fenced(text)))
442-
| Event::Start(Tag::Link(_, text, _))
443-
| Event::Start(Tag::Image(_, text, _)) => unknown.push_str(text.as_ref()),
437+
| Event::Start(
438+
Tag::FootnoteDefinition(text)
439+
| Tag::CodeBlock(pulldown_cmark::CodeBlockKind::Fenced(text))
440+
| Tag::Link(_, text, _)
441+
| Tag::Image(_, text, _),
442+
) => unknown.push_str(text.as_ref()),
444443
_ => {}
445444
}
446445
}
@@ -518,7 +517,7 @@ fn headline<'a, E: ParseError<&'a str> + FromExternalError<&'a str, ()>>(i: &'a
518517
),
519518
|((hashes, (prefix, version)), date)| Headline {
520519
level: hashes.len(),
521-
version_prefix: prefix.map(ToOwned::to_owned).unwrap_or_else(String::new),
520+
version_prefix: prefix.map_or_else(String::new, ToOwned::to_owned),
522521
version,
523522
date,
524523
},

Diff for: cargo-smart-release/src/changelog/section/from_history.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,17 @@ impl Section {
130130
}
131131
}
132132

133-
let version = crate::git::try_strip_tag_path(segment.head.name.as_ref())
134-
.map(|tag_name| {
133+
let version = crate::git::try_strip_tag_path(segment.head.name.as_ref()).map_or_else(
134+
|| changelog::Version::Unreleased,
135+
|tag_name| {
135136
let package_name =
136137
(!is_top_level_package(&package.manifest_path, repo)).then_some(package.name.as_str());
137138
changelog::Version::Semantic(
138139
utils::parse_possibly_prefixed_tag_version(package_name, tag_name)
139140
.expect("here we always have a valid version as it passed a filter when creating it"),
140141
)
141-
})
142-
.unwrap_or_else(|| changelog::Version::Unreleased);
142+
},
143+
);
143144
let date = match version {
144145
changelog::Version::Unreleased => None,
145146
changelog::Version::Semantic(_) => Some(date_time),

Diff for: cargo-smart-release/src/changelog/write.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ impl From<gix::Url> for RepositoryUrl {
5151

5252
impl RepositoryUrl {
5353
pub fn is_github(&self) -> bool {
54-
self.inner.host().map(|h| h == "github.com").unwrap_or(false)
54+
self.inner.host().map_or(false, |h| h == "github.com")
5555
}
5656

5757
fn cleaned_path(&self) -> String {
5858
let path = self.inner.path.to_str_lossy().into_owned();
59+
#[allow(clippy::map_unwrap_or)]
5960
let path = path.strip_suffix(".git").map(ToOwned::to_owned).unwrap_or(path);
6061
if !path.starts_with('/') {
6162
format!("/{path}")

Diff for: cargo-smart-release/src/command/changelog.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,9 @@ pub fn changelog(opts: Options, crates: Vec<String>) -> anyhow::Result<()> {
6666
let linkables = if dry_run || no_links {
6767
Linkables::AsText
6868
} else {
69-
crate::git::remote_url(&ctx.repo)?
70-
.map(|url| Linkables::AsLinks {
71-
repository_url: url.into(),
72-
})
73-
.unwrap_or(Linkables::AsText)
69+
git::remote_url(&ctx.repo)?.map_or(Linkables::AsText, |url| Linkables::AsLinks {
70+
repository_url: url.into(),
71+
})
7472
};
7573
let mut num_crates = 0;
7674
for (idx, package) in crates.iter().enumerate() {

Diff for: cargo-smart-release/src/command/release/manifest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ fn gather_changelog_data<'meta>(
485485
capitalize_commit,
486486
)?;
487487
lock.with_mut(|file| file.write_all(write_buf.as_bytes()))?;
488-
*made_change |= previous_content.map(|previous| write_buf != previous).unwrap_or(true);
488+
*made_change |= previous_content.map_or(true, |previous| write_buf != previous);
489489
pending_changelogs.push((publishee, log_init_state.is_modified(), lock));
490490
release_section_by_publishee.insert(publishee.name.as_str(), log.take_recent_release_section());
491491
}
@@ -534,7 +534,7 @@ fn set_version_and_update_package_dependency(
534534
let force_update = conservative_pre_release_version_handling
535535
&& version::is_pre_release(new_version) // setting the lower bound unnecessarily can be harmful
536536
// don't claim to be conservative if this is necessary anyway
537-
&& req_as_version(&version_req).map(|req_version|!version::rhs_is_breaking_bump_for_lhs(&req_version, new_version)).unwrap_or(false);
537+
&& req_as_version(&version_req).map_or(false, |req_version|!version::rhs_is_breaking_bump_for_lhs(&req_version, new_version));
538538
if !version_req.matches(new_version) || force_update {
539539
if !version_req_unset_or_default(&version_req) {
540540
bail!(

Diff for: cargo-smart-release/src/command/release/mod.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ impl Context {
3636
) -> anyhow::Result<Self> {
3737
let base = crate::Context::new(crate_names, changelog, bump, bump_dependencies)?;
3838
let changelog_links = if changelog_links {
39-
crate::git::remote_url(&base.repo)?
40-
.map(|url| Linkables::AsLinks {
41-
repository_url: url.into(),
42-
})
43-
.unwrap_or(Linkables::AsText)
39+
crate::git::remote_url(&base.repo)?.map_or(Linkables::AsText, |url| Linkables::AsLinks {
40+
repository_url: url.into(),
41+
})
4442
} else {
4543
Linkables::AsText
4644
};
@@ -281,10 +279,10 @@ fn present_and_validate_dependencies(
281279
kind,
282280
dep.package.name,
283281
dep.package.version,
284-
bump.latest_release
285-
.as_ref()
286-
.map(|latest_release| format!(" to succeed latest released version {latest_release}"))
287-
.unwrap_or_else(|| ", creating a new release 🎉".into()),
282+
bump.latest_release.as_ref().map_or_else(
283+
|| ", creating a new release 🎉".into(),
284+
|latest_release| format!(" to succeed latest released version {latest_release}")
285+
),
288286
bump.desired_release
289287
);
290288
};
@@ -455,7 +453,7 @@ fn perform_release(ctx: &Context, options: Options, crates: &[Dependency<'_>]) -
455453
}
456454
}
457455

458-
publish_err.map(Err).unwrap_or(Ok(()))
456+
publish_err.map_or(Ok(()), Err)
459457
}
460458

461459
fn wait_for_release(

Diff for: cargo-smart-release/src/commit/message.rs

+15-17
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ mod additions {
2525
.or_else(|| part_to_left[p..].chars().next().map(|c| p + c.len_utf8()))
2626
})
2727
.unwrap_or(start);
28-
let new_end = s[end..]
29-
.find(|c: char| !c.is_whitespace())
30-
.map(|p| p + end)
31-
.unwrap_or(end);
28+
let new_end = s[end..].find(|c: char| !c.is_whitespace()).map_or(end, |p| p + end);
3229
s.replace_range(
3330
new_start..new_end,
3431
if new_end != end && new_start != start { " " } else { "" },
@@ -84,18 +81,8 @@ mod additions {
8481

8582
impl From<&'_ str> for Message {
8683
fn from(m: &str) -> Self {
87-
let (title, kind, body, breaking, breaking_description) = git_conventional::Commit::parse(m)
88-
.map(|c: git_conventional::Commit<'_>| {
89-
(
90-
c.description().into(),
91-
Some(c.type_()),
92-
c.body().map(Into::into),
93-
c.breaking(),
94-
c.breaking_description()
95-
.and_then(|d| if d == c.description() { None } else { Some(d) }),
96-
)
97-
})
98-
.unwrap_or_else(|_| {
84+
let (title, kind, body, breaking, breaking_description) = git_conventional::Commit::parse(m).map_or_else(
85+
|_| {
9986
let m = gix::objs::commit::MessageRef::from_bytes(m.as_bytes());
10087
(
10188
m.summary().as_ref().to_string().into(),
@@ -104,7 +91,18 @@ impl From<&'_ str> for Message {
10491
false,
10592
None,
10693
)
107-
});
94+
},
95+
|c: git_conventional::Commit<'_>| {
96+
(
97+
c.description().into(),
98+
Some(c.type_()),
99+
c.body().map(Into::into),
100+
c.breaking(),
101+
c.breaking_description()
102+
.and_then(|d| if d == c.description() { None } else { Some(d) }),
103+
)
104+
},
105+
);
108106
let (title, additions) = additions::strip(title);
109107
Message {
110108
title: title.into_owned(),

Diff for: cargo-smart-release/src/context.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ fn fill_in_root_crate_if_needed(crate_names: Vec<String>) -> anyhow::Result<Vec<
7777
.to_str()
7878
.expect("directory is UTF8 representable");
7979
let crate_name = if manifest.is_file() {
80-
cargo_toml::Manifest::from_path(manifest)
81-
.map(|manifest| manifest.package.map_or(dir_name.to_owned(), |p| p.name))
82-
.unwrap_or_else(|_| dir_name.to_owned())
80+
cargo_toml::Manifest::from_path(manifest).map_or_else(
81+
|_| dir_name.to_owned(),
82+
|manifest| manifest.package.map_or(dir_name.to_owned(), |p| p.name),
83+
)
8384
} else {
8485
dir_name.to_owned()
8586
};

Diff for: cargo-smart-release/src/git/history.rs

+19-18
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,8 @@ pub fn crate_ref_segments<'h>(
132132
};
133133

134134
let dir = ctx.repo_relative_path(package);
135-
let mut filter = dir
136-
.map(|dir| {
137-
let mut components = dir.components().collect::<Vec<_>>();
138-
match components.len() {
139-
0 => unreachable!("BUG: it's None if empty"),
140-
1 => Filter::Fast {
141-
name: components.pop().map(component_to_bytes).expect("exactly one").into(),
142-
},
143-
_ => Filter::Slow {
144-
components: components.into_iter().map(component_to_bytes).collect(),
145-
},
146-
}
147-
})
148-
.unwrap_or_else(|| {
135+
let mut filter = dir.map_or_else(
136+
|| {
149137
if ctx.meta.workspace_members.len() == 1 {
150138
Filter::None
151139
} else {
@@ -158,9 +146,22 @@ pub fn crate_ref_segments<'h>(
158146
name: Cow::Borrowed(b"src"),
159147
}
160148
}
161-
});
149+
},
150+
|dir| {
151+
let mut components = dir.components().collect::<Vec<_>>();
152+
match components.len() {
153+
0 => unreachable!("BUG: it's None if empty"),
154+
1 => Filter::Fast {
155+
name: components.pop().map(component_to_bytes).expect("exactly one").into(),
156+
},
157+
_ => Filter::Slow {
158+
components: components.into_iter().map(component_to_bytes).collect(),
159+
},
160+
}
161+
},
162+
);
162163

163-
for item in history.items.iter() {
164+
for item in &history.items {
164165
match tags_by_commit.remove(&item.id) {
165166
None => add_item_if_package_changed(ctx, &mut segment, &mut filter, item, &history.data_by_tree_id)?,
166167
Some(next_ref) => {
@@ -249,7 +250,7 @@ fn add_item_if_package_changed<'a>(
249250
}
250251
history.push(item)
251252
}
252-
(None, Some(_)) | (None, None) => {}
253+
(None, _) => {}
253254
};
254255
}
255256
Filter::Slow { ref components } => {
@@ -269,7 +270,7 @@ fn add_item_if_package_changed<'a>(
269270
}
270271
}
271272
(Some(_), None) => history.push(item),
272-
(None, Some(_)) | (None, None) => {}
273+
(None, _) => {}
273274
};
274275
}
275276
};

Diff for: cargo-smart-release/src/utils.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ pub fn is_top_level_package(manifest_path: &Utf8Path, repo: &gix::Repository) ->
6060
}
6161

6262
pub fn version_req_unset_or_default(req: &VersionReq) -> bool {
63-
req.comparators
64-
.last()
65-
.map(|comp| comp.op == semver::Op::Caret)
66-
.unwrap_or(true)
63+
req.comparators.last().map_or(true, |comp| comp.op == semver::Op::Caret)
6764
}
6865

6966
pub fn package_eq_dependency_ignore_dev_without_version(package: &Package, dependency: &Dependency) -> bool {

Diff for: cargo-smart-release/src/version.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub(crate) fn bump_package_with_spec(
116116
} else if unreleased
117117
.history
118118
.iter()
119-
.any(|item| item.message.kind.map(|kind| kind == "feat").unwrap_or(false))
119+
.any(|item| item.message.kind.map_or(false, |kind| kind == "feat"))
120120
{
121121
let is_breaking = if is_pre_release(&v) {
122122
bump_major_minor_patch(&mut v, Patch)

Diff for: gitoxide-core/src/hours/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ where
412412
.expect("at least one commit at this point");
413413
if show_pii {
414414
results_by_hours.sort_by(|a, b| a.hours.partial_cmp(&b.hours).unwrap_or(std::cmp::Ordering::Equal));
415-
for entry in results_by_hours.iter() {
415+
for entry in &results_by_hours {
416416
entry.write_to(
417417
total_hours,
418418
file_stats.then_some(total_files),

Diff for: gitoxide-core/src/pack/explode.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub fn pack_or_pack_index(
157157
)
158158
})?;
159159

160-
if !object_path.as_ref().map(|p| p.as_ref().is_dir()).unwrap_or(true) {
160+
if !object_path.as_ref().map_or(true, |p| p.as_ref().is_dir()) {
161161
return Err(anyhow!(
162162
"The object directory at '{}' is inaccessible",
163163
object_path
@@ -167,16 +167,16 @@ pub fn pack_or_pack_index(
167167
));
168168
}
169169

170-
let algorithm = object_path
171-
.as_ref()
172-
.map(|_| pack::index::traverse::Algorithm::Lookup)
173-
.unwrap_or_else(|| {
170+
let algorithm = object_path.as_ref().map_or_else(
171+
|| {
174172
if sink_compress {
175173
pack::index::traverse::Algorithm::Lookup
176174
} else {
177175
pack::index::traverse::Algorithm::DeltaTreeLookup
178176
}
179-
});
177+
},
178+
|_| pack::index::traverse::Algorithm::Lookup,
179+
);
180180

181181
let pack::index::traverse::Outcome { progress, .. } = bundle
182182
.index

0 commit comments

Comments
 (0)