Skip to content

Commit 97b3a13

Browse files
committed
Lint: Fix hardest offenses
These changes were all done manually. Also, add .git-blame-ignore-revs to make `git blame` ignore purely style changing commits.
1 parent d6e6879 commit 97b3a13

File tree

10 files changed

+39
-35
lines changed

10 files changed

+39
-35
lines changed

.git-blame-ignore-revs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# .git-blame-ignore-revs
2+
3+
# What is this file?
4+
5+
# To limit the impact of 'unimportant' bulk commits, like big a PR full of rubocop fixes, git 2.23 adds a new option to git blame.
6+
# Using --ignore-rev, or this file, one can specify a commit to be ignored by git blame.
7+
# Lines changed by the ignored commit will be attributed to the previous commit touching that line instead.
8+
# This means that even after our bulk style change, we can get back a meaningful context for the 'real' changes to our code.
9+
10+
# How do I use it?
11+
12+
# The file should contain the full (40 character) commit hashes.
13+
# Lines starting with a # are considered comments and can be used to explain what makes the given commit(s) unimportant.
14+
# Commit order in the file is not important.
15+
16+
# Lint: Fix Style/StringLiterals etc. offenses
17+
afbf222941a6afbc9ac0a4db49534fa15436ae69
18+
19+
# Lint: Fix layout offenses
20+
3db45d38aa28dbbd7830658254ec9c59c02a29e0
21+
22+
# Lint: Fix simple offenses
23+
0221a908fec6d2a55ce645c5a17a074c93957be3
24+
25+
# Move require of spec_helper into .rspec
26+
8f09a851fb6feae50769ffb5430b3f0ebe3053b4

.standard_todo.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,13 @@
22
# Remove from this list as you refactor files.
33
---
44
ignore:
5-
- lib/zendesk_api/actions.rb:
6-
- Lint/AssignmentInCondition
7-
- lib/zendesk_api/association.rb:
8-
- Lint/AssignmentInCondition
9-
- Lint/ShadowedArgument
10-
- lib/zendesk_api/associations.rb:
11-
- Lint/AssignmentInCondition
125
- lib/zendesk_api/client.rb:
136
- Style/MissingRespondToMissing
14-
- Lint/AssignmentInCondition
157
- lib/zendesk_api/resource.rb:
168
- Style/TrivialAccessors
17-
- Lint/DuplicateMethods
18-
- lib/zendesk_api/resources.rb:
19-
- Lint/AssignmentInCondition
209
- spec/core/collection_spec.rb:
2110
- Lint/ConstantDefinitionInBlock
2211
- spec/core/resource_spec.rb:
2312
- Lint/ConstantDefinitionInBlock
2413
- spec/core/spec_helper.rb:
2514
- Style/GlobalVars
26-
- Style/MixinUsage

lib/zendesk_api/actions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def save_associations
6666
self.class.associations.each do |association_data|
6767
association_name = association_data[:name]
6868

69-
next unless send("#{association_name}_used?") && association = send(association_name)
69+
next unless send("#{association_name}_used?") && (association = send(association_name))
7070

7171
inline_creation = association_data[:inline] == :create && new_record?
7272
changed = association.is_a?(Collection) || association.changed?

lib/zendesk_api/association.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def generate_path(*args)
6666
namespace[0] = @options.path || @options[:class].resource_path
6767
end
6868

69-
if id = extract_id(instance, options, original_options)
69+
if (id = extract_id(instance, options, original_options))
7070
namespace << id
7171
end
7272

@@ -106,7 +106,7 @@ def _side_load(resource, side_loads)
106106
end
107107
end
108108

109-
def side_load_from_parent_id(resource, side_loads, key)
109+
def side_load_from_parent_id(resource, side_loads, _key)
110110
key = "#{resource.class.singular_resource_name}_id"
111111

112112
resource.send("#{options.name}=", _side_load(resource, side_loads.select { |side_load|

lib/zendesk_api/associations.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ module Has
7373
# @param [Symbol] resource_name_or_class The underlying resource name or a class to get it from
7474
# @param [Hash] class_level_options The options to pass to the method definition.
7575
def has(resource_name_or_class, class_level_options = {})
76-
if klass = class_level_options.delete(:class)
76+
if (klass = class_level_options.delete(:class))
7777
resource_name = resource_name_or_class
7878
else
7979
klass = resource_name_or_class
@@ -105,9 +105,9 @@ def define_has_getter(association)
105105

106106
# find and cache association
107107
instance_association = Association.new(association.merge(parent: self))
108-
resource = if klass.respond_to?(:find) && resource_id = method_missing(association[:id_column])
108+
resource = if klass.respond_to?(:find) && (resource_id = method_missing(association[:id_column]))
109109
klass.find(@client, id: resource_id, association: instance_association)
110-
elsif found = method_missing(association[:name].to_sym)
110+
elsif (found = method_missing(association[:name].to_sym))
111111
wrap_resource(found, association, include_key: association[:include_key])
112112
elsif klass.superclass == DataResource && !association[:inline]
113113
response = @client.connection.get(instance_association.generate_path(with_parent: true))
@@ -133,7 +133,7 @@ module HasMany
133133
# @param [Symbol] resource_name_or_class The underlying resource name or class to get it from
134134
# @param [Hash] class_level_options The options to pass to the method definition.
135135
def has_many(resource_name_or_class, class_level_options = {})
136-
if klass = class_level_options.delete(:class)
136+
if (klass = class_level_options.delete(:class))
137137
resource_name = resource_name_or_class
138138
else
139139
klass = resource_name_or_class

lib/zendesk_api/client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,10 @@ def set_default_logger
245245
end
246246

247247
def add_warning_callback
248-
return unless logger = config.logger
248+
return unless (logger = config.logger)
249249

250250
insert_callback do |env|
251-
if warning = env[:response_headers]["X-Zendesk-API-Warn"]
251+
if (warning = env[:response_headers]["X-Zendesk-API-Warn"])
252252
logger.warn "WARNING: #{warning}"
253253
end
254254
end

lib/zendesk_api/resource.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,6 @@ def initialize(client, attributes = {})
7676
@attributes.clear_changes unless new_record?
7777
end
7878

79-
def self.new_from_response(client, response, includes = nil)
80-
new(client).tap do |resource|
81-
resource.handle_response(response)
82-
resource.set_includes(resource, includes, response.body) if includes
83-
resource.attributes.clear_changes
84-
end
85-
end
86-
8779
# Passes the method onto the attributes hash.
8880
# If the attributes are nested (e.g. { :tickets => { :id => 1 } }), passes the method onto the nested hash.
8981
def method_missing(*args, &)
@@ -127,7 +119,6 @@ def to_json(*args)
127119
def to_s
128120
"#{self.class.singular_resource_name}: #{attributes.inspect}"
129121
end
130-
alias_method :inspect, :to_s
131122

132123
# Compares resources by class and id. If id is nil, then by object_id
133124
def ==(other)

lib/zendesk_api/resources.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ def initialize(client, attributes = {})
10361036
end
10371037

10381038
def self.create!(client, attributes = {}, &)
1039-
if file_path = attributes.delete(:upload)
1039+
if (file_path = attributes.delete(:upload))
10401040
attributes[:upload_id] = client.apps.uploads.create!(file: file_path).id
10411041
end
10421042

spec/core/middleware/request/retry_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def runtime
8484
end
8585

8686
it "should not fail without a logger" do
87-
client.config.logger = false
87+
client.config.logger = nil
8888
client.connection.get("blergh")
8989
end
9090
end
@@ -113,7 +113,7 @@ def runtime
113113
end
114114

115115
it "should not fail without a logger" do
116-
client.config.logger = false
116+
client.config.logger = nil
117117
client.connection.get("blergh")
118118
end
119119
end

spec/core/spec_helper.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
require "vcr"
77
require "logger"
88
require "stringio"
9+
require "webmock/rspec"
910

1011
begin
1112
require "byebug"
@@ -165,5 +166,3 @@ def stub_json_request(verb, path_matcher, body = json, options = {})
165166
# In development, this helps debugging.
166167
c.allow_http_connections_when_no_cassette = true
167168
end
168-
169-
include WebMock::API

0 commit comments

Comments
 (0)