Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extract_version_from_yarn_lock unwrap errors #1492

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions qlty-cli/src/initializer/scanner/package_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ impl NodePackageFile {
plugin_name: &str,
) -> Result<String> {
let package_file_data = serde_json::from_str::<Value>(package_file_contents)?;
let package_file_data = package_file_data.as_object().unwrap();
let package_file_data = if let Some(package_data) = package_file_data.as_object() {
package_data
} else {
bail!("Invalid package file data");
};

let package_file_version = Self::package_file_version(plugin_name, package_file_data)?;

Expand All @@ -99,9 +103,11 @@ impl NodePackageFile {
let mut tokens = line.split_whitespace();

if version_on_next_line {
tokens.next().unwrap(); // first token is just "version"
tokens.next(); // first token is just "version"

return Ok(tokens.next().unwrap().replace('"', ""));
if let Some(version) = tokens.next() {
return Ok(version.replace('"', ""));
}
}

let potential_package_name = tokens.next().unwrap_or_default().replace([':', '"'], "");
Expand Down
Loading