Skip to content

Commit

Permalink
Remove/fix unnecessary rubocop default overrides/exclusions
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Mar 6, 2019
1 parent c6729ce commit 775417d
Show file tree
Hide file tree
Showing 41 changed files with 132 additions and 209 deletions.
82 changes: 4 additions & 78 deletions rb/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Layout/SpaceInsideHashLiteralBraces:
Style/BracesAroundHashParameters:
EnforcedStyle: context_dependent

Style/BlockDelimiters:
EnforcedStyle: braces_for_chaining

Style/Alias:
EnforcedStyle: prefer_alias_method

Expand Down Expand Up @@ -43,50 +46,37 @@ Naming/UncommunicativeMethodParamName:
- id
- io

# These need to be fixed
Style/MutableConstant:
Exclude:
- 'lib/selenium/webdriver/common/socket_poller.rb'
- 'lib/selenium/webdriver/remote/legacy_bridge.rb'
- 'lib/selenium/webdriver/remote/w3c_bridge.rb'

Style/CommentedKeyword:
Enabled: false

# TODO: Refactor Chrome::Bridge#create_capabilities
Metrics/PerceivedComplexity:
Max: 11
Exclude:
- 'lib/selenium/webdriver/chrome/legacy_bridge.rb'
- 'lib/selenium/webdriver/chrome/driver.rb'
- 'lib/selenium/webdriver/remote/w3c/capabilities.rb'

Metrics/CyclomaticComplexity:
Max: 9
Exclude:
- 'lib/selenium/webdriver/chrome/legacy_bridge.rb'
- 'lib/selenium/webdriver/chrome/driver.rb'
- 'lib/selenium/webdriver/common/driver.rb'
- 'lib/selenium/webdriver/remote/w3c/capabilities.rb'
- 'spec/integration/selenium/webdriver/spec_support/test_environment.rb'

Metrics/ClassLength:
Max: 140
Exclude:
- 'lib/selenium/webdriver/firefox/profile.rb'
- 'lib/selenium/webdriver/remote/legacy_bridge.rb'
- 'lib/selenium/webdriver/remote/capabilities.rb'
- 'lib/selenium/webdriver/remote/oss/bridge.rb'
- 'lib/selenium/webdriver/remote/w3c_bridge.rb'
- 'lib/selenium/webdriver/remote/w3c/capabilities.rb'
- 'lib/selenium/webdriver/remote/w3c/bridge.rb'
- 'lib/selenium/webdriver/remote/w3c/capabilities.rb'
- 'spec/integration/selenium/webdriver/spec_support/test_environment.rb'

Metrics/AbcSize:
Max: 33
Exclude:
- 'lib/selenium/webdriver/chrome/driver.rb'
- 'lib/selenium/webdriver/chrome/legacy_bridge.rb'
- 'lib/selenium/webdriver/remote/w3c/capabilities.rb'
- 'lib/selenium/webdriver/support/color.rb'

Expand All @@ -108,7 +98,6 @@ Metrics/MethodLength:
Max: 33
Exclude:
- 'lib/selenium/webdriver/chrome/driver.rb'
- 'lib/selenium/webdriver/chrome/legacy_bridge.rb'

Metrics/BlockLength:
Exclude:
Expand All @@ -121,75 +110,12 @@ Metrics/ParameterLists:
Layout/EmptyLineAfterMagicComment:
Enabled: false

Layout/EmptyLinesAroundBlockBody:
Exclude:
- 'spec/**/*'

Layout/EmptyLinesAroundClassBody:
Enabled: false

Layout/EmptyLinesAroundModuleBody:
Enabled: false

Lint/UnusedBlockArgument:
Enabled: false

Lint/UnusedMethodArgument:
Enabled: false

Lint/UselessAssignment:
Exclude:
- 'spec/unit/selenium/webdriver/chrome/service_spec.rb'

Performance/Caller:
Enabled: false

Style/CommentAnnotation:
Enabled: false

Style/FormatString:
Exclude:
- 'lib/selenium/webdriver/atoms.rb'

Style/MethodMissingSuper:
Exclude:
- 'lib/selenium/webdriver/support/event_firing_bridge.rb'
- 'lib/selenium/webdriver/support/block_event_listener.rb'

Style/MissingRespondToMissing:
Exclude:
- 'lib/selenium/webdriver/support/event_firing_bridge.rb'
- 'lib/selenium/webdriver/support/block_event_listener.rb'

Layout/MultilineMethodCallIndentation:
Exclude:
- 'spec/unit/selenium/webdriver/chrome/profile_spec.rb'

Style/MultilineMemoization:
Enabled: false

Style/MutableConstant:
Enabled: false

Style/RedundantBegin:
Exclude:
- 'spec/integration/selenium/webdriver/driver_spec.rb'

Style/RedundantSelf:
Enabled: false

Style/StringLiterals:
Enabled: false

Style/SymbolArray:
Enabled: false

Style/TrailingCommaInArrayLiteral:
Enabled: false

Style/TrailingCommaInHashLiteral:
Enabled: false

Style/Dir:
Exclude:
- 'selenium-webdriver.gemspec'
Expand Down
4 changes: 2 additions & 2 deletions rb/lib/selenium/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def stop_process
end

def process
@process ||= (
@process ||= begin
# extract any additional_args that start with -D as options
properties = @additional_args.dup - @additional_args.delete_if { |arg| arg[/^-D/] }
server_command = ['java'] + properties + ['-jar', @jar, '-port', @port.to_s] + @additional_args
Expand All @@ -250,7 +250,7 @@ def process
cp.detach = @background

cp
)
end
end

def poll_for_service
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/atoms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def read_atom(function)
end

def execute_atom(function_name, *arguments)
script = "return (%<atom>s).apply(null, arguments)" % {atom: read_atom(function_name)}
script = format("return (%<atom>s).apply(null, arguments)", atom: read_atom(function_name))
execute_script(script, *arguments)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module WebDriver

module DriverExtensions
module Rotatable
ORIENTATIONS = [:landscape, :portrait].freeze
ORIENTATIONS = %i[landscape portrait].freeze

#
# Change the screen orientation
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/common/keyboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def release(key)

private

MODIFIERS = [:control, :shift, :alt, :command, :meta].freeze
MODIFIERS = %i[control shift alt command meta].freeze

def assert_modifier(key)
return if MODIFIERS.include? key
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/common/port_prober.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def self.random
port
end

IGNORED_ERRORS = [Errno::EADDRNOTAVAIL, Errno::EAFNOSUPPORT]
IGNORED_ERRORS = [Errno::EADDRNOTAVAIL, Errno::EAFNOSUPPORT].freeze
IGNORED_ERRORS << Errno::EBADF if Platform.cygwin?
IGNORED_ERRORS << Errno::EACCES if Platform.windows?
IGNORED_ERRORS.freeze
Expand Down
4 changes: 2 additions & 2 deletions rb/lib/selenium/webdriver/common/socket_poller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def closed?

CONNECT_TIMEOUT = 5

NOT_CONNECTED_ERRORS = [Errno::ECONNREFUSED, Errno::ENOTCONN, SocketError]
NOT_CONNECTED_ERRORS = [Errno::ECONNREFUSED, Errno::ENOTCONN, SocketError].freeze
NOT_CONNECTED_ERRORS << Errno::EPERM if Platform.cygwin?

CONNECTED_ERRORS = [Errno::EISCONN]
CONNECTED_ERRORS = [Errno::EISCONN].freeze
CONNECTED_ERRORS << Errno::EINVAL if Platform.windows?
CONNECTED_ERRORS << Errno::EALREADY if Platform.wsl?

Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/edge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def self.driver_path=(path)
@driver_path = path
end

def self.driver_path(warning = true)
def self.driver_path(_warning = true)
@driver_path ||= nil
end
end # Edge
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/remote/http/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def call(verb, url, command_hash)

if command_hash
payload = JSON.generate(command_hash)
headers['Content-Length'] = payload.bytesize.to_s if [:post, :put].include?(verb)
headers['Content-Length'] = payload.bytesize.to_s if %i[post put].include?(verb)

WebDriver.logger.info(" >>> #{url} | #{payload}")
WebDriver.logger.debug(" > #{headers.inspect}")
Expand Down
4 changes: 2 additions & 2 deletions rb/lib/selenium/webdriver/remote/http/curb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def request(verb, url, headers, payload)
end

def client
@client ||= (
@client ||= begin
c = Curl::Easy.new

c.max_redirects = MAX_REDIRECTS
Expand All @@ -88,7 +88,7 @@ def client
c.verbose = WebDriver.logger.info?

c
)
end
end
end # Curb
end # Http
Expand Down
36 changes: 18 additions & 18 deletions rb/lib/selenium/webdriver/remote/http/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ def timeout=(value)
private

def http
@http ||= (
http = new_http_client
if server_url.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
@http ||= begin
http = new_http_client
if server_url.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end

# Defaulting open_timeout to nil to be consistent with Ruby 2.2 and earlier.
http.open_timeout = self.open_timeout
http.read_timeout = self.read_timeout if self.read_timeout
# Defaulting open_timeout to nil to be consistent with Ruby 2.2 and earlier.
http.open_timeout = open_timeout
http.read_timeout = read_timeout if read_timeout

http
)
http
end
end

MAX_RETRIES = 3
Expand Down Expand Up @@ -140,15 +140,15 @@ def new_http_client
end

def proxy
@proxy ||= (
proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
no_proxy = ENV['no_proxy'] || ENV['NO_PROXY']
@proxy ||= begin
proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
no_proxy = ENV['no_proxy'] || ENV['NO_PROXY']

if proxy
proxy = "http://#{proxy}" unless proxy.start_with?('http://')
Proxy.new(http: proxy, no_proxy: no_proxy)
if proxy
proxy = "http://#{proxy}" unless proxy.start_with?('http://')
Proxy.new(http: proxy, no_proxy: no_proxy)
end
end
)
end

def use_proxy?
Expand Down
4 changes: 2 additions & 2 deletions rb/lib/selenium/webdriver/remote/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def add_backtrace(ex)
end

def backtrace_from_remote(server_trace)
server_trace.map do |frame|
server_trace.map { |frame|
next unless frame.is_a?(Hash)

file = frame['fileName']
Expand All @@ -108,7 +108,7 @@ def backtrace_from_remote(server_trace)
meth = 'unknown' if meth.nil? || meth.empty?

"[remote server] #{file}:#{line}:in `#{meth}'"
end.compact
}.compact
end

def error_payload
Expand Down
4 changes: 2 additions & 2 deletions rb/lib/selenium/webdriver/remote/w3c/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def window_position

def set_window_rect(x: nil, y: nil, width: nil, height: nil)
params = {x: x, y: y, width: width, height: height}
params.update(params) { |k, v| Integer(v) unless v.nil? }
params.update(params) { |_k, v| Integer(v) unless v.nil? }
execute :set_window_rect, {}, params
end

Expand Down Expand Up @@ -570,7 +570,7 @@ def convert_locators(how, what)
[how, what]
end

ESCAPE_CSS_REGEXP = /(['"\\#.:;,!?+<>=~*^$|%&@`{}\-\[\]\(\)])/
ESCAPE_CSS_REGEXP = /(['"\\#.:;,!?+<>=~*^$|%&@`{}\-\[\]\(\)])/.freeze
UNICODE_CODE_POINT = 30

# Escapes invalid characters in CSS selector.
Expand Down
12 changes: 6 additions & 6 deletions rb/lib/selenium/webdriver/remote/w3c/capabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module W3C

class Capabilities

EXTENSION_CAPABILITY_PATTERN = /\A[\w-]+:.*\z/
EXTENSION_CAPABILITY_PATTERN = /\A[\w-]+:.*\z/.freeze

KNOWN = [
:browser_name,
Expand All @@ -48,14 +48,14 @@ class Capabilities
# remote-specific
:remote_session_id,

# TODO (alex): deprecate in favor of Firefox::Options?
# TODO: (alex) deprecate in favor of Firefox::Options?
:accessibility_checks,
:device,

# TODO (alex): deprecate compatibility with OSS-capabilities
# TODO: (alex) deprecate compatibility with OSS-capabilities
:implicit_timeout,
:page_load_timeout,
:script_timeout,
:script_timeout
].freeze

KNOWN.each do |key|
Expand Down Expand Up @@ -147,7 +147,7 @@ def json_create(data)
def from_oss(oss_capabilities)
w3c_capabilities = new

# TODO (alex): make capabilities enumerable?
# TODO: (alex) make capabilities enumerable?
oss_capabilities = oss_capabilities.__send__(:capabilities) unless oss_capabilities.is_a?(Hash)
oss_capabilities.each do |name, value|
next if value.nil?
Expand All @@ -167,7 +167,7 @@ def from_oss(oss_capabilities)

# User can pass :firefox_options or :firefox_profile.
#
# TODO (alex): Refactor this whole method into converter class.
# TODO: (alex) Refactor this whole method into converter class.
firefox_options = oss_capabilities['firefoxOptions'] || oss_capabilities['firefox_options'] || oss_capabilities[:firefox_options]
firefox_profile = oss_capabilities['firefox_profile'] || oss_capabilities[:firefox_profile]
firefox_binary = oss_capabilities['firefox_binary'] || oss_capabilities[:firefox_binary]
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/support/block_event_listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def initialize(callback)
@callback = callback
end

def method_missing(meth, *args)
def method_missing(meth, *args) # rubocop:disable Style/MethodMissingSuper, Style/MissingRespondToMissing
@callback.call meth, *args
end
end # BlockEventListener
Expand Down

0 comments on commit 775417d

Please sign in to comment.