From a14b6599627548c87527a9db644c8f73a8ba2954 Mon Sep 17 00:00:00 2001 From: Augustin Gottlieb <33221555+aguspe@users.noreply.github.com> Date: Sun, 10 Nov 2024 18:58:39 +0100 Subject: [PATCH] [rb] Reduce RBS errors to 0 (#14661) --- rb/Gemfile.lock | 26 ++++++++++--------- rb/lib/selenium/webdriver/bidi/log_handler.rb | 2 ++ rb/lib/selenium/webdriver/bidi/struct.rb | 4 +-- rb/lib/selenium/webdriver/common/error.rb | 4 ++- .../webdriver/common/fedcm/account.rb | 5 ++-- .../webdriver/common/target_locator.rb | 2 ++ .../selenium/webdriver/remote/http/common.rb | 2 ++ rb/sig/lib/selenium/webdriver/bidi.rbs | 2 +- .../selenium/webdriver/bidi/log_handler.rbs | 4 +-- rb/sig/lib/selenium/webdriver/bidi/struct.rbs | 4 +-- .../webdriver/common/driver_finder.rbs | 2 ++ .../lib/selenium/webdriver/common/error.rbs | 2 +- .../lib/selenium/webdriver/common/logger.rbs | 4 +-- .../lib/selenium/webdriver/common/options.rbs | 2 +- .../webdriver/common/selenium_manager.rbs | 2 +- .../lib/selenium/webdriver/common/service.rbs | 2 ++ .../webdriver/common/websocket_connection.rbs | 2 +- .../lib/selenium/webdriver/fedcm/account.rbs | 22 +--------------- .../selenium/webdriver/firefox/options.rbs | 4 +-- .../selenium/webdriver/remote/bidi_bridge.rbs | 2 +- .../lib/selenium/webdriver/remote/bridge.rbs | 6 ++--- .../selenium/webdriver/remote/response.rbs | 6 ++--- rb/sig/selenium/web_driver/script.rbs | 8 +++--- 23 files changed, 55 insertions(+), 64 deletions(-) diff --git a/rb/Gemfile.lock b/rb/Gemfile.lock index 4aedfe0ed9f98..830962b3bc08b 100644 --- a/rb/Gemfile.lock +++ b/rb/Gemfile.lock @@ -13,8 +13,9 @@ PATH GEM remote: https://rubygems.org/ specs: - activesupport (7.2.1.2) + activesupport (7.2.2) base64 + benchmark (>= 0.3) bigdecimal concurrent-ruby (~> 1.0, >= 1.3.1) connection_pool (>= 2.2.5) @@ -28,6 +29,7 @@ GEM public_suffix (>= 2.0.2, < 7.0) ast (2.4.2) base64 (0.2.0) + benchmark (0.4.0) bigdecimal (3.1.8) bigdecimal (3.1.8-java) concurrent-ruby (1.3.4) @@ -45,7 +47,7 @@ GEM ffi (1.17.0) ffi (1.17.0-java) ffi (1.17.0-x86_64-darwin) - fileutils (1.7.2) + fileutils (1.7.3) git (1.19.1) addressable (~> 2.8) rchardet (~> 1.8) @@ -58,8 +60,8 @@ GEM rdoc (>= 4.0.0) reline (>= 0.4.2) jar-dependencies (0.4.1) - json (2.7.5) - json (2.7.5-java) + json (2.8.1) + json (2.8.1-java) language_server-protocol (3.17.0.3) listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) @@ -67,12 +69,12 @@ GEM logger (1.6.1) minitest (5.25.1) parallel (1.26.3) - parser (3.3.5.0) + parser (3.3.6.0) ast (~> 2.4.1) racc - psych (5.1.2) + psych (5.2.0) stringio - psych (5.1.2-java) + psych (5.2.0-java) jar-dependencies (>= 0.1.7) public_suffix (6.0.1) racc (1.8.1) @@ -89,7 +91,7 @@ GEM rdoc (6.7.0) psych (>= 4.0.0) regexp_parser (2.9.2) - reline (0.5.10) + reline (0.5.11) io-console (~> 0.5) rexml (3.3.9) rspec (3.13.0) @@ -105,7 +107,7 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-support (3.13.1) - rubocop (1.67.0) + rubocop (1.68.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -115,7 +117,7 @@ GEM rubocop-ast (>= 1.32.2, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.33.0) + rubocop-ast (1.34.1) parser (>= 3.3.1.0) rubocop-capybara (2.21.0) rubocop (~> 1.41) @@ -151,7 +153,7 @@ GEM securerandom (>= 0.1) strscan (>= 1.0.0) terminal-table (>= 2, < 4) - stringio (3.1.1) + stringio (3.1.2) strscan (3.1.0) strscan (3.1.0-java) terminal-table (3.0.2) @@ -163,7 +165,7 @@ GEM addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - webrick (1.8.2) + webrick (1.9.0) websocket (1.2.11) yard (0.9.37) diff --git a/rb/lib/selenium/webdriver/bidi/log_handler.rb b/rb/lib/selenium/webdriver/bidi/log_handler.rb index 0ba7382927f2e..29b3d4dcab0d9 100644 --- a/rb/lib/selenium/webdriver/bidi/log_handler.rb +++ b/rb/lib/selenium/webdriver/bidi/log_handler.rb @@ -30,6 +30,7 @@ def initialize(bidi) end # @return [int] id of the handler + # steep:ignore:start def add_message_handler(type) subscribe_log_entry unless @log_entry_subscribed @bidi.add_callback('log.entryAdded') do |params| @@ -39,6 +40,7 @@ def add_message_handler(type) end end end + # steep:ignore:end # @param [int] id of the handler previously added def remove_message_handler(id) diff --git a/rb/lib/selenium/webdriver/bidi/struct.rb b/rb/lib/selenium/webdriver/bidi/struct.rb index 38d3e08e85221..1e54477818e84 100644 --- a/rb/lib/selenium/webdriver/bidi/struct.rb +++ b/rb/lib/selenium/webdriver/bidi/struct.rb @@ -37,8 +37,6 @@ def camel_to_snake(camel_str) end end end - end - - # BiDi + end # BiDi end # WebDriver end # Selenium diff --git a/rb/lib/selenium/webdriver/common/error.rb b/rb/lib/selenium/webdriver/common/error.rb index deece7d2e3b0f..ed452cb7377df 100644 --- a/rb/lib/selenium/webdriver/common/error.rb +++ b/rb/lib/selenium/webdriver/common/error.rb @@ -50,9 +50,11 @@ def initialize(msg = '') super(URLS[class_name] ? "#{msg}; #{SUPPORT_MSG} #{URLS[class_name]}" : msg) end + # steep:ignore:start def class_name - self.class.name&.split('::')&.last&.to_sym + self.class.name.split('::')&.last&.to_sym end + # steep:ignore:end end # diff --git a/rb/lib/selenium/webdriver/common/fedcm/account.rb b/rb/lib/selenium/webdriver/common/fedcm/account.rb index edefcd918e5c1..29f5974e198b6 100644 --- a/rb/lib/selenium/webdriver/common/fedcm/account.rb +++ b/rb/lib/selenium/webdriver/common/fedcm/account.rb @@ -30,9 +30,7 @@ class Account attr_reader :account_id, :email, :name, :given_name, :picture_url, :idp_config_url, :login_state, :terms_of_service_url, :privacy_policy_url - # Initializes a new account with the provided attributes. - # - # @param [Hash] + # steep:ignore:start def initialize(**args) @account_id = args['accountId'] @email = args['email'] @@ -44,6 +42,7 @@ def initialize(**args) @terms_of_service_url = args['termsOfServiceUrl'] @privacy_policy_url = args['privacyPolicyUrl'] end + # steep:ignore:end end # Account end # FedCM end # WebDriver diff --git a/rb/lib/selenium/webdriver/common/target_locator.rb b/rb/lib/selenium/webdriver/common/target_locator.rb index 9300d414d6d74..378fa7ea00c28 100644 --- a/rb/lib/selenium/webdriver/common/target_locator.rb +++ b/rb/lib/selenium/webdriver/common/target_locator.rb @@ -50,6 +50,7 @@ def parent_frame # @param type either :tab or :window # + # steep:ignore:start def new_window(type = :window) raise ArgumentError, "Valid types are :tab and :window, received: #{type.inspect}" unless %i[window tab].include?(type) @@ -70,6 +71,7 @@ def new_window(type = :window) window(handle) end end + # steep:ignore:end # # switch to the given window handle diff --git a/rb/lib/selenium/webdriver/remote/http/common.rb b/rb/lib/selenium/webdriver/remote/http/common.rb index 423dc5d7ece14..2f287e2703132 100644 --- a/rb/lib/selenium/webdriver/remote/http/common.rb +++ b/rb/lib/selenium/webdriver/remote/http/common.rb @@ -48,6 +48,7 @@ def close # hook for subclasses - will be called on Driver#quit end + # steep:ignore:start def call(verb, url, command_hash) url = server_url.merge(url) unless url.is_a?(URI) headers = common_headers.dup @@ -66,6 +67,7 @@ def call(verb, url, command_hash) request verb, url, headers, payload end + # steep:ignore:end private diff --git a/rb/sig/lib/selenium/webdriver/bidi.rbs b/rb/sig/lib/selenium/webdriver/bidi.rbs index 9f8395be94270..314dc70fdd5f3 100644 --- a/rb/sig/lib/selenium/webdriver/bidi.rbs +++ b/rb/sig/lib/selenium/webdriver/bidi.rbs @@ -7,7 +7,7 @@ module Selenium def initialize: (url: String) -> void - def add_callback: -> Integer + def add_callback: (String event) { () -> void } -> Integer def close: () -> nil diff --git a/rb/sig/lib/selenium/webdriver/bidi/log_handler.rbs b/rb/sig/lib/selenium/webdriver/bidi/log_handler.rbs index 47f94107b14ec..2506df056f819 100644 --- a/rb/sig/lib/selenium/webdriver/bidi/log_handler.rbs +++ b/rb/sig/lib/selenium/webdriver/bidi/log_handler.rbs @@ -12,9 +12,9 @@ module Selenium def initialize: (BiDi bidi) -> void - def add_message_handler: (String type) { (untyped) -> untyped } -> Integer + def add_message_handler: (String type) ?{ (untyped) -> untyped } -> Integer - def remove_message_handler: (Integer id) -> bool + def remove_message_handler: (Integer id) -> bool? private diff --git a/rb/sig/lib/selenium/webdriver/bidi/struct.rbs b/rb/sig/lib/selenium/webdriver/bidi/struct.rbs index 6fb893dd7e46d..ff4ab92c762e5 100644 --- a/rb/sig/lib/selenium/webdriver/bidi/struct.rbs +++ b/rb/sig/lib/selenium/webdriver/bidi/struct.rbs @@ -1,8 +1,8 @@ module Selenium module WebDriver class BiDi - class Struct < ::Struct - def self.new: (*untyped args) { (?) -> untyped } -> void + class Struct < ::Struct[untyped] + def self.new: (*untyped args) ?{ (self) [self: self] -> untyped } -> void def self.camel_to_snake: (String camel_str) -> String end diff --git a/rb/sig/lib/selenium/webdriver/common/driver_finder.rbs b/rb/sig/lib/selenium/webdriver/common/driver_finder.rbs index 4373fec706895..fc17ee073d3ee 100644 --- a/rb/sig/lib/selenium/webdriver/common/driver_finder.rbs +++ b/rb/sig/lib/selenium/webdriver/common/driver_finder.rbs @@ -19,6 +19,8 @@ module Selenium private def paths: -> untyped + + def to_args: -> Array[String] end end end diff --git a/rb/sig/lib/selenium/webdriver/common/error.rbs b/rb/sig/lib/selenium/webdriver/common/error.rbs index da8be68ee9f8c..224ee6ee29cee 100644 --- a/rb/sig/lib/selenium/webdriver/common/error.rbs +++ b/rb/sig/lib/selenium/webdriver/common/error.rbs @@ -7,7 +7,7 @@ module Selenium ERROR_URL: String - URLS: Hash[Symbol, String] + URLS: Hash[Symbol?, String] class WebDriverError < StandardError def initialize: (?String | Array[String] msg) -> void diff --git a/rb/sig/lib/selenium/webdriver/common/logger.rbs b/rb/sig/lib/selenium/webdriver/common/logger.rbs index 0b8f39a33ca76..69a167e4b9276 100644 --- a/rb/sig/lib/selenium/webdriver/common/logger.rbs +++ b/rb/sig/lib/selenium/webdriver/common/logger.rbs @@ -28,7 +28,7 @@ module Selenium def warn: (String message, ?id: Symbol | Array[Symbol] id) ?{ () -> void } -> void - def deprecate: (String old, ?String? new, ?id: Symbol | Array[Symbol] id, ?reference: String reference) { () -> void } -> (void) + def deprecate: (String old, ?String? new, ?id: Symbol | Array[Symbol] id, ?reference: String reference) ?{ () -> void } -> untyped def debug?: () -> bool @@ -36,7 +36,7 @@ module Selenium def create_logger: (String name, level: Symbol level) -> ::Logger - def discard_or_log: (Symbol level, String message, (Symbol | Array[::Symbol]) | [(Symbol | Array[Symbol])] id) ?{ () -> void } -> (void) + def discard_or_log: (Symbol level, String message, (Symbol | Array[::Symbol]) | [(Symbol | Array[Symbol])] id) ?{ () -> void } -> untyped end end end diff --git a/rb/sig/lib/selenium/webdriver/common/options.rbs b/rb/sig/lib/selenium/webdriver/common/options.rbs index adf1b2bb473c7..d2fe0ccd30b20 100644 --- a/rb/sig/lib/selenium/webdriver/common/options.rbs +++ b/rb/sig/lib/selenium/webdriver/common/options.rbs @@ -1,7 +1,7 @@ module Selenium module WebDriver class Options - @options: Hash[String | Symbol, String | Numeric | bool?] + @options: Hash[untyped, untyped] W3C_OPTIONS: Array[Symbol] diff --git a/rb/sig/lib/selenium/webdriver/common/selenium_manager.rbs b/rb/sig/lib/selenium/webdriver/common/selenium_manager.rbs index f4f0c58f00d81..c73ec88f61487 100644 --- a/rb/sig/lib/selenium/webdriver/common/selenium_manager.rbs +++ b/rb/sig/lib/selenium/webdriver/common/selenium_manager.rbs @@ -12,7 +12,7 @@ module Selenium def self.bin_path: () -> String - def self.binary_paths: (Array[String] arguments) -> Hash[untyped, Array[String]] + def self.binary_paths: (*String arguments) -> Hash[untyped, Array[String]] private diff --git a/rb/sig/lib/selenium/webdriver/common/service.rbs b/rb/sig/lib/selenium/webdriver/common/service.rbs index 788728741d3e1..da5a793919e55 100644 --- a/rb/sig/lib/selenium/webdriver/common/service.rbs +++ b/rb/sig/lib/selenium/webdriver/common/service.rbs @@ -5,6 +5,8 @@ module Selenium DEFAULT_PORT: untyped + DRIVER_PATH_ENV_KEY: String + self.@driver_path: untyped @executable_path: untyped diff --git a/rb/sig/lib/selenium/webdriver/common/websocket_connection.rbs b/rb/sig/lib/selenium/webdriver/common/websocket_connection.rbs index b0276a246d815..98ac289f081ed 100644 --- a/rb/sig/lib/selenium/webdriver/common/websocket_connection.rbs +++ b/rb/sig/lib/selenium/webdriver/common/websocket_connection.rbs @@ -35,7 +35,7 @@ module Selenium def initialize: (url: untyped) -> void - def add_callback: (untyped event, untyped id) -> untyped + def add_callback: (untyped event) { () -> void } -> untyped def close: () -> untyped diff --git a/rb/sig/lib/selenium/webdriver/fedcm/account.rbs b/rb/sig/lib/selenium/webdriver/fedcm/account.rbs index 72ae9bf8b5884..57859a9f1ca06 100644 --- a/rb/sig/lib/selenium/webdriver/fedcm/account.rbs +++ b/rb/sig/lib/selenium/webdriver/fedcm/account.rbs @@ -1,51 +1,31 @@ module Selenium module WebDriver module FedCM - # Represents an account displayed in a FedCm account list. - # See: https://w3c-fedid.github.io/FedCM/#dictdef-identityprovideraccount - # https://w3c-fedid.github.io/FedCM/#webdriver-accountlist class Account @account_id: String - @email: String - @name: String - @given_name: String - @picture_url: String - @idp_config_url: String - @login_state: String - @terms_of_service_url: String - @privacy_policy_url: String LOGIN_STATE_SIGNIN: String - LOGIN_STATE_SIGNUP: String attr_reader account_id: String - attr_reader email: String - attr_reader name: String - attr_reader given_name: String - attr_reader picture_url: String - attr_reader idp_config_url: String - attr_reader login_state: String - attr_reader terms_of_service_url: String - attr_reader privacy_policy_url: String - def initialize: (**untyped args) -> void + def initialize: (**String args) -> void end end end diff --git a/rb/sig/lib/selenium/webdriver/firefox/options.rbs b/rb/sig/lib/selenium/webdriver/firefox/options.rbs index 2fcb015d6430e..4f3b12a6487b8 100644 --- a/rb/sig/lib/selenium/webdriver/firefox/options.rbs +++ b/rb/sig/lib/selenium/webdriver/firefox/options.rbs @@ -6,7 +6,7 @@ module Selenium @profile: untyped - @options: Hash[Symbol, untyped] + @options: Hash[untyped, untyped] attr_accessor debugger_address: untyped @@ -30,7 +30,7 @@ module Selenium def log_level=: (untyped level) -> untyped - def enable_android: (?package: ::String, ?serial_number: untyped?, ?activity: untyped?, ?intent_arguments: untyped?) -> untyped + def enable_android: (?package: String, ?serial_number: untyped?, ?activity: untyped?, ?intent_arguments: untyped?) -> untyped private diff --git a/rb/sig/lib/selenium/webdriver/remote/bidi_bridge.rbs b/rb/sig/lib/selenium/webdriver/remote/bidi_bridge.rbs index cbb4fc665eb09..bb0c77cc36863 100644 --- a/rb/sig/lib/selenium/webdriver/remote/bidi_bridge.rbs +++ b/rb/sig/lib/selenium/webdriver/remote/bidi_bridge.rbs @@ -10,7 +10,7 @@ module Selenium def quit: () -> nil - def close: () -> nil + def close: () -> untyped end end end diff --git a/rb/sig/lib/selenium/webdriver/remote/bridge.rbs b/rb/sig/lib/selenium/webdriver/remote/bridge.rbs index 70520fd5f3aa1..8da1a8dac805d 100644 --- a/rb/sig/lib/selenium/webdriver/remote/bridge.rbs +++ b/rb/sig/lib/selenium/webdriver/remote/bridge.rbs @@ -48,7 +48,7 @@ module Selenium extend WebDriver::Safari::Features - def fedcm_account_list: -> [FedCM::Account] + def fedcm_account_list: -> Array[Hash[untyped, untyped]] def fedcm_dialog_type: -> String @@ -58,7 +58,7 @@ module Selenium def reset_fedcm_cooldown: -> nil - def select_fedcm_account: -> nil + def select_fedcm_account: (Integer index) -> nil def session_id: () -> untyped @@ -250,7 +250,7 @@ module Selenium private - def execute: (untyped command, ?::Hash[untyped, untyped] opts, ?untyped? command_hash) -> WebDriver::Remote::Response + def execute: (untyped command, ?::Hash[untyped, untyped] opts, ?untyped? command_hash) -> String def escaper: () -> untyped diff --git a/rb/sig/lib/selenium/webdriver/remote/response.rbs b/rb/sig/lib/selenium/webdriver/remote/response.rbs index 29c806ff74283..3afa65955917b 100644 --- a/rb/sig/lib/selenium/webdriver/remote/response.rbs +++ b/rb/sig/lib/selenium/webdriver/remote/response.rbs @@ -2,15 +2,15 @@ module Selenium module WebDriver module Remote class Response - @code: String + @code: Integer @payload: Hash[untyped, untyped] - attr_reader code: String + attr_reader code: Integer attr_reader payload: Hash[untyped, untyped] - def initialize: (String code, ?Hash[untyped, untyped]? payload) -> void + def initialize: (Integer code, ?Hash[untyped, untyped]? payload) -> void def error: () -> Error::WebDriverError? diff --git a/rb/sig/selenium/web_driver/script.rbs b/rb/sig/selenium/web_driver/script.rbs index 73804ed7d280a..0bcdcf8318cc3 100644 --- a/rb/sig/selenium/web_driver/script.rbs +++ b/rb/sig/selenium/web_driver/script.rbs @@ -6,13 +6,13 @@ module Selenium @log_handler: BiDi::LogHandler - def initialize: (BiDi bidi) -> void + def initialize: (Remote::BiDiBridge bidi) -> void - def add_console_message_handler: -> Integer + def add_console_message_handler: ?{ (untyped) -> untyped } -> Integer - def add_javascript_error_handler: -> Integer + def add_javascript_error_handler: ?{ (untyped) -> untyped } -> Integer - def remove_console_message_handler: (Integer id) -> bool + def remove_console_message_handler: (Integer id) -> bool? alias remove_javascript_error_handler remove_console_message_handler end