Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions lib/i18n/tasks/scanners/prism_scanners/nodes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ def scope
return nil if @options.nil?
return nil unless @options["scope"]

fail(ScopeError, "Could not process scope") if @options.key?("scope") && Array(@options["scope"]).empty?
fail(ScopeError, "Could not process scope") if @options.key?("scope") && (Array(@options["scope"]).empty? || !Array(@options["scope"]).all? { |s| s.is_a?(String) || s.is_a?(Symbol) })

Array(@options["scope"]).compact.map(&:to_s).join(".")
Array(@options["scope"]).join(".")
end

def occurrence(file_path)
Expand Down
16 changes: 13 additions & 3 deletions spec/prism_scanner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -594,18 +594,28 @@ def what
it "handles scope" do
source = <<~RUBY
scope = 'special.events'
# These should be detected
t('scope_string', scope: 'events.descriptions')
I18n.t('scope_array', scope: ['events', 'titles'])
I18n.t(model.key, **translation_options(model))
I18n.t("success", scope: scope)
I18n.t("scope_array_symbol", scope: %i[events descriptions])
I18n.t("scope_array_words", scope: %w[events descriptions])

# Cannot handle, should ignore
I18n.t("scope_with_known_variable", scope: ["this", "that", scope])
I18n.t("scope_with_unknown", scope: ["this", "that", unknown, "other"])
I18n.t(model.key, **translation_options(model))
I18n.t("success", scope: scope)
RUBY

occurrences = process_string("scope.rb", source)

expect(occurrences.map(&:first).uniq).to match_array(
%w[events.descriptions.scope_string events.titles.scope_array events.descriptions.scope_array_symbol events.descriptions.scope_array_words]
%w[
events.descriptions.scope_string
events.titles.scope_array
events.descriptions.scope_array_symbol
events.descriptions.scope_array_words
]
)
end
end
Expand Down