Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Embark standard set of additional Clippy lints #332

Merged
merged 1 commit into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/advisories/diags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl<'a> crate::CheckCtx<'a, super::cfg::ValidConfig> {
)
};

let mut notes = get_notes_from_advisory(&advisory);
let mut notes = get_notes_from_advisory(advisory);

if let Some(versions) = versions {
if versions.patched.is_empty() {
Expand Down
12 changes: 6 additions & 6 deletions src/advisories/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl super::Report {

warning.versions.as_ref().and_then(|vs| {
warning.advisory.as_ref().map(|adv| Patchable {
advisory: &adv,
advisory: adv,
patched: &vs.patched,
krate: &warning.package,
})
Expand Down Expand Up @@ -110,7 +110,7 @@ impl super::Report {
// (workspace/local crates) that depend on the vulnerable crate version
// 3. For each crate in the chain, check to see if has a version
// available that ultimately includes a patched version of the vulnerable crate
let (ind, vuln_krate) = super::krate_for_pkg(krates, &patchable.krate).unwrap();
let (ind, vuln_krate) = super::krate_for_pkg(krates, patchable.krate).unwrap();

let mut pack = Pack::with_kid(Check::Advisories, vuln_krate.id.clone());

Expand All @@ -119,7 +119,7 @@ impl super::Report {
if patchable.patched.is_empty() {
pack.push(diags::NoAvailablePatches {
affected_krate_coord: krate_spans.get_coord(ind.index()),
advisory: &patchable.advisory,
advisory: patchable.advisory,
});
diags.push(pack);
continue;
Expand Down Expand Up @@ -161,7 +161,7 @@ impl super::Report {
if required.is_empty() {
pack.push(diags::NoAvailablePatchedVersions {
affected_krate_coord: krate_spans.get_coord(ind.index()),
advisory: &patchable.advisory,
advisory: patchable.advisory,
});
diags.push(pack);
continue;
Expand Down Expand Up @@ -342,7 +342,7 @@ impl super::Report {
) -> Result<Vec<Version>, NoVersionReason> {
let mut res = None;

index.read_krate(&parent, |ik| {
index.read_krate(parent, |ik| {
match ik {
Some(parent_krate) => {
// Grab all of the versions of the parent crate that have a version requirement that accepts
Expand All @@ -359,7 +359,7 @@ impl super::Report {
dep.kind != Some(krates::cm::DependencyKind::Development)
&& dep.name == child.name
}) {
if !required.iter().any(|vs| dep.req.matches(&vs)) {
if !required.iter().any(|vs| dep.req.matches(vs)) {
return None;
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/advisories/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub trait AuditReporter {
fn report(&mut self, report: serde_json::Value);
}

/// For when you just want to satisfy AuditReporter without doing anything
/// For when you just want to satisfy `AuditReporter` without doing anything
pub struct NoneReporter;
impl AuditReporter for NoneReporter {
fn report(&mut self, _report: serde_json::Value) {}
Expand Down Expand Up @@ -67,8 +67,7 @@ pub fn check<R>(

let mut send_diag =
|pkg: &Package, advisory: &Metadata, versions: Option<&Versions>| match krate_for_pkg(
&ctx.krates,
pkg,
ctx.krates, pkg,
) {
Some((i, krate)) => {
// This is a workaround for https://github.com/steveklabnik/semver/issues/172,
Expand Down Expand Up @@ -130,13 +129,13 @@ pub fn check<R>(
.iter_warnings()
.filter_map(|(_, wi)| wi.advisory.as_ref().map(|wia| (wi, wia)))
{
send_diag(&warning.package, &advisory, warning.versions.as_ref());
send_diag(&warning.package, advisory, warning.versions.as_ref());
}

match yanked {
Ok(yanked) => {
for pkg in yanked {
match krate_for_pkg(&ctx.krates, &pkg) {
match krate_for_pkg(ctx.krates, pkg) {
Some((ind, krate)) => {
sink.push(ctx.diag_for_yanked(krate, ind));
}
Expand Down
2 changes: 1 addition & 1 deletion src/bans/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl crate::cfg::UnvalidatedConfig for Config {
}

for a in &allowed {
if let Ok(si) = skipped.binary_search(&a) {
if let Ok(si) = skipped.binary_search(a) {
add_diag((a, "allow"), (&skipped[si], "skip"));
}
}
Expand Down
1 change: 0 additions & 1 deletion src/bans/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ pub fn check(
highlight,
tree_skipped,
wildcards,
..
} = ctx.cfg;

let krate_spans = &ctx.krate_spans;
Expand Down
9 changes: 6 additions & 3 deletions src/index/bare.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! This is a copy of https://github.com/frewsxcv/rust-crates-index/pull/41 so
//! This is a copy of <https://github.com/frewsxcv/rust-crates-index/pull/41> so
//! that we can make releases of cargo-deny until/if it is merged and released

use super::IndexKrate;
Expand Down Expand Up @@ -72,7 +72,10 @@ impl<'a> BareIndexRepo<'a> {
let commit = repo.find_commit(head)?;
let tree = commit.tree()?;

unsafe { std::mem::transmute::<git2::Tree<'_>, git2::Tree<'static>>(tree) }
#[allow(unsafe_code)] // TODO: Can we get rid of this transmute?
unsafe {
std::mem::transmute::<git2::Tree<'_>, git2::Tree<'static>>(tree)
}
};

Ok(Self {
Expand Down Expand Up @@ -110,7 +113,7 @@ impl<'a> BareIndexRepo<'a> {
}

fn krate_from_blob(&self, path: &str) -> Result<IndexKrate, Error> {
let entry = self.tree.as_ref().unwrap().get_path(&Path::new(path))?;
let entry = self.tree.as_ref().unwrap().get_path(Path::new(path))?;
let object = entry.to_object(&self.repo)?;
let blob = object.as_blob().context("unable to get blob contents")?;

Expand Down
10 changes: 3 additions & 7 deletions src/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,7 @@ impl Index {
where
F: FnMut(Option<&IndexKrate>),
{
if !krate
.source
.as_ref()
.map(|src| src.is_registry())
.unwrap_or(false)
{
if !krate.source.as_ref().map_or(false, |src| src.is_registry()) {
func(None);
return;
}
Expand All @@ -204,6 +199,7 @@ impl Index {
if self.opened[ind].is_none() {
match self.registries[ind].open_or_clone() {
Ok(bir) => {
#[allow(unsafe_code)] // TODO: Can we get rid of this transmute?
let bir = unsafe { std::mem::transmute::<_, BareIndexRepo<'static>>(bir) };
self.opened[ind] = Some(bir);
}
Expand Down Expand Up @@ -234,7 +230,7 @@ impl Drop for Index {
}
}

/// Converts a full url, eg https://github.com/rust-lang/crates.io-index, into
/// Converts a full url, eg <https://github.com/rust-lang/crates.io-index>, into
/// the root directory name where cargo itself will fetch it on disk
pub(crate) fn url_to_local_dir(url: &str) -> Result<(String, String), Error> {
fn to_hex(num: u64) -> String {
Expand Down
64 changes: 51 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
#![warn(clippy::all)]
#![warn(rust_2018_idioms)]
// Standard Embark lints
#![deny(unsafe_code)]
#![warn(
clippy::all,
clippy::doc_markdown,
clippy::dbg_macro,
clippy::todo,
clippy::empty_enum,
clippy::enum_glob_use,
clippy::pub_enum_variant_names,
clippy::mem_forget,
clippy::unused_self,
clippy::filter_map_next,
clippy::needless_continue,
clippy::explicit_into_iter_loop,
clippy::needless_borrow,
clippy::match_wildcard_for_single_variants,
clippy::if_let_mutex,
clippy::mismatched_target_os,
clippy::await_holding_lock,
clippy::match_on_vec_items,
clippy::imprecise_flops,
clippy::suboptimal_flops,
clippy::lossy_float_literal,
clippy::let_unit_value,
clippy::debug_assert_with_mut_call,
clippy::ref_option_ref,
clippy::map_flatten,
clippy::rest_pat_in_fully_bound_structs,
clippy::fn_params_excessive_bools,
clippy::exit,
clippy::inefficient_to_string,
clippy::linkedlist,
clippy::string_to_string,
clippy::macro_use_imports,
clippy::option_option,
clippy::verbose_file_reads,
clippy::unnested_or_patterns,
clippy::map_unwrap_or,
rust_2018_idioms,
future_incompatible,
nonstandard_style
)]
#![cfg_attr(docsrs, feature(external_doc))]

//! # ❌ cargo-deny
Expand Down Expand Up @@ -244,17 +285,14 @@ impl Krate {
/// Returns true if the crate is marked as `publish = false`, or
/// it is only published to the specified private registries
pub(crate) fn is_private(&self, private_registries: &[&str]) -> bool {
self.publish
.as_ref()
.map(|v| {
if v.is_empty() {
true
} else {
v.iter()
.all(|reg| private_registries.contains(&reg.as_str()))
}
})
.unwrap_or(false)
self.publish.as_ref().map_or(false, |v| {
if v.is_empty() {
true
} else {
v.iter()
.all(|reg| private_registries.contains(&reg.as_str()))
}
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/licenses/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl crate::cfg::UnvalidatedConfig for Config {
// denied and allowed, that's confusing and probably not intended, so
// they should pick one
for (di, d) in denied.iter().enumerate() {
if let Ok(ai) = allowed.binary_search(&d) {
if let Ok(ai) = allowed.binary_search(d) {
diags.push(
Diagnostic::error()
.with_message("a license id was specified in both `allow` and `deny`")
Expand Down
6 changes: 3 additions & 3 deletions src/licenses/gather.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl LicensePack {
// but we want to see what it thinks the license is if the confidence
// is somewhat ok at least
if lic_match.score >= confidence {
match spdx::license_id(&identified.name) {
match spdx::license_id(identified.name) {
Some(id) => {
if lic_count > 0 {
expr.push_str(" AND ");
Expand Down Expand Up @@ -587,7 +587,7 @@ impl Gatherer {
let mut license_pack = None;

// 1
if let Some(ref cfg) = cfg {
if let Some(cfg) = cfg {
for clarification in iter_clarifications(&cfg.clarifications, krate) {
let lp = match license_pack {
Some(ref lp) => lp,
Expand All @@ -601,7 +601,7 @@ impl Gatherer {
// the set of detected licenses, if they do, we use the clarification's
// license expression as the license requirements for this crate
let clarifications_match = clarification.license_files.iter().all(|clf| {
match lp.license_files_match(&clf) {
match lp.license_files_match(clf) {
Ok(_) => true,
Err(reason) => {
if let MismatchReason::FileNotFound = reason {
Expand Down
8 changes: 4 additions & 4 deletions src/licenses/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ pub fn check(
&& krate_lic_nfo.krate.is_private(&private_registries)
{
pack.push(diags::SkippedPrivateWorkspaceCrate {
krate: &krate_lic_nfo.krate,
krate: krate_lic_nfo.krate,
});
sink.push(pack);
continue;
Expand All @@ -302,8 +302,8 @@ pub fn check(
pack.push(evaluate_expression(
&ctx.cfg,
&krate_lic_nfo,
&expr,
&nfo,
expr,
nfo,
&mut hits,
));
}
Expand All @@ -315,7 +315,7 @@ pub fn check(
};

pack.push(diags::Unlicensed {
krate: &krate_lic_nfo.krate,
krate: krate_lic_nfo.krate,
severity,
breadcrumbs: krate_lic_nfo.labels.into_iter().collect(),
});
Expand Down
7 changes: 3 additions & 4 deletions src/manifest/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ impl Dependency {
pub fn set_features(mut self, features: Option<Vec<String>>) -> Dependency {
self.features = features.map(|f| {
f.iter()
.map(|x| x.split(' ').map(String::from))
.flatten()
.flat_map(|x| x.split(' ').map(String::from))
.filter(|s| !s.is_empty())
.collect::<Vec<String>>()
});
Expand All @@ -137,7 +136,7 @@ impl Dependency {
/// that is, either the alias (rename field if Some),
/// or the official package name (name field).
pub fn name_in_manifest(&self) -> &str {
&self.rename().unwrap_or(&self.name)
self.rename().unwrap_or(&self.name)
}

/// Set the value of registry for the dependency
Expand Down Expand Up @@ -170,7 +169,7 @@ impl Dependency {
/// Get the alias for the dependency (if any)
pub fn rename(&self) -> Option<&str> {
match &self.rename {
Some(rename) => Some(&rename),
Some(rename) => Some(rename),
None => None,
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn merge_inline_table(old_dep: &mut toml_edit::Item, new: &toml_edit::Item) {
}

fn str_or_1_len_table(item: &toml_edit::Item) -> bool {
item.is_str() || item.as_table_like().map(|t| t.len() == 1).unwrap_or(false)
item.is_str() || item.as_table_like().map_or(false, |t| t.len() == 1)
}

fn merge_dependencies(old_dep: &mut toml_edit::Item, new: &dep::Dependency) {
Expand Down Expand Up @@ -148,7 +148,7 @@ impl Manifest {
.unwrap_or(name);

if let Some(update_dep) = deps.iter().find(|dep| dep.name == dep_name) {
self.update_table_named_entry(&table_path, &name, update_dep)?;
self.update_table_named_entry(&table_path, name, update_dep)?;
}
}
}
Expand Down