Skip to content

Commit

Permalink
Include custom clippy settings
Browse files Browse the repository at this point in the history
* All custom clippy settings are now centralized
* add `make fix-clippy` for automated fixes
* Modified some simple cases, e.g. use `_` instead of `true|false` in a match
  • Loading branch information
nyurik committed May 25, 2023
1 parent 042f2e1 commit b057500
Show file tree
Hide file tree
Showing 17 changed files with 63 additions and 54 deletions.
24 changes: 19 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# TODO: consider adding these clippy fixes and/or some other?
# -D clippy::default-trait-access \
# -D clippy::explicit-iter-loop \
# -D clippy::map-unwrap-or \
# -D clippy::range-plus-one \
CLIPPY_FLAGS = \
-D clippy::unnested-or-patterns


help: ## Display this help
@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)
Expand Down Expand Up @@ -51,10 +60,16 @@ doc: ## Run cargo doc on all crates
cargo doc --features=max,lean,small

clippy: ## Run cargo clippy on all crates
cargo clippy --all --tests --examples
cargo clippy --all --no-default-features --features small
cargo clippy --all --no-default-features --features max-pure
cargo clippy --all --no-default-features --features lean-async --tests
cargo clippy --all --tests --examples -- $(CLIPPY_FLAGS)
cargo clippy --all --no-default-features --features small -- $(CLIPPY_FLAGS)
cargo clippy --all --no-default-features --features max-pure -- $(CLIPPY_FLAGS)
cargo clippy --all --no-default-features --features lean-async --tests -- $(CLIPPY_FLAGS)

fix-clippy: ## Run cargo clippy on all crates, fixing what can be fixed
cargo clippy --fix --all --tests --examples -- $(CLIPPY_FLAGS)
cargo clippy --fix --allow-dirty --all --no-default-features --features small -- $(CLIPPY_FLAGS)
cargo clippy --fix --allow-dirty --all --no-default-features --features max-pure -- $(CLIPPY_FLAGS)
cargo clippy --fix --allow-dirty --all --no-default-features --features lean-async --tests -- $(CLIPPY_FLAGS)

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

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

10 changes: 6 additions & 4 deletions cargo-smart-release/src/changelog/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,12 @@ fn track_unknown_event(unknown_event: Event<'_>, unknown: &mut String) {
| Event::Code(text)
| Event::Text(text)
| Event::FootnoteReference(text)
| Event::Start(Tag::FootnoteDefinition(text))
| Event::Start(Tag::CodeBlock(pulldown_cmark::CodeBlockKind::Fenced(text)))
| Event::Start(Tag::Link(_, text, _))
| Event::Start(Tag::Image(_, text, _)) => unknown.push_str(text.as_ref()),
| Event::Start(
Tag::FootnoteDefinition(text)
| Tag::CodeBlock(pulldown_cmark::CodeBlockKind::Fenced(text))
| Tag::Link(_, text, _)
| Tag::Image(_, text, _),
) => unknown.push_str(text.as_ref()),
_ => {}
}
}
Expand Down
4 changes: 2 additions & 2 deletions cargo-smart-release/src/git/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ fn add_item_if_package_changed<'a>(
}
history.push(item)
}
(None, Some(_)) | (None, None) => {}
(None, _) => {}
};
}
Filter::Slow { ref components } => {
Expand All @@ -269,7 +269,7 @@ fn add_item_if_package_changed<'a>(
}
}
(Some(_), None) => history.push(item),
(None, Some(_)) | (None, None) => {}
(None, _) => {}
};
}
};
Expand Down
4 changes: 2 additions & 2 deletions gitoxide-core/src/repository/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ impl Filter {
return false;
}
}
(None, None) | (None, Some(_)) => {}
_ => return false,
(None, _) => {}
(Some(_), None) => return false,
};
true
}
Expand Down
6 changes: 3 additions & 3 deletions gix-credentials/src/program/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ impl TryFrom<OsString> for Action {

fn try_from(value: OsString) -> Result<Self, Self::Error> {
Ok(match value.to_str() {
Some("fill") | Some("get") => Action::Get,
Some("approve") | Some("store") => Action::Store,
Some("reject") | Some("erase") => Action::Erase,
Some("fill" | "get") => Action::Get,
Some("approve" | "store") => Action::Store,
Some("reject" | "erase") => Action::Erase,
_ => return Err(Error::ActionInvalid { name: value }),
})
}
Expand Down
2 changes: 1 addition & 1 deletion gix-discover/src/upwards/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub(crate) mod function {
if dir_made_absolute
|| matches!(
cursor.components().next(),
Some(std::path::Component::RootDir) | Some(std::path::Component::Prefix(_))
Some(std::path::Component::RootDir | std::path::Component::Prefix(_))
)
{
break Err(Error::NoGitRepository { path: dir.into_owned() });
Expand Down
6 changes: 3 additions & 3 deletions gix-features/src/zlib/stream/inflate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ pub fn read(rd: &mut impl BufRead, state: &mut Decompress, mut dst: &mut [u8]) -
// The stream has officially ended, nothing more to do here.
Ok(Status::StreamEnd) => return Ok(total_written),
// Either input our output are depleted even though the stream is not depleted yet.
Ok(Status::Ok) | Ok(Status::BufError) if eof || dst.is_empty() => return Ok(total_written),
Ok(Status::Ok | Status::BufError) if eof || dst.is_empty() => return Ok(total_written),
// Some progress was made in both the input and the output, it must continue to reach the end.
Ok(Status::Ok) | Ok(Status::BufError) if consumed != 0 || written != 0 => continue,
Ok(Status::Ok | Status::BufError) if consumed != 0 || written != 0 => continue,
// A strange state, where zlib makes no progress but isn't done either. Call it out.
Ok(Status::Ok) | Ok(Status::BufError) => unreachable!("Definitely a bug somewhere"),
Ok(Status::Ok | Status::BufError) => unreachable!("Definitely a bug somewhere"),
Err(..) => return Err(io::Error::new(io::ErrorKind::InvalidInput, "corrupt deflate stream")),
}
}
Expand Down
2 changes: 1 addition & 1 deletion gix-object/src/commit/ref_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<'a> CommitRefIter<'a> {
/// Errors are not the common case - if an error needs to be detectable, use this instance as iterator.
pub fn signatures(self) -> impl Iterator<Item = gix_actor::SignatureRef<'a>> + 'a {
self.filter_map(|t| match t {
Ok(Token::Author { signature }) | Ok(Token::Committer { signature }) => Some(signature),
Ok(Token::Author { signature } | Token::Committer { signature }) => Some(signature),
_ => None,
})
}
Expand Down
2 changes: 1 addition & 1 deletion gix-odb/src/store_impls/dynamic/prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ where
fn check_candidate(lookup_result: Option<lookup::Outcome>, candidate: &mut Option<gix_hash::ObjectId>) -> bool {
match (lookup_result, &*candidate) {
(Some(Ok(oid)), Some(candidate)) if *candidate != oid => false,
(Some(Ok(_)), Some(_)) | (None, None) | (None, Some(_)) => true,
(Some(Ok(_)) | None, Some(_)) | (None, None) => true,
(Some(Err(())), _) => false,
(Some(Ok(oid)), None) => {
*candidate = Some(oid);
Expand Down
8 changes: 4 additions & 4 deletions gix-odb/src/store_impls/dynamic/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,16 @@ impl<T: Clone> OnDiskFile<T> {
match std::mem::replace(&mut self.state, OnDiskFileState::Missing) {
OnDiskFileState::Garbage(v) => self.state = OnDiskFileState::Loaded(v),
OnDiskFileState::Missing => self.state = OnDiskFileState::Unloaded,
other @ OnDiskFileState::Loaded(_) | other @ OnDiskFileState::Unloaded => self.state = other,
other @ (OnDiskFileState::Loaded(_) | OnDiskFileState::Unloaded) => self.state = other,
}
}

pub fn trash(&mut self) {
match std::mem::replace(&mut self.state, OnDiskFileState::Missing) {
OnDiskFileState::Loaded(v) => self.state = OnDiskFileState::Garbage(v),
other @ OnDiskFileState::Garbage(_)
| other @ OnDiskFileState::Unloaded
| other @ OnDiskFileState::Missing => self.state = other,
other @ (OnDiskFileState::Garbage(_) | OnDiskFileState::Unloaded | OnDiskFileState::Missing) => {
self.state = other
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gix-path/src/realpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(crate) mod function {
let mut components = path.components();
while let Some(component) = components.next() {
match component {
part @ RootDir | part @ Prefix(_) => real_path.push(part),
part @ (RootDir | Prefix(_)) => real_path.push(part),
CurDir => {}
ParentDir => {
if !real_path.pop() {
Expand Down
23 changes: 12 additions & 11 deletions gix-ref/src/store/file/transaction/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ impl<'s, 'p> Transaction<'s, 'p> {
(PreviousValue::MustNotExist, _) => {
panic!("BUG: MustNotExist constraint makes no sense if references are to be deleted")
}
(PreviousValue::ExistingMustMatch(_), None)
| (PreviousValue::MustExist, Some(_))
| (PreviousValue::Any, Some(_))
| (PreviousValue::Any, None) => {}
(PreviousValue::MustExist, None) | (PreviousValue::MustExistAndMatch(_), None) => {
(PreviousValue::ExistingMustMatch(_) | PreviousValue::Any, None)
| (PreviousValue::MustExist | PreviousValue::Any, Some(_)) => {}
(PreviousValue::MustExist | PreviousValue::MustExistAndMatch(_), None) => {
return Err(Error::DeleteReferenceMustExist {
full_name: change.name(),
})
}
(PreviousValue::MustExistAndMatch(previous), Some(existing))
| (PreviousValue::ExistingMustMatch(previous), Some(existing)) => {
(
PreviousValue::MustExistAndMatch(previous) | PreviousValue::ExistingMustMatch(previous),
Some(existing),
) => {
let actual = existing.target.clone();
if *previous != actual {
let expected = previous.clone();
Expand Down Expand Up @@ -124,8 +124,7 @@ impl<'s, 'p> Transaction<'s, 'p> {
match (&expected, &existing_ref) {
(PreviousValue::Any, _)
| (PreviousValue::MustExist, Some(_))
| (PreviousValue::MustNotExist, None)
| (PreviousValue::ExistingMustMatch(_), None) => {}
| (PreviousValue::MustNotExist | PreviousValue::ExistingMustMatch(_), None) => {}
(PreviousValue::MustExist, None) => {
let expected = Target::Peeled(store.object_hash.null());
let full_name = change.name();
Expand All @@ -141,8 +140,10 @@ impl<'s, 'p> Transaction<'s, 'p> {
});
}
}
(PreviousValue::MustExistAndMatch(previous), Some(existing))
| (PreviousValue::ExistingMustMatch(previous), Some(existing)) => {
(
PreviousValue::MustExistAndMatch(previous) | PreviousValue::ExistingMustMatch(previous),
Some(existing),
) => {
if *previous != existing.target {
let actual = existing.target.clone();
let expected = previous.to_owned();
Expand Down
12 changes: 2 additions & 10 deletions gix-ref/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,11 @@ impl Change {
match self {
// TODO: use or-patterns once MRV is larger than 1.52 (and this is supported)
Change::Update {
expected: PreviousValue::MustExistAndMatch(previous),
..
}
| Change::Update {
expected: PreviousValue::ExistingMustMatch(previous),
..
}
| Change::Delete {
expected: PreviousValue::MustExistAndMatch(previous),
expected: PreviousValue::MustExistAndMatch(previous) | PreviousValue::ExistingMustMatch(previous),
..
}
| Change::Delete {
expected: PreviousValue::ExistingMustMatch(previous),
expected: PreviousValue::MustExistAndMatch(previous) | PreviousValue::ExistingMustMatch(previous),
..
} => previous,
_ => return None,
Expand Down
2 changes: 1 addition & 1 deletion gix-refspec/src/match_group/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<'a> Matcher<'a> {
match (self.lhs, self.rhs) {
(Some(lhs), None) => (lhs.matches(item).is_match(), None),
(Some(lhs), Some(rhs)) => lhs.matches(item).into_match_outcome(rhs, item),
(None, None) | (None, Some(_)) => {
(None, _) => {
unreachable!("For all we know, the lefthand side is never empty. Push specs might change that.")
}
}
Expand Down
2 changes: 1 addition & 1 deletion gix-transport/src/client/blocking_io/http/curl/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ pub fn new() -> (
handler.receive_body.take();
match (handler.send_header.take(), handler.send_data.take()) {
(Some(header), mut data) => {
if let Err(TrySendError::Disconnected(err)) | Err(TrySendError::Full(err)) =
if let Err(TrySendError::Disconnected(err) | TrySendError::Full(err)) =
header.channel.try_send(err)
{
if let Some(body) = data.take() {
Expand Down
2 changes: 1 addition & 1 deletion src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ fn stdin_or_bail() -> Result<std::io::BufReader<std::io::Stdin>> {
fn verify_mode(decode: bool, re_encode: bool) -> verify::Mode {
match (decode, re_encode) {
(true, false) => verify::Mode::HashCrc32Decode,
(true, true) | (false, true) => verify::Mode::HashCrc32DecodeEncode,
(_, true) => verify::Mode::HashCrc32DecodeEncode,
(false, false) => verify::Mode::HashCrc32,
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub mod pretty {
res
}
#[cfg(not(feature = "prodash-render-tui"))]
(true, true) | (false, true) => {
(_, true) => {
unreachable!("BUG: This branch can't be run without a TUI built-in")
}
}
Expand Down Expand Up @@ -134,11 +134,11 @@ pub mod pretty {
res
}
#[cfg(not(feature = "prodash-render-tui"))]
(true, true) | (false, true) => {
(_, true) => {
unreachable!("BUG: This branch can't be run without a TUI built-in")
}
#[cfg(feature = "prodash-render-tui")]
(true, true) | (false, true) => {
(_, true) => {
use std::io::Write;

use crate::shared;
Expand Down

0 comments on commit b057500

Please sign in to comment.