Skip to content

Commit 499c4ba

Browse files
authored
Merge pull request #297 from jcraigk/rubocop-fixes
Cleanup various Rubocop offenses
2 parents 7c93cec + b3a039d commit 499c4ba

File tree

27 files changed

+159
-281
lines changed

27 files changed

+159
-281
lines changed

.rubocop.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ Metrics/LineLength:
2222
Max: 100
2323
Style/Documentation:
2424
Enabled: false
25+
Style/ModuleFunction:
26+
Enabled: false
27+
Naming/FileName:
28+
Exclude:
29+
- lib/slack-ruby-client.rb # Required to match gemspec name

.rubocop_todo.yml

Lines changed: 4 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
# This configuration was generated by
2-
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 100`
3-
# on 2019-08-01 15:06:19 -0700 using RuboCop version 0.73.0.
2+
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 1000`
3+
# on 2019-08-20 22:22:29 -0700 using RuboCop version 0.73.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 2
10-
# Configuration parameters: AllowSafeAssignment.
11-
Lint/AssignmentInCondition:
12-
Exclude:
13-
- 'lib/slack/real_time/concurrency/async.rb'
14-
- 'lib/slack/real_time/socket.rb'
15-
169
# Offense count: 5
1710
# Configuration parameters: AllowComments.
1811
Lint/HandleExceptions:
1912
Exclude:
20-
- 'lib/slack-ruby-client.rb'
2113
- 'lib/slack/real_time/concurrency/async.rb'
14+
- 'lib/slack_ruby_client.rb'
2215
- 'spec/slack/real_time/concurrency/celluloid_spec.rb'
2316
- 'spec/slack/real_time/concurrency/eventmachine_spec.rb'
2417

@@ -63,20 +56,6 @@ Metrics/PerceivedComplexity:
6356
Exclude:
6457
- 'lib/slack/web/faraday/connection.rb'
6558

66-
# Offense count: 1
67-
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
68-
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
69-
Naming/FileName:
70-
Exclude:
71-
- 'lib/slack-ruby-client.rb'
72-
73-
# Offense count: 1
74-
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
75-
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
76-
Naming/MemoizedInstanceVariableName:
77-
Exclude:
78-
- 'lib/slack/logger.rb'
79-
8059
# Offense count: 1
8160
RSpec/AnyInstance:
8261
Exclude:
@@ -113,29 +92,6 @@ RSpec/ContextWording:
11392
- 'spec/slack/web/client_spec.rb'
11493
- 'spec/support/real_time/connected_client.rb'
11594

116-
# Offense count: 1
117-
RSpec/DescribeClass:
118-
Exclude:
119-
- 'spec/integration/integration_spec.rb'
120-
121-
# Offense count: 5
122-
# Cop supports --auto-correct.
123-
RSpec/EmptyLineAfterExampleGroup:
124-
Exclude:
125-
- 'spec/slack/web/api/endpoints/custom_specs/auth_spec.rb'
126-
- 'spec/slack/web/api/endpoints/custom_specs/chat_spec.rb'
127-
128-
# Offense count: 8
129-
# Cop supports --auto-correct.
130-
RSpec/EmptyLineAfterFinalLet:
131-
Exclude:
132-
- 'spec/slack/web/api/endpoints/custom_specs/auth_spec.rb'
133-
- 'spec/slack/web/api/endpoints/custom_specs/channels_spec.rb'
134-
- 'spec/slack/web/api/endpoints/custom_specs/chat_spec.rb'
135-
- 'spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb'
136-
- 'spec/slack/web/api/endpoints/custom_specs/groups_spec.rb'
137-
- 'spec/slack/web/api/endpoints/custom_specs/users_spec.rb'
138-
13995
# Offense count: 63
14096
# Configuration parameters: Max.
14197
RSpec/ExampleLength:
@@ -161,11 +117,6 @@ RSpec/ExampleLength:
161117
- 'spec/slack/web/client_spec.rb'
162118
- 'spec/slack/web/faraday/response/raise_error_spec.rb'
163119

164-
# Offense count: 2
165-
RSpec/ExpectInHook:
166-
Exclude:
167-
- 'spec/slack/real_time/client_spec.rb'
168-
169120
# Offense count: 16
170121
# Configuration parameters: CustomTransform, IgnoreMethods.
171122
RSpec/FilePath:
@@ -187,14 +138,6 @@ RSpec/FilePath:
187138
- 'spec/slack/web/api/endpoints/custom_specs/users_spec.rb'
188139
- 'spec/slack/web/api/errors/service_unavailable_spec.rb'
189140

190-
# Offense count: 1
191-
# Cop supports --auto-correct.
192-
# Configuration parameters: EnforcedStyle.
193-
# SupportedStyles: implicit, each, example
194-
RSpec/HookArgument:
195-
Exclude:
196-
- 'spec/slack/web/api/endpoints/custom_specs/chat_spec.rb'
197-
198141
# Offense count: 13
199142
# Configuration parameters: AssignmentOnly.
200143
RSpec/InstanceVariable:
@@ -203,7 +146,7 @@ RSpec/InstanceVariable:
203146
- 'spec/slack/real_time/client_spec.rb'
204147
- 'spec/slack/slack_spec.rb'
205148

206-
# Offense count: 68
149+
# Offense count: 66
207150
# Configuration parameters: .
208151
# SupportedStyles: have_received, receive
209152
RSpec/MessageSpies:
@@ -238,17 +181,6 @@ RSpec/MultipleExpectations:
238181
- 'spec/slack/web/api/pagination/cursor_spec.rb'
239182
- 'spec/slack/web/client_spec.rb'
240183

241-
# Offense count: 53
242-
# Configuration parameters: IgnoreSharedExamples.
243-
RSpec/NamedSubject:
244-
Exclude:
245-
- 'spec/slack/events/request_spec.rb'
246-
- 'spec/slack/messages/formatting_spec.rb'
247-
- 'spec/slack/web/api/mixins/channels_spec.rb'
248-
- 'spec/slack/web/api/mixins/groups_spec.rb'
249-
- 'spec/slack/web/api/mixins/users_spec.rb'
250-
- 'spec/slack/web/faraday/response/raise_error_spec.rb'
251-
252184
# Offense count: 32
253185
# Configuration parameters: Max.
254186
RSpec/NestedGroups:
@@ -257,31 +189,6 @@ RSpec/NestedGroups:
257189
- 'spec/slack/web/api/pagination/cursor_spec.rb'
258190
- 'spec/slack/web/client_spec.rb'
259191

260-
# Offense count: 15
261-
# Cop supports --auto-correct.
262-
# Configuration parameters: EnforcedStyle.
263-
# SupportedStyles: not_to, to_not
264-
RSpec/NotToNot:
265-
Exclude:
266-
- 'spec/slack/web/api/endpoints/custom_specs/auth_spec.rb'
267-
- 'spec/slack/web/api/endpoints/custom_specs/chat_spec.rb'
268-
- 'spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb'
269-
270-
# Offense count: 2
271-
RSpec/RepeatedDescription:
272-
Exclude:
273-
- 'spec/slack/web/api/endpoints/custom_specs/users_spec.rb'
274-
275-
# Offense count: 2
276-
RSpec/ScatteredLet:
277-
Exclude:
278-
- 'spec/integration/integration_spec.rb'
279-
280-
# Offense count: 4
281-
RSpec/ScatteredSetup:
282-
Exclude:
283-
- 'spec/integration/integration_spec.rb'
284-
285192
# Offense count: 3
286193
RSpec/SubjectStub:
287194
Exclude:
@@ -299,60 +206,3 @@ RSpec/VerifiedDoubles:
299206
- 'spec/slack/real_time/concurrency/eventmachine_spec.rb'
300207
- 'spec/slack/web/faraday/response/raise_error_spec.rb'
301208
- 'spec/support/real_time/connected_client.rb'
302-
303-
# Offense count: 1
304-
Security/Open:
305-
Exclude:
306-
- 'lib/slack/real_time/client.rb'
307-
308-
# Offense count: 2
309-
# Configuration parameters: EnforcedStyle.
310-
# SupportedStyles: inline, group
311-
Style/AccessModifierDeclarations:
312-
Exclude:
313-
- 'lib/slack/real_time/concurrency/eventmachine.rb'
314-
- 'lib/slack/real_time/socket.rb'
315-
316-
# Offense count: 6
317-
# Cop supports --auto-correct.
318-
# Configuration parameters: EnforcedStyle.
319-
# SupportedStyles: always, never
320-
Style/FrozenStringLiteralComment:
321-
Exclude:
322-
- 'spec/slack/web/api/endpoints/custom_specs/auth_spec.rb'
323-
- 'spec/slack/web/api/endpoints/custom_specs/channels_spec.rb'
324-
- 'spec/slack/web/api/endpoints/custom_specs/chat_spec.rb'
325-
- 'spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb'
326-
- 'spec/slack/web/api/endpoints/custom_specs/groups_spec.rb'
327-
- 'spec/slack/web/api/endpoints/custom_specs/users_spec.rb'
328-
329-
# Offense count: 2
330-
# Configuration parameters: MinBodyLength.
331-
Style/GuardClause:
332-
Exclude:
333-
- 'lib/slack/real_time/socket.rb'
334-
- 'lib/slack/web/faraday/response/raise_error.rb'
335-
336-
# Offense count: 3
337-
# Cop supports --auto-correct.
338-
# Configuration parameters: EnforcedStyle, Autocorrect.
339-
# SupportedStyles: module_function, extend_self
340-
Style/ModuleFunction:
341-
Exclude:
342-
- 'lib/slack/config.rb'
343-
- 'lib/slack/events/config.rb'
344-
- 'lib/slack/web/config.rb'
345-
346-
# Offense count: 1
347-
Style/MultilineTernaryOperator:
348-
Exclude:
349-
- 'spec/support/real_time/connected_client.rb'
350-
351-
# Offense count: 1
352-
# Cop supports --auto-correct.
353-
# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods.
354-
# SupportedStyles: predicate, comparison
355-
Style/NumericPredicate:
356-
Exclude:
357-
- 'spec/**/*'
358-
- 'lib/slack/real_time/client.rb'

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
### 0.14.5 (Next)
22

33
* [#293](https://github.com/slack-ruby/slack-ruby-client/pull/293): Rubocop auto-correct and comprehensive todo - [@jcraigk](https://github.com/jcraigk).
4+
* [#297](https://github.com/slack-ruby/slack-ruby-client/pull/297): Various Rubocop fixes - [@jcraigk](https://github.com/jcraigk).
5+
46
* Your contribution here.
57

68
### 0.14.4 (2019/7/28)

bin/slack

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env ruby
22
require 'gli'
3-
require 'slack-ruby-client'
3+
require 'slack_ruby_client'
44

55
include GLI::App
66

lib/slack-ruby-client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
require 'logger'
1616
begin
1717
require 'picky'
18-
rescue LoadError
18+
rescue LoadError # rubocop:disable Lint/HandleExceptions
1919
# ignore, only used in users_search
2020
end
2121
begin
2222
require 'openssl'
23-
rescue LoadError
23+
rescue LoadError # rubocop:disable Lint/HandleExceptions
2424
# Used in slack/web/config
2525
end
2626
require_relative 'slack/web/config'

lib/slack/logger.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
module Slack
55
class Logger < ::Logger
66
def self.default
7-
@logger ||= begin
8-
logger = new STDOUT
9-
logger.level = Logger::WARN
10-
logger
11-
end
7+
return @default if @default
8+
9+
logger = new STDOUT
10+
logger.level = Logger::WARN
11+
@default = logger
1212
end
1313
end
1414
end

lib/slack/real_time/client.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def run_loop
8484
@socket.connect! do |driver|
8585
driver.on :open do |event|
8686
logger.debug("#{self}##{__method__}") { event.class.name }
87-
open(event)
87+
open_event(event)
8888
callback(event, :open)
8989
end
9090

@@ -137,7 +137,7 @@ def run_ping!
137137
end
138138

139139
def run_ping?
140-
!websocket_ping.nil? && websocket_ping > 0
140+
!websocket_ping.nil? && websocket_ping.positive?
141141
end
142142

143143
def websocket_ping_timer
@@ -205,7 +205,7 @@ def send_json(data)
205205
@socket.send_data(data.to_json)
206206
end
207207

208-
def open(_event); end
208+
def open_event(_event); end
209209

210210
def close(_event)
211211
[@socket, socket_class].each do |s|

lib/slack/real_time/concurrency/async.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def connect!
8282
def disconnect!
8383
super
8484
ensure
85-
if restart = @restart
85+
if (restart = @restart)
8686
@restart = nil
8787
restart.signal
8888
end

lib/slack/real_time/concurrency/eventmachine.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ module RealTime
77
module Concurrency
88
module Eventmachine
99
class Client < Faye::WebSocket::Client
10-
attr_reader :logger
11-
protected :logger
12-
1310
def initialize(url, protocols = nil, options = {})
1411
@logger =
1512
options.fetch(:logger) || Slack::RealTime::Config.logger || Slack::Config.logger
@@ -25,6 +22,10 @@ def write(data)
2522
logger.debug("#{self.class}##{__method__}") { data }
2623
super data
2724
end
25+
26+
protected
27+
28+
attr_reader :logger
2829
end
2930

3031
class Socket < Slack::RealTime::Socket

lib/slack/real_time/socket.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ class Socket
55
attr_accessor :url
66
attr_accessor :options
77
attr_reader :driver
8-
attr_reader :logger
9-
protected :logger
108

119
def initialize(url, options = {})
1210
@url = url
@@ -80,14 +78,16 @@ def close
8078
# When you call `driver.emit(:close)`, it will typically end up calling `client.close`
8179
# which will call `@socket.close` and end up back here. In order to break this infinite
8280
# recursion, we check and set `@driver = nil` before invoking `client.close`.
83-
if driver = @driver
84-
@driver = nil
85-
driver.emit(:close)
86-
end
81+
return unless (driver = @driver)
82+
83+
@driver = nil
84+
driver.emit(:close)
8785
end
8886

8987
protected
9088

89+
attr_reader :logger
90+
9191
def addr
9292
URI(url).host
9393
end

0 commit comments

Comments
 (0)