diff --git a/npm_and_yarn/lib/dependabot/npm_and_yarn/version.rb b/npm_and_yarn/lib/dependabot/npm_and_yarn/version.rb index 10c05b1df3..7973baf2bb 100644 --- a/npm_and_yarn/lib/dependabot/npm_and_yarn/version.rb +++ b/npm_and_yarn/lib/dependabot/npm_and_yarn/version.rb @@ -63,8 +63,9 @@ def self.semver_for(version) sig { override.params(version: VersionParameter).void } def initialize(version) version = clean_version(version) + @version_string = T.let(version.to_s, String) - version = version.gsub(/^v/, "") if version.is_a?(String) + @build_info = T.let(nil, T.nilable(String)) version, @build_info = version.to_s.split("+") if version.to_s.include?("+") @@ -74,10 +75,13 @@ def initialize(version) sig { params(version: VersionParameter).returns(VersionParameter) } def clean_version(version) - # Check if version is a string before attempting to match - # Matches @ followed by x.y.z (digits separated by dots) - if version.is_a?(String) && (match = version.match(/@(\d+\.\d+\.\d+)/)) - return match[1] # Just "4.5.3" + if version.is_a?(String) + # Check if version is a string before attempting to match + # Matches @ followed by x.y.z (digits separated by dots) + if (match = version.match(/@(\d+\.\d+\.\d+)/)) + version = match[1] # Just "4.5.3" + end + version = version.gsub(/^v/, "") if version.is_a?(String) end # If version is not a string or no match found, return original version