Skip to content

Commit 219181d

Browse files
authored
fix: rubocop (#890)
* feat: bump ruby version * fix: fix rubocop * fix rubocop more
1 parent 334b791 commit 219181d

File tree

23 files changed

+61
-63
lines changed

23 files changed

+61
-63
lines changed

.rubocop.yml

+15-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,21 @@ Naming/AccessorMethodName:
3131
Enabled: false
3232
Naming/RescuedExceptionsVariableName:
3333
Enabled: false
34-
Layout/IndentHeredoc:
34+
Layout/HeredocIndentation:
3535
Enabled: false
3636
Layout/RescueEnsureAlignment:
3737
Enabled: false
38+
Layout/HashAlignment:
39+
Enabled: false
40+
Style/ExplicitBlockArgument:
41+
Enabled: false
42+
Style/OptionalBooleanParameter:
43+
Enabled: false
44+
Naming/MethodParameterName:
45+
Enabled: false
46+
Style/KeywordParametersOrder:
47+
Enabled: false
48+
Style/AccessorGrouping:
49+
Enabled: false
50+
Style/StringConcatenation:
51+
Enabled: false

android_tests/Rakefile

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ require 'rubocop/rake_task'
1919
task default: :android
2020

2121
# Run sh and ignore exception
22-
# rubocop:disable Lint/HandleExceptions,Style/RescueStandardError
2322
def run_sh(cmd)
2423
sh cmd
25-
rescue
24+
rescue StandardError
2625
# ignored
2726
end
28-
# rubocop:enable Lint/HandleExceptions,Style/RescueStandardError
2927

3028
# Run cmd. On failure run install and try again.
3129
def bash(cmd)

android_tests/lib/android/specs/common/helper.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
proc { wait(timeout: 0.2, interval: 0.0) { raise NoMemoryError } }.must_raise ::Appium::Core::Wait::TimeoutError
3838

3939
proc { wait_true(invalidkey: 2) { true } }.must_raise ArgumentError do
40-
assert_equal'unknown keyword: invalidkey', e.message
40+
assert_equal 'unknown keyword: invalidkey', e.message
4141
end
4242
end
4343

@@ -69,7 +69,7 @@
6969
.must_raise ::Appium::Core::Wait::TimeoutError
7070

7171
proc { wait_true(invalidkey: 2) { true } }.must_raise ArgumentError do
72-
assert_equal'unknown keyword: invalidkey', e.message
72+
assert_equal 'unknown keyword: invalidkey', e.message
7373
end
7474
end
7575

android_tests/lib/android/specs/common/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
end
1919

2020
t '::Appium::DATE' do
21-
::Appium::DATE.must_match(/(\d+)\-(\d+)\-(\d+)/)
21+
::Appium::DATE.must_match(/(\d+)-(\d+)-(\d+)/)
2222
end
2323
end

android_tests/lib/android/specs/device/touch_actions.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def swipe_till_text_visible(seen_text)
1818
start_x = window_size[:width] / 2
1919
start_y = window_size[:height] / 2
2020
wait(timeout: 0.6) do
21-
# rubocop:disable Metrics/LineLength
21+
# rubocop:disable Layout/LineLength
2222
# Example for Android's log
2323
# [0] pry(#<device/touch_actions>)> swipe start_x: start_x, start_y: start_y, end_x: start_y, end_y: start_y - 100
2424
# [HTTP] --> POST /wd/hub/session/9baa18bf-a19b-4654-be4a-d0db0334bbc0/touch/perform {"actions":[{"action":"press","options":{"x":600,"y":919}},{"action":"wait","options":{"ms":200}},{"action":"moveTo","options":{"x":600,"y":819}},{"action":"release"}]}
@@ -31,7 +31,7 @@ def swipe_till_text_visible(seen_text)
3131
# [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][1200,1838]
3232
# [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Swiping from [x=600.0, y=919.0] to [x=600.0, y=819.0] with steps: 6
3333
# [debug] [AndroidBootstrap] Received command result from bootstrap
34-
# rubocop:enable Metrics/LineLength
34+
# rubocop:enable Layout/LineLength
3535
swipe start_x: start_x, start_y: start_y, end_x: 0.0, end_y: - 100
3636
text(seen_text).displayed?
3737
end

android_tests/lib/android/specs/driver.rb

-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def sauce?
5151
caps_app_for_teardown = actual[:caps][:app]
5252
expected_app = File.absolute_path('../test_apps/api.apk')
5353

54-
# rubocop:disable Layout/AlignHash
5554
expected = {
5655
automation_name: :uiautomator2,
5756
custom_url: 'http://127.0.0.1:4723/wd/hub',
@@ -68,7 +67,6 @@ def sauce?
6867
wait_timeout: 30, # default
6968
wait_interval: 0.5 # default
7069
}
71-
# rubocop:enable Layout/AlignHash
7270

7371
# actual[:caps].to_json send to Appium server
7472
caps_with_json = JSON.parse(actual[:caps].to_json)

android_tests/lib/run.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ def start_driver(caps)
6363
else
6464
# ensure ext is .rb
6565
one_test = File.join(File.dirname(one_test),
66-
File.basename(one_test, '.*') + '.rb')
67-
one_test = File.join(dir, test_dir + 'specs/', one_test)
66+
"#{File.basename(one_test, '.*')}.rb")
67+
one_test = File.join(dir, "#{test_dir}specs/#{one_test}")
6868
end
6969

7070
raise "\nTest #{one_test} does not exist.\n" unless File.exist?(one_test)
7171

7272
start_driver(caps)
7373

7474
# require support (common.rb)
75-
file_name = File.join dir, test_dir + '/*.rb'
76-
Dir.glob(file_name) do |test|
75+
file_name = File.join dir, "#{test_dir}/*.rb"
76+
Dir.glob(file_name).sort.each do |test|
7777
require test
7878
trace_files << test
7979
end
@@ -82,8 +82,8 @@ def start_driver(caps)
8282
trace_files << one_test
8383
else
8484
# require all
85-
file_names = File.join(dir, test_dir + '**/*.rb')
86-
Dir.glob(file_names) do |test|
85+
file_names = File.join(dir, "#{test_dir}**/*.rb")
86+
Dir.glob(file_names).sort.each do |test|
8787
# load all tests
8888
trace_files << test
8989
puts " #{File.basename(test, '.*')}"
@@ -96,7 +96,7 @@ def start_driver(caps)
9696
trace_files.map! do |f|
9797
f = File.expand_path f
9898
# ensure all traced files end in .rb
99-
f = File.join(File.dirname(f), File.basename(f, '.*') + '.rb')
99+
f = File.join(File.dirname(f), "#{File.basename(f, '.*')}.rb")
100100
f
101101
end
102102

appium_lib.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
2424
s.add_development_dependency 'posix-spawn', '~> 0.3'
2525
s.add_development_dependency 'pry'
2626
s.add_development_dependency 'rake', '~> 13.0'
27-
s.add_development_dependency 'rubocop', '~> 0.68.1'
27+
s.add_development_dependency 'rubocop', '1.6.1'
2828
s.add_development_dependency 'spec', '~> 5.3', '>= 5.3.4'
2929
s.add_development_dependency 'yard', '~> 0.9.11'
3030

ios_tests/Rakefile

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ require 'rubocop/rake_task'
1919
task default: :ios
2020

2121
# Run sh and ignore exception
22-
# rubocop:disable Lint/HandleExceptions,Style/RescueStandardError
2322
def run_sh(cmd)
2423
sh cmd
25-
rescue
24+
rescue StandardError
25+
# Ignored
2626
end
27-
# rubocop:enable Lint/HandleExceptions,Style/RescueStandardError
2827

2928
# Run cmd. On failure run install and try again.
3029
def bash(cmd)

ios_tests/lib/ios/specs/common/helper.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def before_first
4646
proc { wait(timeout: 0.2, interval: 0.0) { raise NoMemoryError } }.must_raise ::Appium::Core::Wait::TimeoutError
4747

4848
proc { wait(invalidkey: 2) { true } }.must_raise ArgumentError do |e|
49-
assert_equal'unknown keyword: invalidkey', e.message
49+
assert_equal 'unknown keyword: invalidkey', e.message
5050
end
5151
end
5252

@@ -78,7 +78,7 @@ def before_first
7878
.must_raise ::Appium::Core::Wait::TimeoutError
7979

8080
proc { wait_true(invalidkey: 2) { true } }.must_raise ArgumentError do
81-
assert_equal'unknown keyword: invalidkey', e.message
81+
assert_equal 'unknown keyword: invalidkey', e.message
8282
end
8383
end
8484

ios_tests/lib/ios/specs/common/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ def before_first
2626
end
2727

2828
t '::Appium::DATE' do
29-
::Appium::DATE.must_match(/(\d+)\-(\d+)\-(\d+)/)
29+
::Appium::DATE.must_match(/(\d+)-(\d+)-(\d+)/)
3030
end
3131
end

ios_tests/lib/ios/specs/device/touch_actions.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def after_last
3030
size = picker.size.to_h
3131
start_x = loc[:x] + size[:width] / 2
3232
start_y = loc[:y] + size[:height] / 2
33-
# rubocop:disable Metrics/LineLength
33+
# rubocop:disable Layout/LineLength
3434
# Example for iOS's log with XCUITest
3535
# [0] pry(#<device/touch_actions>)> swipe start_x: start_x, start_y: start_y, offset_x: 0, offset_y: - 50
3636
# [debug] [WebDriverAgent] Sim: Jan 14 16:35:05 rrcs-172-254-99-35 CoreSimulatorBridge[65868]: KEYMAP: Chose mode=en_US@hw=Automatic;sw=QWERTY from match=en_US@hw=Automatic;sw=QWERTY from language=en
@@ -57,7 +57,7 @@ def after_last
5757
# [debug] [UIAuto] Got result from instruments: {"status":0,"value":""}
5858
# [debug] [MJSONWP] Responding to client with driver.performTouch() result: ""
5959
# [HTTP] <-- POST /wd/hub/session/8b651f03-0fbc-43f0-aaf2-243d0650f6aa/touch/perform 200 1895 ms - 74
60-
# rubocop:enable Metrics/LineLength
60+
# rubocop:enable Layout/LineLength
6161
Appium::TouchAction.new.swipe(start_x: start_x, start_y: start_y, end_x: 0, end_y: - 50).perform
6262
ele_index(ui_ios.static_text, 2).text.must_equal 'Chris Armstrong - 0' # depends on iOS
6363
end

ios_tests/lib/ios/specs/driver.rb

-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ def sauce?
5050
caps_app_for_teardown = actual[:caps][:app]
5151
expected_app = File.absolute_path('../test_apps/UICatalog.app.zip')
5252

53-
# rubocop:disable Layout/AlignHash
5453
expected = {
5554
automation_name: :xcuitest,
5655
custom_url: false,
@@ -67,7 +66,6 @@ def sauce?
6766
wait_timeout: 20, # defined in appium.txt
6867
wait_interval: 1 # defined in appium.txt
6968
}
70-
# rubocop:enable Layout/AlignHash
7169

7270
# actual[:caps].to_json send to Appium server
7371
caps_with_json = JSON.parse(actual[:caps].to_json)

ios_tests/lib/ios/specs/ios/element/text.rb

+4-7
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# rubocop:disable Lint/HandleExceptions,Style/RescueStandardError
16-
1715
# rake ios['ios/element/text']
1816
describe 'ios/element/text' do
1917
def ui_catalog
@@ -60,10 +58,10 @@ def before_first
6058
# should fail
6159
set_wait 0
6260
act = begin
63-
text_exact 'mos'
64-
rescue
65-
# nop
66-
end
61+
text_exact 'mos'
62+
rescue StandardError
63+
# nop
64+
end
6765
act.must_be_nil
6866
set_wait
6967

@@ -75,4 +73,3 @@ def before_first
7573
texts_exact('UICatalog').length.must_equal 1
7674
end
7775
end
78-
# rubocop:enable Lint/HandleExceptions,Style/RescueStandardError

ios_tests/lib/ios/specs/ios/element/textfield.rb

-2
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,9 @@ def after_last
7373
textfields_exact(enter_password).first.value.must_equal enter_password
7474
end
7575

76-
# rubocop:disable Style/DoubleNegation
7776
def keyboard_exists?
7877
!!ignore { wait_true(3) { execute_script 'au.mainApp().keyboard().type() !== "UIAElementNil"' } }
7978
end
80-
# rubocop:enable Style/DoubleNegation
8179

8280
def keyboard_must_not_exist
8381
keyboard_exists?.must_equal false

lib/appium_lib/android/common/helper.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def filter=(value)
2727
@filter = value.to_s.downcase
2828
end
2929

30-
def initialize
30+
def initialize # rubocop:disable Lint/MissingSuper
3131
reset
3232
@filter = false
3333
end
@@ -217,7 +217,7 @@ def resource_id(string, on_match)
217217
# [^\/]+ - type is made up of at least one non-/ characters
218218
# \\/ - / ends the type and starts the name
219219
# [\S]+$ - the name contains at least one non-space character and then the line is ended
220-
resource_id = /^[a-zA-Z_][a-zA-Z0-9\._]*:[^\/]+\/[\S]+$/
220+
resource_id = /^[a-zA-Z_][a-zA-Z0-9._]*:[^\/]+\/\S+$/
221221
string.match(resource_id) ? on_match : ''
222222
end
223223

lib/appium_lib/appium.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ def load_settings(opts = {})
7777
Appium::Logger.info "Loading #{toml}" if verbose
7878

7979
data = Tomlrb.load_file(toml, symbolize_keys: true)
80-
if verbose
81-
Appium::Logger.info data unless data.empty?
82-
end
80+
81+
Appium::Logger.info data if verbose && !data.empty?
8382

8483
if data && data[:caps] && data[:caps][:app] && !data[:caps][:app].empty?
8584
data[:caps][:app] = Appium::Driver.absolute_app_path data
@@ -200,7 +199,7 @@ def promote_appium_methods(class_array, driver = $driver)
200199
raise 'Driver is nil' if driver.nil?
201200

202201
# Wrap single class into an array
203-
class_array = [class_array] unless class_array.class == Array
202+
class_array = [class_array] unless class_array.instance_of? Array
204203
# Promote Appium driver methods to class instance methods.
205204
class_array.each do |klass|
206205
driver.public_methods(false).each do |m|

lib/appium_lib/common/helper.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ module Common
2929
# Return yield and ignore any exceptions.
3030
def ignore
3131
yield
32-
rescue Exception # rubocop:disable Lint/HandleExceptions, Lint/RescueException
32+
rescue StandardError
33+
# Ignored
3334
end
3435

3536
# Navigate back.
@@ -73,7 +74,7 @@ def xpaths(xpath_str)
7374
class CountElements < Nokogiri::XML::SAX::Document
7475
attr_reader :result
7576

76-
def initialize(platform)
77+
def initialize(platform) # rubocop:disable Lint/MissingSuper
7778
reset
7879
@platform = platform
7980
end
@@ -213,7 +214,7 @@ def filter=(value)
213214
@filter = value.to_s.downcase
214215
end
215216

216-
def initialize
217+
def initialize # rubocop:disable Lint/MissingSuper
217218
reset
218219
@filter = false
219220
end

lib/appium_lib/driver.rb

+6-10
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ def set_sauce_related_values(appium_lib_opts)
276276

277277
# Returns a hash of the driver attributes
278278
def driver_attributes
279-
# rubocop:disable Layout/AlignHash
280279
{
281280
caps: @core.caps,
282281
automation_name: @core.automation_name,
@@ -294,7 +293,6 @@ def driver_attributes
294293
wait_timeout: @core.wait_timeout,
295294
wait_interval: @core.wait_interval
296295
}
297-
# rubocop:enable Layout/AlignHash
298296
end
299297

300298
def device_is_android?
@@ -425,14 +423,12 @@ def self.absolute_app_path(opts)
425423
return app_path if app_path =~ URI::DEFAULT_PARSER.make_regexp # public URL for Sauce
426424

427425
absolute_app_path = File.expand_path app_path
428-
app_path = if File.exist? absolute_app_path
429-
absolute_app_path
430-
else
431-
::Appium::Logger.info("Use #{app_path}")
432-
app_path
433-
end
434-
435-
app_path
426+
if File.exist? absolute_app_path
427+
absolute_app_path
428+
else
429+
::Appium::Logger.info("Use #{app_path}")
430+
app_path
431+
end
436432
end
437433

438434
# Get the server url

lib/appium_lib/ios/common/helper.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def _print_attr(type, name, label, value, hint, visible) # rubocop:disable Metri
4949
puts " visible: #{visible}" if visible
5050
end
5151
end
52+
5253
# iOS only. On Android uiautomator always returns an empty string for EditText password.
5354
#
5455
# Password character returned from value of UIASecureTextField
@@ -470,7 +471,7 @@ def _by_json(opts)
470471
# will be present.
471472
_validate_object opts[:name], opts[:label], opts[:value]
472473

473-
# note that mainWindow is sometimes nil so it's passed as a param
474+
# NOTE: that mainWindow is sometimes nil so it's passed as a param
474475
# $._elementOrElementsByType will validate that the window isn't nil
475476
element_or_elements_by_type = <<-JS
476477
(function() {

lib/appium_lib/ios/xcuitest.rb

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
require_relative 'xcuitest/element'
1616
require_relative 'xcuitest/command'
1717
require_relative 'xcuitest/helper'
18-
require_relative 'xcuitest/element'
1918
require_relative 'xcuitest/bridge'
2019

2120
module Appium

0 commit comments

Comments
 (0)