Skip to content

Commit 439da14

Browse files
committed
[rb] fix new linting failures
1 parent 8ef7001 commit 439da14

File tree

21 files changed

+199
-33
lines changed

21 files changed

+199
-33
lines changed

‎rb/.rubocop.yml

Lines changed: 167 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ AllCops:
66
TargetRubyVersion: 2.7
77
Exclude:
88
- 'lib/selenium/devtools/**/*'
9-
NewCops: enable
109

1110
Layout/EmptyLinesAroundAttributeAccessor:
1211
Enabled: true
@@ -18,7 +17,7 @@ Layout/EmptyLinesAroundModuleBody:
1817
Enabled: false
1918

2019
Layout/LineLength:
21-
IgnoredPatterns:
20+
AllowedPatterns:
2221
- '\s+# rubocop'
2322
- '^\s*#'
2423
- '^\s*it .*, except: \{.*\} do$'
@@ -190,3 +189,169 @@ Style/SignalException:
190189

191190
RSpec/BeEq:
192191
Enabled: false
192+
193+
# Additional things
194+
Gemspec/DateAssignment: # new in 1.10
195+
Enabled: true
196+
Gemspec/RequireMFA: # new in 1.23
197+
Enabled: true
198+
Layout/LineEndStringConcatenationIndentation: # new in 1.18
199+
Enabled: true
200+
Layout/SpaceBeforeBrackets: # new in 1.7
201+
Enabled: true
202+
Lint/AmbiguousAssignment: # new in 1.7
203+
Enabled: true
204+
Lint/AmbiguousOperatorPrecedence: # new in 1.21
205+
Enabled: true
206+
Lint/AmbiguousRange: # new in 1.19
207+
Enabled: true
208+
Lint/DeprecatedConstants: # new in 1.8
209+
Enabled: true
210+
Lint/DuplicateBranch: # new in 1.3
211+
Enabled: true
212+
Lint/DuplicateRegexpCharacterClassElement: # new in 1.1
213+
Enabled: true
214+
Lint/EmptyBlock: # new in 1.1
215+
Enabled: true
216+
Lint/EmptyClass: # new in 1.3
217+
Enabled: true
218+
Lint/EmptyInPattern: # new in 1.16
219+
Enabled: true
220+
Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21
221+
Enabled: true
222+
Lint/LambdaWithoutLiteralBlock: # new in 1.8
223+
Enabled: true
224+
Lint/NoReturnInBeginEndBlocks: # new in 1.2
225+
Enabled: true
226+
Lint/NumberedParameterAssignment: # new in 1.9
227+
Enabled: true
228+
Lint/OrAssignmentToConstant: # new in 1.9
229+
Enabled: true
230+
Lint/RedundantDirGlobSort: # new in 1.8
231+
Enabled: true
232+
Lint/RefinementImportMethods: # new in 1.27
233+
Enabled: true
234+
Lint/RequireRelativeSelfPath: # new in 1.22
235+
Enabled: true
236+
Lint/SymbolConversion: # new in 1.9
237+
Enabled: true
238+
Lint/ToEnumArguments: # new in 1.1
239+
Enabled: true
240+
Lint/TripleQuotes: # new in 1.9
241+
Enabled: true
242+
Lint/UnexpectedBlockArity: # new in 1.5
243+
Enabled: true
244+
Lint/UnmodifiedReduceAccumulator: # new in 1.1
245+
Enabled: true
246+
Lint/UselessRuby2Keywords: # new in 1.23
247+
Enabled: true
248+
Naming/BlockForwarding: # new in 1.24
249+
Enabled: true
250+
Security/CompoundHash: # new in 1.28
251+
Enabled: true
252+
Security/IoMethods: # new in 1.22
253+
Enabled: true
254+
Style/ArgumentsForwarding: # new in 1.1
255+
Enabled: true
256+
Style/CollectionCompact: # new in 1.2
257+
Enabled: true
258+
Style/DocumentDynamicEvalDefinition: # new in 1.1
259+
Enabled: true
260+
Style/EndlessMethod: # new in 1.8
261+
Enabled: true
262+
Style/FetchEnvVar: # new in 1.28
263+
Enabled: true
264+
Style/FileRead: # new in 1.24
265+
Enabled: true
266+
Style/FileWrite: # new in 1.24
267+
Enabled: true
268+
Style/HashConversion: # new in 1.10
269+
Enabled: true
270+
Style/HashExcept: # new in 1.7
271+
Enabled: true
272+
Style/IfWithBooleanLiteralBranches: # new in 1.9
273+
Enabled: true
274+
Style/InPatternThen: # new in 1.16
275+
Enabled: true
276+
Style/MapToHash: # new in 1.24
277+
Enabled: true
278+
Style/MultilineInPatternThen: # new in 1.16
279+
Enabled: true
280+
Style/NegatedIfElseCondition: # new in 1.2
281+
Enabled: true
282+
Style/NestedFileDirname: # new in 1.26
283+
Enabled: true
284+
Style/NilLambda: # new in 1.3
285+
Enabled: true
286+
Style/NumberedParameters: # new in 1.22
287+
Enabled: true
288+
Style/NumberedParametersLimit: # new in 1.22
289+
Enabled: true
290+
Style/ObjectThen: # new in 1.28
291+
Enabled: true
292+
Style/OpenStructUse: # new in 1.23
293+
Enabled: true
294+
Style/QuotedSymbols: # new in 1.16
295+
Enabled: true
296+
Style/RedundantArgument: # new in 1.4
297+
Enabled: true
298+
Style/RedundantInitialize: # new in 1.27
299+
Enabled: true
300+
Style/RedundantSelfAssignmentBranch: # new in 1.19
301+
Enabled: true
302+
Style/SelectByRegexp: # new in 1.22
303+
Enabled: true
304+
Style/StringChars: # new in 1.12
305+
Enabled: true
306+
Style/SwapValues: # new in 1.1
307+
Enabled: true
308+
Performance/AncestorsInclude: # new in 1.7
309+
Enabled: true
310+
Performance/BigDecimalWithNumericArgument: # new in 1.7
311+
Enabled: true
312+
Performance/BlockGivenWithExplicitBlock: # new in 1.9
313+
Enabled: true
314+
Performance/CollectionLiteralInLoop: # new in 1.8
315+
Enabled: true
316+
Performance/ConcurrentMonotonicTime: # new in 1.12
317+
Enabled: true
318+
Performance/ConstantRegexp: # new in 1.9
319+
Enabled: true
320+
Performance/MapCompact: # new in 1.11
321+
Enabled: true
322+
Performance/MethodObjectAsBlock: # new in 1.9
323+
Enabled: true
324+
Performance/RedundantEqualityComparisonBlock: # new in 1.10
325+
Enabled: true
326+
Performance/RedundantSortBlock: # new in 1.7
327+
Enabled: true
328+
Performance/RedundantSplitRegexpArgument: # new in 1.10
329+
Enabled: true
330+
Performance/RedundantStringChars: # new in 1.7
331+
Enabled: true
332+
Performance/ReverseFirst: # new in 1.7
333+
Enabled: true
334+
Performance/SortReverse: # new in 1.7
335+
Enabled: true
336+
Performance/Squeeze: # new in 1.7
337+
Enabled: true
338+
Performance/StringIdentifierArgument: # new in 1.13
339+
Enabled: true
340+
Performance/StringInclude: # new in 1.7
341+
Enabled: true
342+
Performance/Sum: # new in 1.8
343+
Enabled: true
344+
RSpec/BeNil: # new in 2.9.0
345+
Enabled: true
346+
RSpec/ExcessiveDocstringSpacing: # new in 2.5
347+
Enabled: true
348+
RSpec/IdenticalEqualityAssertion: # new in 2.4
349+
Enabled: true
350+
RSpec/SubjectDeclaration: # new in 2.5
351+
Enabled: true
352+
RSpec/VerifiedDoubleReference: # new in 2.10.0
353+
Enabled: true
354+
RSpec/FactoryBot/SyntaxMethods: # new in 2.7
355+
Enabled: true
356+
RSpec/Rails/AvoidSetupHook: # new in 2.4
357+
Enabled: true

‎rb/lib/selenium/server.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def available_assets
122122
end
123123

124124
def net_http_start(address, &block)
125-
http_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
125+
http_proxy = ENV.fetch('http_proxy', nil) || ENV.fetch('HTTP_PROXY', nil)
126126
if http_proxy
127127
http_proxy = "http://#{http_proxy}" unless http_proxy.start_with?('http://')
128128
uri = URI.parse(http_proxy)

‎rb/lib/selenium/webdriver/common/element.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def ==(other)
4646
alias_method :eql?, :==
4747

4848
def hash
49-
@id.hash ^ @bridge.hash
49+
[@id, @bridge].hash
5050
end
5151

5252
#

‎rb/lib/selenium/webdriver/common/platform.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ def find_binary(*binary_names)
177177

178178
def find_in_program_files(*binary_names)
179179
paths = [
180-
ENV['PROGRAMFILES'] || '\\Program Files',
181-
ENV['ProgramFiles(x86)'] || '\\Program Files (x86)',
182-
ENV['ProgramW6432'] || '\\Program Files'
180+
ENV.fetch('PROGRAMFILES', '\\Program Files'),
181+
ENV.fetch('ProgramFiles(x86)', '\\Program Files (x86)'),
182+
ENV.fetch('ProgramW6432', '\\Program Files')
183183
]
184184

185185
paths.each do |root|

‎rb/lib/selenium/webdriver/common/shadow_root.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def ==(other)
4545
alias_method :eql?, :==
4646

4747
def hash
48-
@id.hash ^ @bridge.hash
48+
[@id, @bridge].hash
4949
end
5050

5151
#

‎rb/lib/selenium/webdriver/firefox/util.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module Util
2727
def app_data_path
2828
case Platform.os
2929
when :windows
30-
"#{ENV['APPDATA']}\\Mozilla\\Firefox"
30+
"#{ENV.fetch('APPDATA')}\\Mozilla\\Firefox"
3131
when :macosx
3232
"#{Platform.home}/Library/Application Support/Firefox"
3333
when :unix, :linux

‎rb/lib/selenium/webdriver/remote/http/default.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ def new_http_client
136136

137137
def proxy
138138
@proxy ||= begin
139-
proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
140-
no_proxy = ENV['no_proxy'] || ENV['NO_PROXY']
139+
proxy = ENV.fetch('http_proxy', nil) || ENV.fetch('HTTP_PROXY', nil)
140+
no_proxy = ENV.fetch('no_proxy', nil) || ENV.fetch('NO_PROXY', nil)
141141

142142
if proxy
143143
proxy = "http://#{proxy}" unless proxy.start_with?('http://')

‎rb/lib/selenium/webdriver/support/color.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def ==(other)
125125
alias_method :eql?, :==
126126

127127
def hash
128-
[red, green, blue, alpha].hash ^ self.class.hash
128+
[red, green, blue, alpha, self.class].hash
129129
end
130130

131131
def rgb

‎rb/lib/selenium/webdriver/support/guards.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def add_message(name, message)
4848
def disposition
4949
if !skipping_guard.nil?
5050
[:skip, skipping_guard.message]
51-
elsif !pending_guard.nil? && ENV['SKIP_PENDING']
51+
elsif !pending_guard.nil? && ENV.fetch('SKIP_PENDING', nil)
5252
[:skip, pending_guard.message]
5353
elsif !pending_guard.nil?
5454
[:pending, pending_guard.message]

‎rb/spec/integration/selenium/webdriver/chrome/profile_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module Chrome
3939

4040
profile.add_extension(ext_path)
4141

42-
ext_file = instance_double('file')
42+
ext_file = instance_double(File)
4343
allow(File).to receive(:open).with(ext_path, 'rb').and_yield ext_file
4444
allow(ext_file).to receive(:read).and_return 'test'
4545

‎rb/spec/integration/selenium/webdriver/edge/profile_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module Edge
3838

3939
profile.add_extension(ext_path)
4040

41-
ext_file = instance_double('file')
41+
ext_file = instance_double(File)
4242
allow(File).to receive(:open).with(ext_path, 'rb').and_yield ext_file
4343
allow(ext_file).to receive(:read).and_return 'test'
4444

‎rb/spec/integration/selenium/webdriver/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
c.include(WebDriver::SpecSupport::Helpers)
3838

3939
c.before(:suite) do
40-
$DEBUG ||= ENV['DEBUG'] == 'true'
40+
$DEBUG ||= ENV.fetch('DEBUG', nil) == 'true'
4141
GlobalTestEnv.remote_server.start if GlobalTestEnv.driver == :remote && ENV['WD_REMOTE_URL'].nil?
4242
GlobalTestEnv.print_env
4343
end

‎rb/spec/integration/selenium/webdriver/spec_support/rack_server.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def initialize(path, port = nil)
3030
@path = path
3131
@app = TestApp.new(path)
3232

33-
@host = ENV['localhost'] || 'localhost'
33+
@host = ENV.fetch('localhost', 'localhost')
3434
@port = Integer(port || PortProber.above(8180))
3535
end
3636

‎rb/spec/integration/selenium/webdriver/spec_support/test_environment.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def initialize
2929

3030
extract_browser_from_bazel_target_name
3131

32-
@driver = (ENV['WD_SPEC_DRIVER'] || :chrome).to_sym
32+
@driver = ENV.fetch('WD_SPEC_DRIVER', 'chrome').to_sym
3333
@driver_instance = nil
3434
end
3535

@@ -47,7 +47,7 @@ def print_env
4747
end
4848

4949
def browser
50-
driver == :remote ? (ENV['WD_REMOTE_BROWSER'] || :chrome).to_sym : driver
50+
driver == :remote ? ENV.fetch('WD_REMOTE_BROWSER', 'chrome').to_sym : driver
5151
end
5252

5353
def driver_instance
@@ -189,19 +189,19 @@ def create_remote_driver(opt = {})
189189
options = opt.delete(:capabilities)
190190
opt[:capabilities] = [WebDriver::Remote::Capabilities.send(browser)]
191191
opt[:capabilities] << options if options
192-
opt[:url] = ENV['WD_REMOTE_URL'] || remote_server.webdriver_url
192+
opt[:url] = ENV.fetch('WD_REMOTE_URL', remote_server.webdriver_url)
193193
opt[:http_client] ||= WebDriver::Remote::Http::Default.new
194194

195195
WebDriver::Driver.for(:remote, opt)
196196
end
197197

198198
def create_firefox_driver(opt = {})
199-
WebDriver::Firefox.path = ENV['FIREFOX_BINARY'] if ENV['FIREFOX_BINARY']
199+
WebDriver::Firefox.path = ENV.fetch('FIREFOX_BINARY', nil) if ENV.key?('FIREFOX_BINARY')
200200
WebDriver::Driver.for :firefox, opt
201201
end
202202

203203
def create_firefox_nightly_driver(opt = {})
204-
ENV['FIREFOX_BINARY'] = ENV['FIREFOX_NIGHTLY_BINARY']
204+
ENV['FIREFOX_BINARY'] = ENV.fetch('FIREFOX_NIGHTLY_BINARY', nil)
205205
opt[:capabilities] = [
206206
WebDriver::Firefox::Options.new(debugger_address: true),
207207
WebDriver::Remote::Capabilities.firefox(web_socket_url: true)
@@ -215,7 +215,7 @@ def create_ie_driver(opt = {})
215215
end
216216

217217
def create_chrome_driver(opt = {})
218-
WebDriver::Chrome.path = ENV['CHROME_BINARY'] if ENV['CHROME_BINARY']
218+
WebDriver::Chrome.path = ENV.fetch('CHROME_BINARY', nil) if ENV.key?('CHROME_BINARY')
219219
WebDriver::Driver.for :chrome, opt
220220
end
221221

@@ -225,12 +225,12 @@ def create_safari_preview_driver(opt = {})
225225
end
226226

227227
def create_edge_driver(opt = {})
228-
WebDriver::Edge.path = ENV['EDGE_BINARY'] if ENV['EDGE_BINARY']
228+
WebDriver::Edge.path = ENV.fetch('EDGE_BINARY', nil) if ENV.key?('EDGE_BINARY')
229229
WebDriver::Driver.for :edge, opt
230230
end
231231

232232
def extract_browser_from_bazel_target_name
233-
name = ENV['TEST_TARGET']
233+
name = ENV.fetch('TEST_TARGET', nil)
234234
return unless name
235235

236236
case name

‎rb/spec/unit/selenium/server_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
module Selenium
2424
describe Server do
2525
let(:mock_process) { instance_double(ChildProcess::AbstractProcess).as_null_object }
26-
let(:mock_poller) { instance_double('SocketPoller', connected?: true, closed?: true) }
26+
let(:mock_poller) { instance_double(WebDriver::SocketPoller, connected?: true, closed?: true) }
2727
let(:repo) { 'https://api.github.com/repos/seleniumhq/selenium/releases' }
2828
let(:example_json) do
2929
[{url: "#{repo}/41272273",
@@ -191,7 +191,7 @@ module Selenium
191191
it 'raises Selenium::Server::Error if the server is not launched within the timeout' do
192192
allow(File).to receive(:exist?).with('selenium_server_deploy.jar').and_return(true)
193193

194-
poller = instance_double('SocketPoller')
194+
poller = instance_double(WebDriver::SocketPoller)
195195
allow(poller).to receive(:connected?).and_return(false)
196196

197197
server = Selenium::Server.new('selenium_server_deploy.jar', background: true)

‎rb/spec/unit/selenium/webdriver/common/action_builder_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module WebDriver
2424
describe ActionBuilder do
2525
let(:keyboard) { Interactions.key('key') }
2626
let(:mouse) { Interactions.pointer(:mouse, name: 'mouse') }
27-
let(:bridge) { instance_double('Bridge').as_null_object }
27+
let(:bridge) { instance_double(Remote::Bridge).as_null_object }
2828
let(:builder) { ActionBuilder.new(bridge, devices: [mouse, keyboard]) }
2929
let(:async_builder) { ActionBuilder.new(bridge, devices: [mouse, keyboard], async: true) }
3030

0 commit comments

Comments
 (0)