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

Code before:

    if !config.display_private
        && package_json.get("private").and_then(json::Value::as_bool) == Some(true)
    {
        return None;
    }

    let raw_version = package_json.get("version")?.as_str()?;
    if raw_version == "null" {
        return None;
    };

    let formatted_version = format_version(raw_version, config.version_format)?;
    if formatted_version == "v0.0.0-development" || formatted_version.starts_with("v0.0.0-semantic")
    {
        return Some("semantic".to_string());
    };

    Some(formatted_version)
}

fn get_jsr_package_version(context: &Context, config: &PackageConfig) -> Option<String> {
    ["jsr.json", "jsr.jsonc", "deno.json", "deno.jsonc"]
        .iter()
        .find_map(|file| {
            let contents = context.read_file_from_pwd(file)?;
            let json_content: json::Value = if file.ends_with(".jsonc") {
                jsonc_parser::parse_to_serde_value(&contents, &Default::default()).ok()??
            } else {
                json::from_str(&contents).ok()?
            };

            let raw_version = json_content.get("version")?.as_str()?;
            format_version(raw_version, config.version_format)
        })
}

fn get_poetry_version(pyproject: &toml::Table) -> Option<&str> {
    pyproject
        .get("tool")?
        .get("poetry")?
        .get("version")?
        .as_str()
}

fn get_pep621_version(pyproject: &toml::Table) -> Option<&str> {
    pyproject.get("project")?.get("version")?.as_str()
}

fn get_pyproject_version(context: &Context, config: &PackageConfig) -> Option<String> {
    let file_contents = context.read_file_from_pwd("pyproject.toml")?;

Review comment (suggestion):
It's likely best to stop after finding the first file, whether it parses correctly or not:
```suggestion
        .find_map(|file| context.read_file_from_pwd(file))
        .and_then(|contents| {
```

Code after:

    if !config.display_private
        && package_json.get("private").and_then(json::Value::as_bool) == Some(true)
    {
        return None;
    }

    let raw_version = package_json.get("version")?.as_str()?;
    if raw_version == "null" {
        return None;
    };

    let formatted_version = format_version(raw_version, config.version_format)?;
    if formatted_version == "v0.0.0-development" || formatted_version.starts_with("v0.0.0-semantic")
    {
        return Some("semantic".to_string());
    };

    Some(formatted_version)
}

fn get_jsr_package_version(context: &Context, config: &PackageConfig) -> Option<String> {
    let (filename, contents) = ["deno.json", "deno.jsonc", "jsr.json", "jsr.jsonc"]
        .iter()
        .find_map(|filename| {
            context
                .read_file_from_pwd(filename)
                .map(|contents| (filename, contents))
        })?;

    let json_content: json::Value = if filename.ends_with(".jsonc") {
        jsonc_parser::parse_to_serde_value(&contents, &Default::default()).ok()??
    } else {
        json::from_str(&contents).ok()?
    };

    let raw_version = json_content.get("version")?.as_str()?;
    format_version(raw_version, config.version_format)
}

fn get_poetry_version(pyproject: &toml::Table) -> Option<&str> {
    pyproject
        .get("tool")?
        .get("poetry")?
        .get("version")?
        .as_str()
}

fn get_pep621_version(pyproject: &toml::Table) -> Option<&str> {
    pyproject.get("project")?.get("version")?.as_str()
}