Skip to content

Commit

Permalink
Merge pull request #297 from jcraigk/rubocop-fixes
Browse files Browse the repository at this point in the history
Cleanup various Rubocop offenses
  • Loading branch information
dblock authored Aug 23, 2019
2 parents 7c93cec + b3a039d commit 499c4ba
Show file tree
Hide file tree
Showing 27 changed files with 159 additions and 281 deletions.
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ Metrics/LineLength:
Max: 100
Style/Documentation:
Enabled: false
Style/ModuleFunction:
Enabled: false
Naming/FileName:
Exclude:
- lib/slack-ruby-client.rb # Required to match gemspec name
158 changes: 4 additions & 154 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 100`
# on 2019-08-01 15:06:19 -0700 using RuboCop version 0.73.0.
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 1000`
# on 2019-08-20 22:22:29 -0700 using RuboCop version 0.73.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
# Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition:
Exclude:
- 'lib/slack/real_time/concurrency/async.rb'
- 'lib/slack/real_time/socket.rb'

# Offense count: 5
# Configuration parameters: AllowComments.
Lint/HandleExceptions:
Exclude:
- 'lib/slack-ruby-client.rb'
- 'lib/slack/real_time/concurrency/async.rb'
- 'lib/slack_ruby_client.rb'
- 'spec/slack/real_time/concurrency/celluloid_spec.rb'
- 'spec/slack/real_time/concurrency/eventmachine_spec.rb'

Expand Down Expand Up @@ -63,20 +56,6 @@ Metrics/PerceivedComplexity:
Exclude:
- 'lib/slack/web/faraday/connection.rb'

# Offense count: 1
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# 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
Naming/FileName:
Exclude:
- 'lib/slack-ruby-client.rb'

# Offense count: 1
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
Naming/MemoizedInstanceVariableName:
Exclude:
- 'lib/slack/logger.rb'

# Offense count: 1
RSpec/AnyInstance:
Exclude:
Expand Down Expand Up @@ -113,29 +92,6 @@ RSpec/ContextWording:
- 'spec/slack/web/client_spec.rb'
- 'spec/support/real_time/connected_client.rb'

# Offense count: 1
RSpec/DescribeClass:
Exclude:
- 'spec/integration/integration_spec.rb'

# Offense count: 5
# Cop supports --auto-correct.
RSpec/EmptyLineAfterExampleGroup:
Exclude:
- 'spec/slack/web/api/endpoints/custom_specs/auth_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/chat_spec.rb'

# Offense count: 8
# Cop supports --auto-correct.
RSpec/EmptyLineAfterFinalLet:
Exclude:
- 'spec/slack/web/api/endpoints/custom_specs/auth_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/channels_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/chat_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/groups_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/users_spec.rb'

# Offense count: 63
# Configuration parameters: Max.
RSpec/ExampleLength:
Expand All @@ -161,11 +117,6 @@ RSpec/ExampleLength:
- 'spec/slack/web/client_spec.rb'
- 'spec/slack/web/faraday/response/raise_error_spec.rb'

# Offense count: 2
RSpec/ExpectInHook:
Exclude:
- 'spec/slack/real_time/client_spec.rb'

# Offense count: 16
# Configuration parameters: CustomTransform, IgnoreMethods.
RSpec/FilePath:
Expand All @@ -187,14 +138,6 @@ RSpec/FilePath:
- 'spec/slack/web/api/endpoints/custom_specs/users_spec.rb'
- 'spec/slack/web/api/errors/service_unavailable_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: implicit, each, example
RSpec/HookArgument:
Exclude:
- 'spec/slack/web/api/endpoints/custom_specs/chat_spec.rb'

# Offense count: 13
# Configuration parameters: AssignmentOnly.
RSpec/InstanceVariable:
Expand All @@ -203,7 +146,7 @@ RSpec/InstanceVariable:
- 'spec/slack/real_time/client_spec.rb'
- 'spec/slack/slack_spec.rb'

# Offense count: 68
# Offense count: 66
# Configuration parameters: .
# SupportedStyles: have_received, receive
RSpec/MessageSpies:
Expand Down Expand Up @@ -238,17 +181,6 @@ RSpec/MultipleExpectations:
- 'spec/slack/web/api/pagination/cursor_spec.rb'
- 'spec/slack/web/client_spec.rb'

# Offense count: 53
# Configuration parameters: IgnoreSharedExamples.
RSpec/NamedSubject:
Exclude:
- 'spec/slack/events/request_spec.rb'
- 'spec/slack/messages/formatting_spec.rb'
- 'spec/slack/web/api/mixins/channels_spec.rb'
- 'spec/slack/web/api/mixins/groups_spec.rb'
- 'spec/slack/web/api/mixins/users_spec.rb'
- 'spec/slack/web/faraday/response/raise_error_spec.rb'

# Offense count: 32
# Configuration parameters: Max.
RSpec/NestedGroups:
Expand All @@ -257,31 +189,6 @@ RSpec/NestedGroups:
- 'spec/slack/web/api/pagination/cursor_spec.rb'
- 'spec/slack/web/client_spec.rb'

# Offense count: 15
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: not_to, to_not
RSpec/NotToNot:
Exclude:
- 'spec/slack/web/api/endpoints/custom_specs/auth_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/chat_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb'

# Offense count: 2
RSpec/RepeatedDescription:
Exclude:
- 'spec/slack/web/api/endpoints/custom_specs/users_spec.rb'

# Offense count: 2
RSpec/ScatteredLet:
Exclude:
- 'spec/integration/integration_spec.rb'

# Offense count: 4
RSpec/ScatteredSetup:
Exclude:
- 'spec/integration/integration_spec.rb'

# Offense count: 3
RSpec/SubjectStub:
Exclude:
Expand All @@ -299,60 +206,3 @@ RSpec/VerifiedDoubles:
- 'spec/slack/real_time/concurrency/eventmachine_spec.rb'
- 'spec/slack/web/faraday/response/raise_error_spec.rb'
- 'spec/support/real_time/connected_client.rb'

# Offense count: 1
Security/Open:
Exclude:
- 'lib/slack/real_time/client.rb'

# Offense count: 2
# Configuration parameters: EnforcedStyle.
# SupportedStyles: inline, group
Style/AccessModifierDeclarations:
Exclude:
- 'lib/slack/real_time/concurrency/eventmachine.rb'
- 'lib/slack/real_time/socket.rb'

# Offense count: 6
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, never
Style/FrozenStringLiteralComment:
Exclude:
- 'spec/slack/web/api/endpoints/custom_specs/auth_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/channels_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/chat_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/groups_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/users_spec.rb'

# Offense count: 2
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'lib/slack/real_time/socket.rb'
- 'lib/slack/web/faraday/response/raise_error.rb'

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, Autocorrect.
# SupportedStyles: module_function, extend_self
Style/ModuleFunction:
Exclude:
- 'lib/slack/config.rb'
- 'lib/slack/events/config.rb'
- 'lib/slack/web/config.rb'

# Offense count: 1
Style/MultilineTernaryOperator:
Exclude:
- 'spec/support/real_time/connected_client.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods.
# SupportedStyles: predicate, comparison
Style/NumericPredicate:
Exclude:
- 'spec/**/*'
- 'lib/slack/real_time/client.rb'
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
### 0.14.5 (Next)

* [#293](https://github.com/slack-ruby/slack-ruby-client/pull/293): Rubocop auto-correct and comprehensive todo - [@jcraigk](https://github.com/jcraigk).
* [#297](https://github.com/slack-ruby/slack-ruby-client/pull/297): Various Rubocop fixes - [@jcraigk](https://github.com/jcraigk).

* Your contribution here.

### 0.14.4 (2019/7/28)
Expand Down
2 changes: 1 addition & 1 deletion bin/slack
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
require 'gli'
require 'slack-ruby-client'
require 'slack_ruby_client'

include GLI::App

Expand Down
4 changes: 2 additions & 2 deletions lib/slack-ruby-client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
require 'logger'
begin
require 'picky'
rescue LoadError
rescue LoadError # rubocop:disable Lint/HandleExceptions
# ignore, only used in users_search
end
begin
require 'openssl'
rescue LoadError
rescue LoadError # rubocop:disable Lint/HandleExceptions
# Used in slack/web/config
end
require_relative 'slack/web/config'
Expand Down
10 changes: 5 additions & 5 deletions lib/slack/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
module Slack
class Logger < ::Logger
def self.default
@logger ||= begin
logger = new STDOUT
logger.level = Logger::WARN
logger
end
return @default if @default

logger = new STDOUT
logger.level = Logger::WARN
@default = logger
end
end
end
6 changes: 3 additions & 3 deletions lib/slack/real_time/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def run_loop
@socket.connect! do |driver|
driver.on :open do |event|
logger.debug("#{self}##{__method__}") { event.class.name }
open(event)
open_event(event)
callback(event, :open)
end

Expand Down Expand Up @@ -137,7 +137,7 @@ def run_ping!
end

def run_ping?
!websocket_ping.nil? && websocket_ping > 0
!websocket_ping.nil? && websocket_ping.positive?
end

def websocket_ping_timer
Expand Down Expand Up @@ -205,7 +205,7 @@ def send_json(data)
@socket.send_data(data.to_json)
end

def open(_event); end
def open_event(_event); end

def close(_event)
[@socket, socket_class].each do |s|
Expand Down
2 changes: 1 addition & 1 deletion lib/slack/real_time/concurrency/async.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def connect!
def disconnect!
super
ensure
if restart = @restart
if (restart = @restart)
@restart = nil
restart.signal
end
Expand Down
7 changes: 4 additions & 3 deletions lib/slack/real_time/concurrency/eventmachine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ module RealTime
module Concurrency
module Eventmachine
class Client < Faye::WebSocket::Client
attr_reader :logger
protected :logger

def initialize(url, protocols = nil, options = {})
@logger =
options.fetch(:logger) || Slack::RealTime::Config.logger || Slack::Config.logger
Expand All @@ -25,6 +22,10 @@ def write(data)
logger.debug("#{self.class}##{__method__}") { data }
super data
end

protected

attr_reader :logger
end

class Socket < Slack::RealTime::Socket
Expand Down
12 changes: 6 additions & 6 deletions lib/slack/real_time/socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class Socket
attr_accessor :url
attr_accessor :options
attr_reader :driver
attr_reader :logger
protected :logger

def initialize(url, options = {})
@url = url
Expand Down Expand Up @@ -80,14 +78,16 @@ def close
# When you call `driver.emit(:close)`, it will typically end up calling `client.close`
# which will call `@socket.close` and end up back here. In order to break this infinite
# recursion, we check and set `@driver = nil` before invoking `client.close`.
if driver = @driver
@driver = nil
driver.emit(:close)
end
return unless (driver = @driver)

@driver = nil
driver.emit(:close)
end

protected

attr_reader :logger

def addr
URI(url).host
end
Expand Down
13 changes: 6 additions & 7 deletions lib/slack/web/faraday/response/raise_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ module Faraday
module Response
class RaiseError < ::Faraday::Response::Middleware
def on_complete(env)
if env.status == 429
raise Slack::Web::Api::Errors::TooManyRequestsError, env.response
elsif (body = env.body) && !body['ok']
error_message =
body['error'] || body['errors'].map { |message| message['error'] }.join(',')
raise Slack::Web::Api::Errors::SlackError.new(error_message, env.response)
end
raise Slack::Web::Api::Errors::TooManyRequestsError, env.response if env.status == 429
return unless (body = env.body) && !body['ok']

error_message =
body['error'] || body['errors'].map { |message| message['error'] }.join(',')
raise Slack::Web::Api::Errors::SlackError.new(error_message, env.response)
end
end
end
Expand Down
Loading

0 comments on commit 499c4ba

Please sign in to comment.