From 9e302f7ee90c796ae09e6ca190e2db195cc8ff2d Mon Sep 17 00:00:00 2001 From: Siddarth Challa Date: Wed, 11 Dec 2024 18:17:02 -0500 Subject: [PATCH] rubocop linting --- lib/ruby_lsp/ruby_lsp_rails/completion.rb | 22 +++++++++++----------- test/ruby_lsp_rails/completion_test.rb | 11 +++++------ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/ruby_lsp/ruby_lsp_rails/completion.rb b/lib/ruby_lsp/ruby_lsp_rails/completion.rb index d2ead08e..36d84479 100644 --- a/lib/ruby_lsp/ruby_lsp_rails/completion.rb +++ b/lib/ruby_lsp/ruby_lsp_rails/completion.rb @@ -45,7 +45,7 @@ def handle_active_record_where_completions(node) return if resolved_class.nil? arguments = node.arguments&.arguments - existing_args = T.let({},T::Hash[String, T::Boolean]) + existing_args = T.let({}, T::Hash[String, T::Boolean]) if arguments.present? existing_args = get_call_node_arguments(arguments: arguments) end @@ -69,19 +69,19 @@ def handle_active_record_where_completions(node) def get_call_node_arguments(arguments:) existing_args = {} arguments.each do |argument| - if argument.is_a?(Prism::KeywordHashNode) - argument.elements.each do |e| - if e.is_a?(Prism::AssocNode) - key = e.key - if key.is_a?(Prism::SymbolNode) - id = key.value - existing_args[id] = true - end + next unless argument.is_a?(Prism::KeywordHashNode) + + argument.elements.each do |e| + next unless e.is_a?(Prism::AssocNode) + + key = e.key + if key.is_a?(Prism::SymbolNode) + id = key.value + existing_args[id] = true end end end - end - existing_args + existing_args end end end diff --git a/test/ruby_lsp_rails/completion_test.rb b/test/ruby_lsp_rails/completion_test.rb index bdc7636d..5ee14621 100644 --- a/test/ruby_lsp_rails/completion_test.rb +++ b/test/ruby_lsp_rails/completion_test.rb @@ -33,10 +33,10 @@ class CompletionTest < ActiveSupport::TestCase test "Does not suggest column if it already exists within .where as an arg and parantheses are not closed" do response = generate_completions_for_source(<<~RUBY, { line: 1, character: 28 }) # typed: false - User.where(id:, first_name:, + User.where(id:, first_name:,#{" "} RUBY - columns = [ "last_name", "age", "created_at", "updated_at", "country_id", "active" ] + columns = ["last_name", "age", "created_at", "updated_at", "country_id", "active"] assert_equal(columns.size, response.size) columns.each_with_index do |column, i| @@ -51,7 +51,7 @@ class CompletionTest < ActiveSupport::TestCase User.where(id:, first_name:, ) RUBY - columns = [ "last_name", "age", "created_at", "updated_at", "country_id", "active" ] + columns = ["last_name", "age", "created_at", "updated_at", "country_id", "active"] assert_equal(columns.size, response.size) columns.each_with_index do |column, i| @@ -61,15 +61,14 @@ class CompletionTest < ActiveSupport::TestCase end test "Does not provide suggestions when typing argument values" do - response = generate_completions_for_source(<<~RUBY, { line: 1, character: 14}) + response = generate_completions_for_source(<<~RUBY, { line: 1, character: 14 }) # typed: false - User.where(id: + User.where(id:#{" "} RUBY assert_equal(0, response.size) end - private def generate_completions_for_source(source, position)