Skip to content

Commit

Permalink
🚨 - Fix Clippy Warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandpeelen committed Apr 12, 2024
1 parent 1838727 commit f934553
Show file tree
Hide file tree
Showing 15 changed files with 249 additions and 334 deletions.
21 changes: 9 additions & 12 deletions src/bsconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,13 @@ pub fn flatten_flags(flags: &Option<Vec<OneOrMore<String>>>) -> Vec<String> {
None => vec![],
Some(xs) => xs
.iter()
.map(|x| match x {
.flat_map(|x| match x {
OneOrMore::Single(y) => vec![y.to_owned()],
OneOrMore::Multiple(ys) => ys.to_owned(),
})
.flatten()
.collect::<Vec<String>>()
.iter()
.map(|str| str.split(" "))
.flatten()
.flat_map(|str| str.split(' '))
.map(|str| str.to_string())
.collect::<Vec<String>>(),
}
Expand All @@ -197,9 +195,9 @@ pub fn flatten_ppx_flags(
None => vec![],
Some(xs) => xs
.iter()
.map(|x| match x {
.flat_map(|x| match x {
OneOrMore::Single(y) => {
let first_character = y.chars().nth(0);
let first_character = y.chars().next();
match first_character {
Some('.') => {
vec![
Expand All @@ -210,9 +208,9 @@ pub fn flatten_ppx_flags(
_ => vec!["-ppx".to_string(), node_modules_dir.to_owned() + "/" + y],
}
}
OneOrMore::Multiple(ys) if ys.len() == 0 => vec![],
OneOrMore::Multiple(ys) if ys.is_empty() => vec![],
OneOrMore::Multiple(ys) => {
let first_character = ys[0].chars().nth(0);
let first_character = ys[0].chars().next();
let ppx = match first_character {
Some('.') => node_modules_dir.to_owned() + "/" + package_name + "/" + &ys[0],
_ => node_modules_dir.to_owned() + "/" + &ys[0],
Expand All @@ -227,7 +225,6 @@ pub fn flatten_ppx_flags(
]
}
})
.flatten()
.collect::<Vec<String>>(),
}
}
Expand All @@ -243,14 +240,14 @@ pub fn read(path: String) -> Config {
}

fn check_if_rescript11_or_higher(version: &str) -> bool {
version.split(".").nth(0).unwrap().parse::<usize>().unwrap() >= 11
version.split('.').next().unwrap().parse::<usize>().unwrap() >= 11
}

fn namespace_from_package_name(package_name: &str) -> String {
package_name
.to_owned()
.replace("@", "")
.replace("/", "_")
.replace('@', "")
.replace('/', "_")
.to_case(Case::Pascal)
}

Expand Down
10 changes: 5 additions & 5 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn get_compiler_args(path: &str, rescript_version: Option<String>) -> String
&workspace_root,
workspace_root.as_ref().unwrap_or(&package_root),
);
let is_interface = filename.ends_with("i");
let is_interface = filename.ends_with('i');
let has_interface = if is_interface {
true
} else {
Expand All @@ -106,7 +106,7 @@ pub fn get_compiler_args(path: &str, rescript_version: Option<String>) -> String
.unwrap()
}

pub fn initialize_build<'a>(
pub fn initialize_build(
default_timing: Option<Duration>,
filter: &Option<regex::Regex>,
path: &str,
Expand All @@ -120,7 +120,7 @@ pub fn initialize_build<'a>(
print!("{}{}Building package tree...", style("[1/7]").bold().dim(), TREE);
let _ = stdout().flush();
let timing_package_tree = Instant::now();
let packages = packages::make(&filter, &project_root, &workspace_root);
let packages = packages::make(filter, &project_root, &workspace_root);
let timing_package_tree_elapsed = timing_package_tree.elapsed();

println!(
Expand Down Expand Up @@ -307,7 +307,7 @@ pub fn incremental_build(

logs::finalize(&build_state.packages);
pb.finish();
if compile_errors.len() > 0 {
if !compile_errors.is_empty() {
if helpers::contains_ascii_characters(&compile_warnings) {
println!("{}", &compile_warnings);
}
Expand All @@ -326,7 +326,7 @@ pub fn incremental_build(
module.compile_dirty = true;
}
}
return Err(());
Err(())
} else {
println!(
"{}{} {}Compiled {} modules in {:.2}s",
Expand Down
8 changes: 3 additions & 5 deletions src/build/build_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,10 @@ pub struct Module {

impl Module {
pub fn is_mlmap(&self) -> bool {
match self.source_type {
SourceType::MlMap(_) => true,
_ => false,
}
matches!(self.source_type, SourceType::MlMap(_))
}
pub fn get_interface<'a>(&'a self) -> &'a Option<Interface> {

pub fn get_interface(&self) -> &Option<Interface> {
match &self.source_type {
SourceType::SourceFile(source_file) => &source_file.interface,
_ => &None,
Expand Down
92 changes: 39 additions & 53 deletions src/build/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn clean_mjs_files(build_state: &BuildState) {
.expect("Could not find root package");
Some((
std::path::PathBuf::from(package.path.to_string())
.join(source_file.implementation.path.to_string())
.join(&source_file.implementation.path)
.to_string_lossy()
.to_string(),
root_package
Expand All @@ -88,7 +88,7 @@ pub fn clean_mjs_files(build_state: &BuildState) {

rescript_file_locations
.par_iter()
.for_each(|(rescript_file_location, suffix)| remove_mjs_file(&rescript_file_location, &suffix));
.for_each(|(rescript_file_location, suffix)| remove_mjs_file(rescript_file_location, suffix));
}

// TODO: change to scan_previous_build => CompileAssetsState
Expand Down Expand Up @@ -131,7 +131,7 @@ pub fn cleanup_previous_build(
.expect("Could not find package");
remove_compile_assets(package, res_file_location);
remove_mjs_file(
&res_file_location,
res_file_location,
&suffix
.to_owned()
.unwrap_or(String::from(bsconfig::DEFAULT_SUFFIX)),
Expand All @@ -152,7 +152,6 @@ pub fn cleanup_previous_build(
compile_assets_state
.ast_rescript_file_locations
.intersection(&compile_assets_state.rescript_file_locations)
.into_iter()
.for_each(|res_file_location| {
let AstModule {
module_name,
Expand All @@ -173,7 +172,7 @@ pub fn cleanup_previous_build(
let last_modified = Some(ast_last_modified);

if let Some(last_modified) = last_modified {
if compile_dirty > &last_modified && !deleted_interfaces.contains(module_name) {
if compile_dirty > last_modified && !deleted_interfaces.contains(module_name) {
module.compile_dirty = false;
}
}
Expand Down Expand Up @@ -209,18 +208,18 @@ pub fn cleanup_previous_build(
.cmi_modules
.iter()
.for_each(|(module_name, last_modified)| {
build_state.modules.get_mut(module_name).map(|module| {
if let Some(module) = build_state.modules.get_mut(module_name) {
module.last_compiled_cmi = Some(*last_modified);
});
}
});

compile_assets_state
.cmt_modules
.iter()
.for_each(|(module_name, last_modified)| {
build_state.modules.get_mut(module_name).map(|module| {
if let Some(module) = build_state.modules.get_mut(module_name) {
module.last_compiled_cmt = Some(*last_modified);
});
}
});

let ast_module_names = compile_assets_state
Expand All @@ -241,11 +240,7 @@ pub fn cleanup_previous_build(
)
.collect::<AHashSet<&String>>();

let all_module_names = build_state
.modules
.keys()
.map(|module_name| module_name)
.collect::<AHashSet<&String>>();
let all_module_names = build_state.modules.keys().collect::<AHashSet<&String>>();

let deleted_module_names = ast_module_names
.difference(&all_module_names)
Expand All @@ -254,7 +249,7 @@ pub fn cleanup_previous_build(
if let Some(namespace) = helpers::get_namespace_from_module_name(module_name) {
return namespace;
}
return module_name.to_string();
module_name.to_string()
})
.collect::<AHashSet<String>>();

Expand All @@ -264,59 +259,50 @@ pub fn cleanup_previous_build(
}

fn has_parse_warnings(module: &Module) -> bool {
match &module.source_type {
matches!(
&module.source_type,
SourceType::SourceFile(SourceFile {
implementation:
Implementation {
parse_state: ParseState::Warning,
..
},
implementation: Implementation {
parse_state: ParseState::Warning,
..
},
..
}) => true,
SourceType::SourceFile(SourceFile {
interface:
Some(Interface {
parse_state: ParseState::Warning,
..
}),
}) | SourceType::SourceFile(SourceFile {
interface: Some(Interface {
parse_state: ParseState::Warning,
..
}),
..
}) => true,
_ => false,
}
})
)
}

fn has_compile_warnings(module: &Module) -> bool {
match &module.source_type {
matches!(
&module.source_type,
SourceType::SourceFile(SourceFile {
implementation:
Implementation {
compile_state: CompileState::Warning,
..
},
implementation: Implementation {
compile_state: CompileState::Warning,
..
},
..
}) => true,
SourceType::SourceFile(SourceFile {
interface:
Some(Interface {
compile_state: CompileState::Warning,
..
}),
}) | SourceType::SourceFile(SourceFile {
interface: Some(Interface {
compile_state: CompileState::Warning,
..
}),
..
}) => true,
_ => false,
}
})
)
}

pub fn cleanup_after_build(build_state: &BuildState) {
build_state.modules.par_iter().for_each(|(_module_name, module)| {
let package = build_state.get_package(&module.package_name).unwrap();
if has_parse_warnings(module) {
match &module.source_type {
SourceType::SourceFile(source_file) => {
remove_iast(package, &source_file.implementation.path);
remove_ast(package, &source_file.implementation.path);
}
_ => (),
if let SourceType::SourceFile(source_file) = &module.source_type {
remove_iast(package, &source_file.implementation.path);
remove_ast(package, &source_file.implementation.path);
}
}
if has_compile_warnings(module) {
Expand Down
Loading

0 comments on commit f934553

Please sign in to comment.