Skip to content

Commit b2e239c

Browse files
committed
🚨 - Fix clippy suggestions
1 parent f0485e1 commit b2e239c

File tree

6 files changed

+131
-149
lines changed

6 files changed

+131
-149
lines changed

src/build/clean.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ pub fn cleanup_previous_build(
125125
.get(package_name)
126126
.expect("Could not find package");
127127
remove_compile_assets(package, res_file_location);
128-
remove_mjs_file(res_file_location, &suffix);
128+
remove_mjs_file(res_file_location, suffix);
129129
remove_iast(package, res_file_location);
130130
remove_ast(package, res_file_location);
131131
match helpers::get_extension(ast_file_path).as_str() {
@@ -234,14 +234,13 @@ pub fn cleanup_previous_build(
234234

235235
let deleted_module_names = ast_module_names
236236
.difference(&all_module_names)
237-
.map(|module_name| {
237+
.flat_map(|module_name| {
238238
// if the module is a namespace, we need to mark the whole namespace as dirty when a module has been deleted
239239
if let Some(namespace) = helpers::get_namespace_from_module_name(module_name) {
240240
return vec![namespace, module_name.to_string()];
241241
}
242242
vec![module_name.to_string()]
243243
})
244-
.flatten()
245244
.collect::<AHashSet<String>>();
246245

247246
build_state.deleted_modules = deleted_module_names;

src/build/compile.rs

Lines changed: 83 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,10 @@ pub fn compile(
219219
} else {
220220
None
221221
}
222-
.map(|res| {
222+
.inspect(|_res| {
223223
if !(log_enabled!(Info)) {
224224
inc();
225225
}
226-
res
227226
})
228227
})
229228
.collect::<Vec<
@@ -236,103 +235,100 @@ pub fn compile(
236235
)>,
237236
>>()
238237
.iter()
239-
.for_each(|result| match result {
240-
Some((module_name, result, interface_result, is_clean, is_compiled)) => {
241-
in_progress_modules.remove(module_name);
238+
.for_each(|result| if let Some((module_name, result, interface_result, is_clean, is_compiled)) = result {
239+
in_progress_modules.remove(module_name);
242240

243-
if *is_compiled {
244-
num_compiled_modules += 1;
245-
}
241+
if *is_compiled {
242+
num_compiled_modules += 1;
243+
}
246244

247-
files_current_loop_count += 1;
248-
compiled_modules.insert(module_name.to_string());
245+
files_current_loop_count += 1;
246+
compiled_modules.insert(module_name.to_string());
249247

250-
if *is_clean {
251-
// actually add it to a list of clean modules
252-
clean_modules.insert(module_name.to_string());
253-
}
248+
if *is_clean {
249+
// actually add it to a list of clean modules
250+
clean_modules.insert(module_name.to_string());
251+
}
254252

255-
let module_dependents = build_state.get_module(module_name).unwrap().dependents.clone();
253+
let module_dependents = build_state.get_module(module_name).unwrap().dependents.clone();
256254

257-
// if not clean -- compile modules that depend on this module
258-
for dep in module_dependents.iter() {
255+
// if not clean -- compile modules that depend on this module
256+
for dep in module_dependents.iter() {
257+
// mark the reverse dep as dirty when the source is not clean
258+
if !*is_clean {
259+
let dep_module = build_state.modules.get_mut(dep).unwrap();
259260
// mark the reverse dep as dirty when the source is not clean
260-
if !*is_clean {
261-
let dep_module = build_state.modules.get_mut(dep).unwrap();
262-
// mark the reverse dep as dirty when the source is not clean
263-
dep_module.compile_dirty = true;
264-
}
265-
if !compiled_modules.contains(dep) {
266-
in_progress_modules.insert(dep.to_string());
267-
}
261+
dep_module.compile_dirty = true;
268262
}
263+
if !compiled_modules.contains(dep) {
264+
in_progress_modules.insert(dep.to_string());
265+
}
266+
}
269267

270-
let module = build_state.modules.get_mut(module_name).unwrap();
271-
let package = build_state
272-
.packages
273-
.get(&module.package_name)
274-
.expect("Package not found");
275-
match module.source_type {
276-
SourceType::MlMap(ref mut mlmap) => {
277-
module.compile_dirty = false;
278-
mlmap.parse_dirty = false;
279-
}
280-
SourceType::SourceFile(ref mut source_file) => {
281-
match result {
282-
Ok(Some(err)) => {
283-
source_file.implementation.compile_state = CompileState::Warning;
284-
logs::append(package, err);
285-
compile_warnings.push_str(err);
286-
}
287-
Ok(None) => {
288-
source_file.implementation.compile_state = CompileState::Success;
289-
}
290-
Err(err) => {
291-
source_file.implementation.compile_state = CompileState::Error;
292-
logs::append(package, err);
293-
compile_errors.push_str(err);
294-
}
295-
};
296-
match interface_result {
297-
Some(Ok(Some(err))) => {
298-
source_file.interface.as_mut().unwrap().compile_state =
299-
CompileState::Warning;
300-
logs::append(package, err);
301-
compile_warnings.push_str(err);
302-
}
303-
Some(Ok(None)) => {
304-
if let Some(interface) = source_file.interface.as_mut() {
305-
interface.compile_state = CompileState::Success;
306-
}
268+
let module = build_state.modules.get_mut(module_name).unwrap();
269+
let package = build_state
270+
.packages
271+
.get(&module.package_name)
272+
.expect("Package not found");
273+
match module.source_type {
274+
SourceType::MlMap(ref mut mlmap) => {
275+
module.compile_dirty = false;
276+
mlmap.parse_dirty = false;
277+
}
278+
SourceType::SourceFile(ref mut source_file) => {
279+
match result {
280+
Ok(Some(err)) => {
281+
source_file.implementation.compile_state = CompileState::Warning;
282+
logs::append(package, err);
283+
compile_warnings.push_str(err);
284+
}
285+
Ok(None) => {
286+
source_file.implementation.compile_state = CompileState::Success;
287+
}
288+
Err(err) => {
289+
source_file.implementation.compile_state = CompileState::Error;
290+
logs::append(package, err);
291+
compile_errors.push_str(err);
292+
}
293+
};
294+
match interface_result {
295+
Some(Ok(Some(err))) => {
296+
source_file.interface.as_mut().unwrap().compile_state =
297+
CompileState::Warning;
298+
logs::append(package, err);
299+
compile_warnings.push_str(err);
300+
}
301+
Some(Ok(None)) => {
302+
if let Some(interface) = source_file.interface.as_mut() {
303+
interface.compile_state = CompileState::Success;
307304
}
305+
}
308306

309-
Some(Err(err)) => {
310-
source_file.interface.as_mut().unwrap().compile_state =
311-
CompileState::Error;
312-
logs::append(package, err);
313-
compile_errors.push_str(err);
314-
}
315-
_ => (),
316-
};
317-
match (result, interface_result) {
318-
// successfull compilation
319-
(Ok(None), Some(Ok(None))) | (Ok(None), None) => {
320-
module.compile_dirty = false;
321-
module.last_compiled_cmi = Some(SystemTime::now());
322-
module.last_compiled_cmt = Some(SystemTime::now());
323-
}
324-
// some error or warning
325-
(Err(_), _)
326-
| (_, Some(Err(_)))
327-
| (Ok(Some(_)), _)
328-
| (_, Some(Ok(Some(_)))) => {
329-
module.compile_dirty = true;
330-
}
307+
Some(Err(err)) => {
308+
source_file.interface.as_mut().unwrap().compile_state =
309+
CompileState::Error;
310+
logs::append(package, err);
311+
compile_errors.push_str(err);
312+
}
313+
_ => (),
314+
};
315+
match (result, interface_result) {
316+
// successfull compilation
317+
(Ok(None), Some(Ok(None))) | (Ok(None), None) => {
318+
module.compile_dirty = false;
319+
module.last_compiled_cmi = Some(SystemTime::now());
320+
module.last_compiled_cmt = Some(SystemTime::now());
321+
}
322+
// some error or warning
323+
(Err(_), _)
324+
| (_, Some(Err(_)))
325+
| (Ok(Some(_)), _)
326+
| (_, Some(Ok(Some(_)))) => {
327+
module.compile_dirty = true;
331328
}
332329
}
333330
}
334331
}
335-
None => (),
336332
});
337333

338334
files_total_count += files_current_loop_count;
@@ -388,7 +384,7 @@ pub fn compiler_args(
388384
// .unwrap_or(&vec![])
389385
// .to_owned();
390386

391-
let deps = vec![normal_deps]
387+
let deps = [normal_deps]
392388
.concat()
393389
.par_iter()
394390
.map(|package_name| {
@@ -455,7 +451,7 @@ pub fn compiler_args(
455451
_ => vec![],
456452
};
457453

458-
vec![warn_number, warn_error].concat()
454+
[warn_number, warn_error].concat()
459455
}
460456
};
461457

src/build/deps.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,15 @@ pub fn get_deps(build_state: &mut BuildState, deleted_modules: &AHashSet<String>
8484
all_mod,
8585
);
8686

87-
match &source_file.interface {
88-
Some(interface) => {
89-
let iast_path = package.get_iast_path(&interface.path);
87+
if let Some(interface) = &source_file.interface {
88+
let iast_path = package.get_iast_path(&interface.path);
9089

91-
deps.extend(get_dep_modules(
92-
&iast_path,
93-
package.namespace.to_suffix(),
94-
package.modules.as_ref().unwrap(),
95-
all_mod,
96-
))
97-
}
98-
None => (),
90+
deps.extend(get_dep_modules(
91+
&iast_path,
92+
package.namespace.to_suffix(),
93+
package.modules.as_ref().unwrap(),
94+
all_mod,
95+
))
9996
}
10097
match &package.namespace {
10198
packages::Namespace::NamespaceWithEntry { namespace: _, entry }

src/build/packages.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ pub fn read_dependency(
278278
279279
/// Given a bsconfig, recursively finds all dependencies.
280280
/// 1. It starts with registering dependencies and
281-
/// prevents the operation for the ones which are already
282-
/// registerd for the parent packages. Especially relevant for peerDependencies.
281+
/// prevents the operation for the ones which are already
282+
/// registerd for the parent packages. Especially relevant for peerDependencies.
283283
/// 2. In parallel performs IO to read the dependencies bsconfig and
284-
/// recursively continues operation for their dependencies as well.
284+
/// recursively continues operation for their dependencies as well.
285285
fn read_dependencies(
286286
registered_dependencies_set: &mut AHashSet<String>,
287287
parent_bsconfig: &bsconfig::Config,
@@ -292,7 +292,7 @@ fn read_dependencies(
292292
return parent_bsconfig
293293
.bs_dependencies
294294
.to_owned()
295-
.unwrap_or(vec![])
295+
.unwrap_or_default()
296296
.iter()
297297
.filter_map(|package_name| {
298298
if registered_dependencies_set.contains(package_name) {
@@ -517,6 +517,7 @@ fn extend_with_children(
517517
/// 1. Get all the packages parsed, and take all the source folders from the bsconfig
518518
/// 2. Take the (by then deduplicated) packages, and find all the '.re', '.res', '.ml' and
519519
/// interface files.
520+
///
520521
/// The two step process is there to reduce IO overhead
521522
pub fn make(
522523
filter: &Option<regex::Regex>,
@@ -528,12 +529,9 @@ pub fn make(
528529
/* Once we have the deduplicated packages, we can add the source files for each - to minimize
529530
* the IO */
530531
let result = extend_with_children(filter, map);
531-
result.values().for_each(|package| match &package.dirs {
532-
Some(dirs) => dirs.iter().for_each(|dir| {
533-
let _ = std::fs::create_dir_all(std::path::Path::new(&package.get_bs_build_path()).join(dir));
534-
}),
535-
None => (),
536-
});
532+
result.values().for_each(|package| if let Some(dirs) = &package.dirs { dirs.iter().for_each(|dir| {
533+
let _ = std::fs::create_dir_all(std::path::Path::new(&package.get_bs_build_path()).join(dir));
534+
}) });
537535
result
538536
}
539537

@@ -778,11 +776,9 @@ pub fn validate_packages_dependencies(packages: &AHashMap<String, Package>) -> b
778776
let pinned_dependencies = &package.bsconfig.pinned_dependencies.to_owned().unwrap_or(vec![]);
779777
let dev_dependencies = &package.bsconfig.bs_dev_dependencies.to_owned().unwrap_or(vec![]);
780778

781-
vec![
782-
("bs-dependencies", bs_dependencies),
779+
[("bs-dependencies", bs_dependencies),
783780
("pinned-dependencies", pinned_dependencies),
784-
("bs-dev-dependencies", dev_dependencies),
785-
]
781+
("bs-dev-dependencies", dev_dependencies)]
786782
.iter()
787783
.for_each(|(dependency_type, dependencies)| {
788784
if let Some(unallowed_dependency_name) =
@@ -812,11 +808,9 @@ pub fn validate_packages_dependencies(packages: &AHashMap<String, Package>) -> b
812808
console::style(package_name).bold()
813809
);
814810

815-
vec![
816-
("bs-dependencies", unallowed_deps.bs_deps.to_owned()),
811+
[("bs-dependencies", unallowed_deps.bs_deps.to_owned()),
817812
("pinned-dependencies", unallowed_deps.pinned_deps.to_owned()),
818-
("bs-dev-dependencies", unallowed_deps.bs_dev_deps.to_owned()),
819-
]
813+
("bs-dev-dependencies", unallowed_deps.bs_dev_deps.to_owned())]
820814
.iter()
821815
.for_each(|(deps_type, map)| {
822816
if !map.is_empty() {
@@ -854,7 +848,7 @@ mod test {
854848
dev_deps: Vec<String>,
855849
allowed_dependents: Option<Vec<String>>,
856850
) -> Package {
857-
return Package {
851+
Package {
858852
name: name.clone(),
859853
bsconfig: crate::bsconfig::Config {
860854
name: name.clone(),
@@ -883,7 +877,7 @@ mod test {
883877
dirs: None,
884878
is_pinned_dep: false,
885879
is_root: false,
886-
};
880+
}
887881
}
888882
#[test]
889883
fn should_return_false_with_invalid_parents_as_bs_dependencies() {
@@ -910,7 +904,7 @@ mod test {
910904
);
911905

912906
let is_valid = super::validate_packages_dependencies(&packages);
913-
assert_eq!(is_valid, false)
907+
assert!(!is_valid)
914908
}
915909

916910
#[test]
@@ -938,7 +932,7 @@ mod test {
938932
);
939933

940934
let is_valid = super::validate_packages_dependencies(&packages);
941-
assert_eq!(is_valid, false)
935+
assert!(!is_valid)
942936
}
943937

944938
#[test]
@@ -966,7 +960,7 @@ mod test {
966960
);
967961

968962
let is_valid = super::validate_packages_dependencies(&packages);
969-
assert_eq!(is_valid, false)
963+
assert!(!is_valid)
970964
}
971965

972966
#[test]
@@ -994,6 +988,6 @@ mod test {
994988
);
995989

996990
let is_valid = super::validate_packages_dependencies(&packages);
997-
assert_eq!(is_valid, true)
991+
assert!(is_valid)
998992
}
999993
}

0 commit comments

Comments
 (0)