Skip to content

Commit d6e6879

Browse files
committed
Lint: Fix harder offenses
These changes were all done with `standardrb --fix-unsafely`.
1 parent 0221a90 commit d6e6879

File tree

8 files changed

+21
-30
lines changed

8 files changed

+21
-30
lines changed

.standard_todo.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,20 @@ ignore:
77
- lib/zendesk_api/association.rb:
88
- Lint/AssignmentInCondition
99
- Lint/ShadowedArgument
10-
- Style/SafeNavigation
1110
- lib/zendesk_api/associations.rb:
1211
- Lint/AssignmentInCondition
13-
- Performance/RedundantMerge
1412
- lib/zendesk_api/client.rb:
1513
- Style/MissingRespondToMissing
1614
- Lint/AssignmentInCondition
17-
- lib/zendesk_api/collection.rb:
18-
- Performance/RedundantMerge
19-
- Style/SafeNavigation
20-
- lib/zendesk_api/middleware/request/retry.rb:
21-
- Style/SafeNavigation
2215
- lib/zendesk_api/resource.rb:
2316
- Style/TrivialAccessors
2417
- Lint/DuplicateMethods
2518
- lib/zendesk_api/resources.rb:
2619
- Lint/AssignmentInCondition
2720
- spec/core/collection_spec.rb:
2821
- Lint/ConstantDefinitionInBlock
29-
- Lint/InheritException
3022
- spec/core/resource_spec.rb:
3123
- Lint/ConstantDefinitionInBlock
3224
- spec/core/spec_helper.rb:
3325
- Style/GlobalVars
3426
- Style/MixinUsage
35-
- spec/live/target_spec.rb:
36-
- Lint/BooleanSymbol
37-
- spec/macros/resource_macros.rb:
38-
- Performance/RedundantMerge

lib/zendesk_api/association.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def extract_parent_id(parent_class, instance, options, original_options)
178178

179179
def extract_id(instance, options, original_options)
180180
if options[:with_id] && !@options[:class].ancestors.include?(SingularResource)
181-
if instance && instance.id
181+
if instance&.id
182182
instance.id
183183
elsif options[:id]
184184
original_options.delete(:id) || original_options.delete("id")

lib/zendesk_api/associations.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def has(resource_name_or_class, class_level_options = {})
8181
end
8282

8383
class_level_association = build_association(klass, resource_name, class_level_options)
84-
class_level_association.merge!(singular: true, id_column: "#{resource_name}_id")
84+
class_level_association[:singular] = true
85+
class_level_association[:id_column] = "#{resource_name}_id"
8586

8687
associations << class_level_association
8788

@@ -140,7 +141,8 @@ def has_many(resource_name_or_class, class_level_options = {})
140141
end
141142

142143
class_level_association = build_association(klass, resource_name, class_level_options)
143-
class_level_association.merge!(singular: false, id_column: "#{resource_name}_ids")
144+
class_level_association[:singular] = false
145+
class_level_association[:id_column] = "#{resource_name}_ids"
144146

145147
associations << class_level_association
146148

lib/zendesk_api/collection.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def initialize(client, resource, options = {})
6161
end
6262

6363
args << {} unless args.last.is_a?(Hash)
64-
args.last.merge!(association: @association)
64+
args.last[:association] = @association
6565

6666
@resource_class.send(deferrable, @client, *args)
6767
end
@@ -161,7 +161,7 @@ def path
161161
def fetch!(reload = false)
162162
if @resources && (!@fetchable || !reload)
163163
return @resources
164-
elsif association && association.options.parent && association.options.parent.new_record?
164+
elsif association&.options&.parent&.new_record?
165165
return (@resources = [])
166166
end
167167

@@ -389,7 +389,7 @@ def get_response(path)
389389
@client.connection.send(@verb || "get", path) do |req|
390390
opts = @options.delete_if { |_, v| v.nil? }
391391

392-
req.params.merge!(include: @includes.join(",")) if @includes.any?
392+
req.params[:include] = @includes.join(",") if @includes.any?
393393

394394
if %w[put post].include?(@verb.to_s)
395395
req.body = opts
@@ -444,7 +444,7 @@ def wrap_resource(res, with_association = with_association?)
444444
@resource_class.new(@client, res)
445445
else
446446
res = {id: res}
447-
res.merge!(association: @association) if with_association
447+
res[:association] = @association if with_association
448448
@resource_class.new(@client, res)
449449
end
450450
end
@@ -464,7 +464,8 @@ def array_method(name, ...)
464464
# If you call client.tickets.foo - and foo is not an attribute nor an association, it ends up here, as a new collection
465465
def next_collection(name, *args, &)
466466
opts = args.last.is_a?(Hash) ? args.last : {}
467-
opts.merge!(collection_path: [*@collection_path, name], page: nil)
467+
opts[:collection_path] = [*@collection_path, name]
468+
opts[:page] = nil
468469
# Why `page: nil`?
469470
# when you do client.tickets.fetch followed by client.tickets.foos => the request to /tickets/foos will
470471
# have the options page set to whatever the last options were for the tickets collection

lib/zendesk_api/middleware/request/retry.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ def call(env)
3434

3535
if exception_happened
3636
seconds_left = DEFAULT_RETRY_AFTER.to_i
37-
@logger.warn "An exception happened, waiting #{seconds_left} seconds... #{e}" if @logger
37+
@logger&.warn "An exception happened, waiting #{seconds_left} seconds... #{e}"
3838
else
3939
seconds_left = (response.env[:response_headers][:retry_after] || DEFAULT_RETRY_AFTER).to_i
4040
end
4141

42-
@logger.warn "You have been rate limited. Retrying in #{seconds_left} seconds..." if @logger
42+
@logger&.warn "You have been rate limited. Retrying in #{seconds_left} seconds..."
4343

4444
seconds_left.times do |i|
4545
sleep 1
4646
time_left = seconds_left - i
47-
@logger.warn "#{time_left}..." if time_left > 0 && time_left % 5 == 0 && @logger
47+
@logger&.warn "#{time_left}..." if time_left > 0 && time_left % 5 == 0
4848
end
4949

50-
@logger.warn "" if @logger
50+
@logger&.warn ""
5151

5252
@app.call(original_env)
5353
else

spec/core/collection_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@
274274
end
275275

276276
it "should retry from the same page" do
277-
class SearchError < Exception; end
277+
class SearchError < RuntimeError; end
278278

279279
expect do |b|
280280
client.insert_callback do |env|

spec/live/target_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def valid_attributes
1010
}
1111
end
1212

13-
it_should_be_readable :targets, create: :true
13+
it_should_be_readable :targets, create: true
1414
it_should_be_creatable
1515
it_should_be_updatable :active, false
1616
it_should_be_deletable

spec/macros/resource_macros.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def it_should_be_creatable(options = {})
3232

3333
it "should be findable", unless: metadata[:not_findable] do
3434
options = default_options
35-
options.merge!(id: @creatable_object.id) unless described_class.ancestors.include?(ZendeskAPI::SingularResource)
35+
options[:id] = @creatable_object.id unless described_class.ancestors.include?(ZendeskAPI::SingularResource)
3636
expect(described_class.find(client, options)).to eq(@creatable_object)
3737
end
3838

@@ -76,7 +76,7 @@ def it_should_be_updatable(attribute, value = "TESTDATA", extra = {})
7676

7777
it "should be findable", unless: metadata[:not_findable] do
7878
options = default_options
79-
options.merge!(id: @updatable_object.id) unless described_class.ancestors.include?(ZendeskAPI::SingularResource)
79+
options[:id] = @updatable_object.id unless described_class.ancestors.include?(ZendeskAPI::SingularResource)
8080
expect(described_class.find(client, options)).to eq(@updatable_object)
8181
end
8282
end
@@ -108,7 +108,7 @@ def it_should_be_deletable(options = {})
108108
expect(@deletable_object.destroyed?).to be(true)
109109
if (!options.key?(:find) || options[:find]) && !example.metadata[:not_findable]
110110
opts = default_options
111-
opts.merge!(id: @deletable_object.id) unless described_class.ancestors.include?(ZendeskAPI::SingularResource)
111+
opts[:id] = @deletable_object.id unless described_class.ancestors.include?(ZendeskAPI::SingularResource)
112112
obj = described_class.find(client, opts)
113113

114114
if options[:find]
@@ -169,7 +169,7 @@ def it_should_be_readable(*args)
169169

170170
if described_class.respond_to?(:find) && !example.metadata[:not_findable]
171171
options = default_options
172-
options.merge!(id: object.id) unless described_class.ancestors.include?(ZendeskAPI::SingularResource)
172+
options[:id] = object.id unless described_class.ancestors.include?(ZendeskAPI::SingularResource)
173173
expect(described_class.find(client, options)).to_not be_nil
174174
end
175175
end

0 commit comments

Comments
 (0)