Skip to content

Commit

Permalink
Fixes a lot of clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
hoijui committed Nov 2, 2023
1 parent 4f64e3a commit ab2b217
Show file tree
Hide file tree
Showing 25 changed files with 118 additions and 104 deletions.
8 changes: 4 additions & 4 deletions src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ pub struct Environment {

impl Environment {
#[must_use]
pub fn new(settings: Settings) -> Environment {
pub fn new(settings: Settings) -> Self {
let vars = HashMap::<String, String>::new();
let output = Storage::new();
let repo = git::Repo::try_from(settings.repo_path.as_deref()).ok();
Environment {
Self {
settings,
vars,
output,
Expand All @@ -33,12 +33,12 @@ impl Environment {
}

#[must_use]
pub fn stub() -> Environment {
pub fn stub() -> Self {
Self::new(STUB.clone())
}

#[must_use]
pub fn repo(&self) -> Option<&git::Repo> {
pub const fn repo(&self) -> Option<&git::Repo> {
// TODO DEPRECATED Just use the repo property directly, instead
self.repo.as_ref()
}
Expand Down
2 changes: 1 addition & 1 deletion src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use tracing_subscriber::{
Registry,
};

fn verbosity_to_level(verbosity: Verbosity) -> LevelFilter {
const fn verbosity_to_level(verbosity: Verbosity) -> LevelFilter {
match verbosity {
Verbosity::None => LevelFilter::OFF,
Verbosity::Errors => LevelFilter::ERROR,
Expand Down
6 changes: 3 additions & 3 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ pub fn run(
) -> BoxResult<()> {
sources.sort_unstable_by(|s1, s2| {
let o_hierarchy = s1.hierarchy().cmp(&s2.hierarchy());
if let Ordering::Equal = o_hierarchy {
if Ordering::Equal == o_hierarchy {
let o_type = s1.type_name().cmp(s2.type_name());
if let Ordering::Equal = o_type {
if Ordering::Equal == o_type {
let o_props = s1.properties().cmp(s2.properties());
o_props
} else {
Expand Down Expand Up @@ -106,7 +106,7 @@ pub fn run(
None => {
if required {
log::warn!("Missing value for required key '{:?}'", key);
if let FailOn::AnyMissingValue = environment.settings.fail_on {
if matches!(environment.settings.fail_on, FailOn::AnyMissingValue) {
return Err(validator::Error::Missing.into()); // TODO Should/could this be handled in the validator already?
}
} else {
Expand Down
33 changes: 17 additions & 16 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::{
EnumIter,
IntoStaticStr,
PartialEq,
Eq,
PartialOrd,
Copy,
Clone,
Expand All @@ -47,7 +48,7 @@ lazy_static! {
}

impl Verbosity {
fn index(self) -> usize {
const fn index(self) -> usize {
self as usize
}

Expand All @@ -71,9 +72,9 @@ impl Verbosity {
impl From<bool> for Verbosity {
fn from(verbose: bool) -> Self {
if verbose {
Verbosity::Info
Self::Info
} else {
Verbosity::Warnings
Self::Warnings
}
}
}
Expand All @@ -88,18 +89,18 @@ pub enum Overwrite {

impl Overwrite {
#[must_use]
pub fn main(&self) -> bool {
pub const fn main(&self) -> bool {
match self {
Overwrite::All | Overwrite::Main => true,
Overwrite::None | Overwrite::Alternative => false,
Self::All | Self::Main => true,
Self::None | Self::Alternative => false,
}
}

#[must_use]
pub fn alt(&self) -> bool {
pub const fn alt(&self) -> bool {
match self {
Overwrite::All | Overwrite::Alternative => true,
Overwrite::None | Overwrite::Main => false,
Self::All | Self::Alternative => true,
Self::None | Self::Main => false,
}
}
}
Expand All @@ -123,9 +124,9 @@ pub enum FailOn {
impl From<bool> for FailOn {
fn from(verbose: bool) -> Self {
if verbose {
FailOn::AnyMissingValue
Self::AnyMissingValue
} else {
FailOn::Error
Self::Error
}
}
}
Expand Down Expand Up @@ -156,10 +157,10 @@ pub struct Settings /*<S: ::std::hash::BuildHasher>*/ {
}

impl Settings {
fn stub() -> Settings {
fn stub() -> Self {
let mut all_keys = HashSet::<Key>::new();
all_keys.extend(Key::iter());
Settings {
Self {
repo_path: None,
required_keys: all_keys,
overwrite: Overwrite::All,
Expand All @@ -178,7 +179,7 @@ impl Settings {
/// from the given (possible) repo hosting URL (any form of it).
#[must_use]
pub fn hosting_type(&self, url: &Url) -> HostingType {
if let HostingType::Unknown = self.hosting_type {
if HostingType::Unknown == self.hosting_type {
HostingType::from(PublicSite::from(url.host()))
} else {
self.hosting_type
Expand All @@ -187,7 +188,7 @@ impl Settings {

#[must_use]
pub fn hosting_type_from_host(&self, host: &str) -> HostingType {
if let HostingType::Unknown = self.hosting_type {
if HostingType::Unknown == self.hosting_type {
let host_assumed_domain = url::Host::Domain(host);
HostingType::from(PublicSite::from(host_assumed_domain))
} else {
Expand All @@ -197,7 +198,7 @@ impl Settings {

#[must_use]
pub fn hosting_type_from_hosting_suffix(&self, url: &Url) -> HostingType {
if let HostingType::Unknown = self.hosting_type {
if HostingType::Unknown == self.hosting_type {
HostingType::from(PublicSite::from_hosting_domain_option(url.host().as_ref()))
} else {
self.hosting_type
Expand Down
2 changes: 1 addition & 1 deletion src/sinks/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ impl super::VarSink for VarSink {

impl fmt::Display for VarSink {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", std::any::type_name::<VarSink>())
write!(f, "{}", std::any::type_name::<Self>())
}
}
2 changes: 1 addition & 1 deletion src/sinks/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl fmt::Display for VarSink {
write!(
f,
"{}(file: {})",
std::any::type_name::<VarSink>(),
std::any::type_name::<Self>(),
self.file.as_path().to_str().ok_or(fmt::Error {})?
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/sinks/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl fmt::Display for VarSink {
write!(
f,
"{}(file: {})",
std::any::type_name::<VarSink>(),
std::any::type_name::<Self>(),
self.file.as_path().to_str().ok_or(fmt::Error {})?
)
}
Expand Down
7 changes: 4 additions & 3 deletions src/sinks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ pub fn cli_list(
sinks.clear();
} else if sinks.is_empty() {
log::warn!("No sinks registered! The results of this run will not be stored anywhere.");
}
for sink in &sinks {
log::trace!("Registered sink {}.", sink);
} else {
for sink in &sinks {
log::trace!("Registered sink {}.", sink);
}
}
sinks
}
2 changes: 1 addition & 1 deletion src/sources/bitbucket_ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl super::VarSource for VarSource {
}

fn type_name(&self) -> &'static str {
std::any::type_name::<VarSource>()
std::any::type_name::<Self>()
}

fn properties(&self) -> &Vec<String> {
Expand Down
2 changes: 1 addition & 1 deletion src/sources/deriver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl super::VarSource for VarSource {
}

fn type_name(&self) -> &'static str {
std::any::type_name::<VarSource>()
std::any::type_name::<Self>()
}

fn properties(&self) -> &Vec<String> {
Expand Down
2 changes: 1 addition & 1 deletion src/sources/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl super::VarSource for VarSource {
}

fn type_name(&self) -> &'static str {
std::any::type_name::<VarSource>()
std::any::type_name::<Self>()
}

fn properties(&self) -> &Vec<String> {
Expand Down
4 changes: 2 additions & 2 deletions src/sources/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::cleanup;
use crate::environment::Environment;
use crate::license;
use crate::std_error;
use crate::var::{Confidence, Key, C_HIGH, C_LOW, C_MIDDLE};
use crate::var::{Confidence, Key, C_HIGH, C_LOW};
use std::path::{Path, PathBuf};
use std::{env, fs};

Expand Down Expand Up @@ -167,7 +167,7 @@ impl super::VarSource for VarSource {
}

fn type_name(&self) -> &'static str {
std::any::type_name::<VarSource>()
std::any::type_name::<Self>()
}

fn properties(&self) -> &Vec<String> {
Expand Down
2 changes: 1 addition & 1 deletion src/sources/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl super::VarSource for VarSource {
}

fn type_name(&self) -> &'static str {
std::any::type_name::<VarSource>()
std::any::type_name::<Self>()
}

fn properties(&self) -> &Vec<String> {
Expand Down
2 changes: 1 addition & 1 deletion src/sources/github_ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl super::VarSource for VarSource {
}

fn type_name(&self) -> &'static str {
std::any::type_name::<VarSource>()
std::any::type_name::<Self>()
}

fn properties(&self) -> &Vec<String> {
Expand Down
2 changes: 1 addition & 1 deletion src/sources/gitlab_ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl super::VarSource for VarSource {
}

fn type_name(&self) -> &'static str {
std::any::type_name::<VarSource>()
std::any::type_name::<Self>()
}

fn properties(&self) -> &Vec<String> {
Expand Down
2 changes: 1 addition & 1 deletion src/sources/jenkins_ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl super::VarSource for VarSource {
}

fn type_name(&self) -> &'static str {
std::any::type_name::<VarSource>()
std::any::type_name::<Self>()
}

fn properties(&self) -> &Vec<String> {
Expand Down
2 changes: 1 addition & 1 deletion src/sources/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl super::VarSource for VarSource {
}

fn type_name(&self) -> &'static str {
std::any::type_name::<VarSource>()
std::any::type_name::<Self>()
}

fn properties(&self) -> &Vec<String> {
Expand Down
2 changes: 1 addition & 1 deletion src/sources/travis_ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl super::VarSource for VarSource {
}

fn type_name(&self) -> &'static str {
std::any::type_name::<VarSource>()
std::any::type_name::<Self>()
}

fn properties(&self) -> &Vec<String> {
Expand Down
4 changes: 2 additions & 2 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ macro_rules! quote_empty {

impl Storage {
/// Creates a new, empty instance of a storage.
pub fn new() -> Storage {
Storage {
pub fn new() -> Self {
Self {
key_values: HashMap::new(),
key_primary: HashMap::new(),
}
Expand Down
12 changes: 7 additions & 5 deletions src/tools/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct Error {

impl From<&str> for Error {
fn from(message: &str) -> Self {
Error {
Self {
from: git2::Error::from_str("PLACEHOLDER"),
message: String::from(message),
}
Expand Down Expand Up @@ -67,6 +67,7 @@ pub enum TransferProtocol {
}

impl TransferProtocol {
#[must_use]
pub const fn scheme_str(self) -> &'static str {
match self {
Self::Git => "git",
Expand All @@ -75,6 +76,7 @@ impl TransferProtocol {
}
}

#[must_use]
pub const fn to_clone_url_key(self) -> Key {
match self {
Self::Git => Key::RepoCloneUrlGit,
Expand Down Expand Up @@ -109,7 +111,7 @@ pub fn is_git_dirty_version(vers: &str) -> bool {
/// Returns true if the repo contains any tags.
fn _has_tags(repo: &git2::Repository) -> bool {
let mut has_tags = false;
repo.tag_foreach(|_, _| {
let _ = repo.tag_foreach(|_, _| {
has_tags = true;
false
});
Expand Down Expand Up @@ -155,7 +157,7 @@ impl TryFrom<Option<&str>> for Repo {
type Error = git2::Error;
fn try_from(repo_root: Option<&str>) -> Result<Self, Self::Error> {
let repo_root = repo_root.unwrap_or(".");
Ok(Repo {
Ok(Self {
repo: Repository::open(repo_root)?,
})
}
Expand All @@ -165,7 +167,7 @@ impl TryFrom<Option<&Path>> for Repo {
type Error = git2::Error;
fn try_from(repo_root: Option<&Path>) -> Result<Self, Self::Error> {
let repo_root = repo_root.unwrap_or_else(|| Path::new("."));
Ok(Repo {
Ok(Self {
repo: Repository::open(repo_root)?,
})
}
Expand All @@ -187,7 +189,7 @@ impl Repo {
// }

#[must_use]
pub fn inner(&self) -> &git2::Repository {
pub const fn inner(&self) -> &git2::Repository {
&self.repo
}

Expand Down
8 changes: 8 additions & 0 deletions src/tools/git_clone_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ macro_rules! let_named_cap {
//pub(crate) use let_named_cap;

impl<'a> PartsRef<'a> {
/// Parses a git clone URL of any type -
/// including non URL spec compliant ones -
/// into a set of basic parts.
///
/// # Errors
///
/// If our internal regex to parse a git clone URL
/// does not match the supplied string.
pub fn parse<'b>(any_clone_url: &'b str) -> Result<PartsRef<'a>, String>
where
'b: 'a,
Expand Down
Loading

0 comments on commit ab2b217

Please sign in to comment.