Skip to content

Commit

Permalink
adding types
Browse files Browse the repository at this point in the history
  • Loading branch information
robaiken committed Feb 3, 2025
1 parent 4ebe833 commit 57f1330
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions elm/lib/dependabot/elm/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,14 @@ def elm_json_dependencies

DEPENDENCY_TYPES.each do |dep_type|
if repo_type == "application"
dependencies_hash = T.cast(T.must(parsed_elm_json).fetch(dep_type, {}), T::Hash[String, T.untyped])
T.cast(dependencies_hash.fetch("direct", {}), T::Hash[String, String]).each do |name, req|
dependencies_hash = T.cast(T.must(parsed_elm_json).fetch(dep_type, {}),
T::Hash[String, T::Hash[String, String]])
dependencies_hash.fetch("direct", {}).each do |name, req|
dependency_set << build_elm_json_dependency(
name: name, group: dep_type, requirement: req, direct: true
)
end
T.cast(dependencies_hash.fetch("indirect", {}), T::Hash[String, String]).each do |name, req|
dependencies_hash.fetch("indirect", {}).each do |name, req|
dependency_set << build_elm_json_dependency(
name: name, group: dep_type, requirement: req, direct: false
)
Expand Down Expand Up @@ -144,11 +145,11 @@ def elm_json_dependencies
end
def build_elm_json_dependency(name:, group:, requirement:, direct:)
requirements = [{
requirement: requirement,
groups: [group],
source: nil,
file: MANIFEST_FILE
}]
requirement: requirement,
groups: [group],
source: nil,
file: MANIFEST_FILE
}]

Dependency.new(
name: name,
Expand Down Expand Up @@ -183,9 +184,10 @@ def version_for(version_requirement)
req.requirements.first.last
end

sig { returns(T.nilable(T::Hash[String, T.untyped])) }
sig { returns(T.nilable(T::Hash[String, T.any(String, T::Boolean, NilClass)])) }
def parsed_elm_json
@parsed_elm_json ||= T.let(JSON.parse(T.must(T.must(elm_json).content)), T.nilable(T::Hash[String, T.untyped]))
@parsed_elm_json ||= T.let(JSON.parse(T.must(T.must(elm_json).content)),
T.nilable(T::Hash[String, T.any(String, T::Boolean, NilClass)]))
rescue JSON::ParserError
raise Dependabot::DependencyFileNotParseable, elm_json&.path || MANIFEST_FILE
end
Expand Down

0 comments on commit 57f1330

Please sign in to comment.