Skip to content

Commit

Permalink
Use Embark's Clippy config (#27)
Browse files Browse the repository at this point in the history
* Add Embark's Clippy config

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix all clippy

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  • Loading branch information
ggwpez committed Aug 24, 2023
1 parent bba51e9 commit 6088a15
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 40 deletions.
79 changes: 79 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
[target.'cfg(all())']
rustflags = [
# BEGIN - Embark standard lints v6 for Rust 1.55+
# do not change or add/remove here, but one can add exceptions after this section
# for more info see: <https://github.com/EmbarkStudios/rust-ecosystem/issues/59>
"-Dunsafe_code",
"-Wclippy::all",
"-Wclippy::await_holding_lock",
"-Wclippy::char_lit_as_u8",
"-Wclippy::checked_conversions",
"-Wclippy::dbg_macro",
"-Wclippy::debug_assert_with_mut_call",
"-Wclippy::doc_markdown",
"-Wclippy::empty_enum",
"-Wclippy::enum_glob_use",
"-Wclippy::exit",
"-Wclippy::expl_impl_clone_on_copy",
"-Wclippy::explicit_deref_methods",
"-Wclippy::explicit_into_iter_loop",
"-Wclippy::fallible_impl_from",
"-Wclippy::filter_map_next",
"-Wclippy::flat_map_option",
"-Wclippy::float_cmp_const",
"-Wclippy::fn_params_excessive_bools",
"-Wclippy::from_iter_instead_of_collect",
"-Wclippy::if_let_mutex",
"-Wclippy::implicit_clone",
"-Wclippy::imprecise_flops",
"-Wclippy::inefficient_to_string",
"-Wclippy::invalid_upcast_comparisons",
"-Wclippy::large_digit_groups",
"-Wclippy::large_stack_arrays",
"-Wclippy::large_types_passed_by_value",
"-Wclippy::let_unit_value",
"-Wclippy::linkedlist",
"-Wclippy::lossy_float_literal",
"-Wclippy::macro_use_imports",
"-Wclippy::manual_ok_or",
"-Wclippy::map_err_ignore",
"-Wclippy::map_flatten",
"-Wclippy::map_unwrap_or",
"-Wclippy::match_on_vec_items",
"-Wclippy::match_same_arms",
"-Wclippy::match_wild_err_arm",
"-Wclippy::match_wildcard_for_single_variants",
"-Wclippy::mem_forget",
"-Wclippy::mismatched_target_os",
"-Wclippy::missing_enforced_import_renames",
"-Wclippy::mut_mut",
"-Wclippy::mutex_integer",
"-Wclippy::needless_borrow",
"-Wclippy::needless_continue",
"-Wclippy::needless_for_each",
"-Wclippy::option_option",
"-Wclippy::path_buf_push_overwrite",
"-Wclippy::ptr_as_ptr",
"-Wclippy::rc_mutex",
"-Wclippy::ref_option_ref",
"-Wclippy::rest_pat_in_fully_bound_structs",
"-Wclippy::same_functions_in_if_condition",
"-Wclippy::semicolon_if_nothing_returned",
"-Wclippy::single_match_else",
"-Wclippy::string_add_assign",
"-Wclippy::string_add",
"-Wclippy::string_lit_as_bytes",
"-Wclippy::string_to_string",
"-Wclippy::todo",
"-Wclippy::trait_duplication_in_bounds",
"-Wclippy::unimplemented",
"-Wclippy::unnested_or_patterns",
"-Wclippy::unused_self",
"-Wclippy::useless_transmute",
"-Wclippy::verbose_file_reads",
"-Wclippy::zero_sized_map_values",
"-Wfuture_incompatible",
"-Wnonstandard_style",
"-Wrust_2018_idioms",
# END - Embark standard lints v6 for Rust 1.55+
]
35 changes: 16 additions & 19 deletions src/autofix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl AutoFixer {
// DOGSHIT CODE
values.sort_by(|a, b| a.as_str().unwrap().cmp(b.as_str().unwrap()));
feature.clear();
for value in values.into_iter() {
for value in values {
feature.push_formatted(value.clone());
}
}
Expand Down Expand Up @@ -164,7 +164,7 @@ impl AutoFixer {
feature.set_trailing_comma(false);
feature.set_trailing("");
feature.clear();
for value in values.into_iter() {
for value in values {
feature.push_formatted(value.clone());
}

Expand Down Expand Up @@ -211,7 +211,7 @@ impl AutoFixer {
}

feature.clear();
for value in values.into_iter() {
for value in values {
feature.push_formatted(value.clone());
}
feature.set_trailing_comma(false);
Expand Down Expand Up @@ -275,22 +275,19 @@ impl AutoFixer {
for feature_name in features.iter() {
let feature = self.get_feature_mut(feature_name).unwrap();

match mode_per_feature.get(feature_name) {
Some(modes) => {
if modes.contains(&Mode::None) {
continue
}
if modes.contains(&Mode::Sort) {
Self::sort_feature(feature);
}
if modes.contains(&Mode::Canonicalize) {
Self::format_feature(feature_name, feature, line_width)?;
}
},
None => {
if let Some(modes) = mode_per_feature.get(feature_name) {
if modes.contains(&Mode::None) {
continue
}
if modes.contains(&Mode::Sort) {
Self::sort_feature(feature);
}
if modes.contains(&Mode::Canonicalize) {
Self::format_feature(feature_name, feature, line_width)?;
},
}
} else {
Self::sort_feature(feature);
Self::format_feature(feature_name, feature, line_width)?;
}
}

Expand Down Expand Up @@ -348,7 +345,7 @@ impl AutoFixer {
feature.set_trailing_comma(false); // We need to add this manually later on.
let mut new_vals = Vec::new();

for mut value in values.into_iter() {
for mut value in values {
if value.as_str().map_or(false, |s| s.is_empty()) {
panic!("Empty value in feature");
}
Expand Down Expand Up @@ -388,7 +385,7 @@ impl AutoFixer {
new_vals[i - 1].decor_mut().set_suffix("");
}

for new_val in new_vals.into_iter() {
for new_val in new_vals {
feature.push_formatted(new_val);
}

Expand Down
9 changes: 4 additions & 5 deletions src/cmd/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl LintCmd {
struct CrateAndFeature(String, String);

impl Display for CrateAndFeature {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}/{}", self.0, self.1)
}
}
Expand Down Expand Up @@ -287,7 +287,7 @@ impl NeverEnablesCmd {
let Some(enabled) = lhs.features.get(&self.precondition) else { continue };

// TODO do the same in other command.
if enabled.contains(&self.stays_disabled.to_string()) {
if enabled.contains(&self.stays_disabled) {
offenders.entry(lhs.id.to_string()).or_default().insert(RenamedPackage::new(
(*lhs).clone(),
None,
Expand Down Expand Up @@ -565,9 +565,8 @@ impl OnlyEnablesCmd {
for (feat, imply) in pkg.features.iter() {
if feat == &self.precondition {
continue
} else {
log::info!("{}: {}", feat, imply.join(", "));
}
log::info!("{}: {}", feat, imply.join(", "));

let opt = if dep.optional { "?" } else { "" };
let bad_opt = format!("{}{}/{}", dep.name(), opt, self.only_enables);
Expand Down Expand Up @@ -726,7 +725,7 @@ fn build_feature_dag(meta: &Metadata, pkgs: &[Package]) -> Dag<CrateAndFeature>
dag.add_edge(
CrateAndFeature(pkg.id.to_string(), feature.clone()),
CrateAndFeature(pkg.id.to_string(), dep_feature.into()),
)
);
}
}
}
Expand Down
9 changes: 3 additions & 6 deletions src/cmd/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub struct TraceCmd {
impl TraceCmd {
pub fn run(&self, _global: &GlobalArgs) {
let meta = self.cargo_args.load_metadata().expect("Loads metadata");
let (dag, index) = self.build_dag(meta).expect("Builds dependency graph");
let (dag, index) = Self::build_dag(meta).expect("Builds dependency graph");
let lookup = |id: &str| {
index
.get(id)
Expand Down Expand Up @@ -120,14 +120,11 @@ impl TraceCmd {
}

/// Build a dependency graph over the crates ids and return an index of all crates.
fn build_dag(
&self,
meta: Metadata,
) -> Result<(Dag<CrateId>, BTreeMap<CrateId, Package>), String> {
fn build_dag(meta: Metadata) -> Result<(Dag<CrateId>, BTreeMap<CrateId, Package>), String> {
let mut dag = Dag::new();
let mut index = BTreeMap::new();

for pkg in meta.packages.clone().into_iter() {
for pkg in meta.packages.clone() {
let id = pkg.id.to_string();
dag.add_node(id.clone());
index.insert(pkg.id.to_string(), pkg.clone());
Expand Down
4 changes: 2 additions & 2 deletions src/dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ where
F: FnMut(&T),
{
for e in self.0.iter() {
f(e.as_ref())
f(e.as_ref());
}
}
}
Expand Down Expand Up @@ -143,7 +143,7 @@ where
///
/// *Directly* means with via an edge.
pub fn connected(&self, from: &T, to: &T) -> bool {
self.edges.get(from).map(|v| v.contains(to)).unwrap_or(false)
self.edges.get(from).map_or(false, |v| v.contains(to))
}

/// Whether `from` appears on the lhs of the edge relation.
Expand Down
13 changes: 7 additions & 6 deletions src/mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl Context {

/// Convert a crate's name to a file path.
///
/// This is needed for case-insensitive file systems like on MacOS. It prefixes all lower-case
/// This is needed for case-insensitive file systems like on `MacOS`. It prefixes all lower-case
/// letters with an `l` and turns the upper case.
pub(crate) fn crate_name_to_path(n: &str) -> String {
n.chars()
Expand All @@ -263,9 +263,10 @@ pub enum CrateDependency {
impl CrateDependency {
fn def(&self) -> String {
let option = if self.optional() { ", optional = true".to_string() } else { String::new() };
let mut ret = match self.rename() {
Some(rename) => format!("{} = {{ package = \"{}\", ", rename, self.name()),
None => format!("{} = {{ ", self.name()),
let mut ret = if let Some(rename) = self.rename() {
format!("{} = {{ package = \"{}\", ", rename, self.name())
} else {
format!("{} = {{ ", self.name())
};
ret.push_str(&format!("version = \"*\", path = \"../{}\"{}}}\n", self.path(), option));
ret
Expand All @@ -284,14 +285,14 @@ impl CrateDependency {
fn rename(&self) -> Option<String> {
match self {
Self::Explicit { rename, .. } => rename.clone(),
_ => None,
Self::Implicit(_) => None,
}
}

fn optional(&self) -> bool {
match self {
Self::Explicit { optional, .. } => optional.unwrap_or_default(),
_ => false,
Self::Implicit(_) => false,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ fn integration() {
continue
}

for (i, stdout) in overwrites.into_iter() {
for (i, stdout) in overwrites {
config.case_mut(i).stdout = stdout;
}
for (i, diff) in diff_overwrites.into_iter() {
for (i, diff) in diff_overwrites {
config.case_mut(i).diff = diff;
}

Expand Down

0 comments on commit 6088a15

Please sign in to comment.