Skip to content

Commit

Permalink
Undo Style/SafeNavigation autocorrect
Browse files Browse the repository at this point in the history
Normally you would be able to use the safe navigation (&.) to check for missing
values and automatically run `.map` if it's set. However, it appears this
sometimes gets passed `false` instead of nil, which is breaking specs.

The code should probably be refactored, but leaving that as a future item to
reduce the scope of this PR.
  • Loading branch information
joshbuker committed Jun 14, 2024
1 parent cd958bf commit 0049d22
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,7 @@ Style/RedundantParentheses:
# This will probably be a breaking change, but should happen
Style/ReturnNilInPredicateMethodDefinition:
Enabled: false

# FIXME: Disabled due to breaking tests, should probably refactor the code instead
Style/SafeNavigation:
Enabled: false
2 changes: 1 addition & 1 deletion lib/discordrb/data/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ def bulk_delete(ids, strict = false, reason = nil)
def update_channel_data(new_data)
new_nsfw = new_data[:nsfw].is_a?(TrueClass) || new_data[:nsfw].is_a?(FalseClass) ? new_data[:nsfw] : @nsfw
# send permission_overwrite only when explicitly set
overwrites = new_data[:permission_overwrites]&.map { |_, v| v.to_hash }
overwrites = new_data[:permission_overwrites] ? new_data[:permission_overwrites].map { |_, v| v.to_hash } : nil
response = JSON.parse(API::Channel.update(@bot.token, @id,
new_data[:name] || @name,
new_data[:topic] || @topic,
Expand Down
2 changes: 1 addition & 1 deletion lib/discordrb/data/embed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def initialize(data, message)
@provider = data['provider'].nil? ? nil : EmbedProvider.new(data['provider'], self)
@thumbnail = data['thumbnail'].nil? ? nil : EmbedThumbnail.new(data['thumbnail'], self)
@author = data['author'].nil? ? nil : EmbedAuthor.new(data['author'], self)
@fields = data['fields']&.map { |field| EmbedField.new(field, self) }
@fields = data['fields'].nil? ? nil : data['fields'].map { |field| EmbedField.new(field, self) }
end
end

Expand Down

0 comments on commit 0049d22

Please sign in to comment.