mirror of
https://github.com/sharkdp/bat
synced 2026-08-07 19:31:42 +00:00
Reduce nesting in if blocks by short circuiting
This commit is contained in:
committed by
Martin Nordholts
parent
9124271eaf
commit
372e42f350
+7
-10
@@ -100,17 +100,14 @@ pub fn get_languages(config: &Config) -> Result<String> {
|
||||
// Also skip if the 'extension' contains another real extension, likely
|
||||
// that is a full match file name like 'CMakeLists.txt' and 'Cargo.lock'
|
||||
if extension.starts_with('.') || Path::new(extension).extension().is_some() {
|
||||
true
|
||||
} else {
|
||||
let test_file = Path::new("test").with_extension(extension);
|
||||
let syntax_in_set = assets
|
||||
.get_syntax_for_file_name(test_file, &config.syntax_mapping)
|
||||
.unwrap(); // safe since .get_syntaxes() above worked
|
||||
match syntax_in_set {
|
||||
Some(syntax_in_set) => syntax_in_set.syntax.name == lang_name,
|
||||
None => false,
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
let test_file = Path::new("test").with_extension(extension);
|
||||
let syntax_in_set = assets
|
||||
.get_syntax_for_file_name(test_file, &config.syntax_mapping)
|
||||
.unwrap(); // safe since .get_syntaxes() above worked
|
||||
matches!(syntax_in_set, Some(syntax_in_set) if syntax_in_set.syntax.name == lang_name)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user