Repository: starship/starship
File: src/modules/nodejs.rs (Rust)

Code before:
            })
            .parse(None, Some(context))
    });

    module.set_segments(match parsed {
        Ok(segments) => segments,
        Err(error) => {
            log::warn!("Error in module `nodejs`:\n{}", error);
            return None;
        }
    });

    Some(module)
}

fn get_engines_version(context: &Context) -> Option<String> {
    let json_str = context.read_file_from_pwd("package.json")?;
    let package_json: json::Value = json::from_str(&json_str).ok()?;
    let raw_version = package_json.get("engines")?.get("node")?.as_str()?;
    Some(raw_version.to_string())
}

fn check_engines_version(nodejs_version: Option<&String>, engines_version: Option<String>) -> bool {
    if engines_version.is_none() || nodejs_version.is_none() {
        return true;
    }
    let r = match VersionReq::parse(&engines_version.unwrap()) {
        Ok(r) => r,
        Err(_e) => return true,
    };
    let re = Regex::new(r"\d+\.\d+\.\d+").unwrap();
    let version = re
        .captures(nodejs_version.unwrap())
        .unwrap()
        .get(0)
        .unwrap()
        .as_str();
    let v = match Version::parse(version) {
        Ok(v) => v,
        Err(_e) => return true,
    };
    r.matches(&v)
}

#[cfg(test)]
mod tests {
    use crate::test::ModuleRenderer;
    use nu_ansi_term::Color;
    use std::fs::{self, File};
    use std::io;
    use std::io::Write;

Review comment (refactor):
I would prefer not calling `unwrap` unless strictly necessary to avoid issue in case of potential refactorings, Perhaps use something like this?

```suggestion
    let (nodejs_version, engines_version) = match (nodejs_version, engines_version) {
        (Some(nv), Some(ev)) => (nv, ev),
        _ => return true,
    };
```

Code after:
            })
            .parse(None, Some(context))
    });

    module.set_segments(match parsed {
        Ok(segments) => segments,
        Err(error) => {
            log::warn!("Error in module `nodejs`:\n{}", error);
            return None;
        }
    });

    Some(module)
}

fn get_engines_version(context: &Context) -> Option<String> {
    let json_str = context.read_file_from_pwd("package.json")?;
    let package_json: json::Value = json::from_str(&json_str).ok()?;
    let raw_version = package_json.get("engines")?.get("node")?.as_str()?;
    Some(raw_version.to_string())
}

fn check_engines_version(nodejs_version: Option<&str>, engines_version: Option<String>) -> bool {
    let (nodejs_version, engines_version) = match (nodejs_version, engines_version) {
        (Some(nv), Some(ev)) => (nv, ev),
        _ => return true,
    };
    let r = match VersionReq::parse(&engines_version) {
        Ok(r) => r,
        Err(_e) => return true,
    };
    let re = Regex::new(r"\d+\.\d+\.\d+").unwrap();
    let version = re
        .captures(nodejs_version)
        .unwrap()
        .get(0)
        .unwrap()
        .as_str();
    let v = match Version::parse(version) {
        Ok(v) => v,
        Err(_e) => return true,
    };
    r.matches(&v)
}

#[cfg(test)]
mod tests {
    use crate::test::ModuleRenderer;
    use nu_ansi_term::Color;
    use std::fs::{self, File};
    use std::io;