From c9cd1a570f2583b57e58f82bffa285685ef065bd Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sun, 6 Apr 2025 14:14:48 +0100 Subject: [PATCH 1/4] Use RuboCop `Base` class not `Cop` - This was showing a deprecation warning with the latest RuboCop version. ``` warning: Inheriting from `RuboCop::Cop::Cop` is deprecated. Use `RuboCop::Cop::Base` instead. For more information, see https://docs.rubocop.org/rubocop/v1_upgrade_notes.html `` --- lib/rubocop/cop/graphql/heredoc.rb | 2 +- lib/rubocop/cop/graphql/overfetch.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rubocop/cop/graphql/heredoc.rb b/lib/rubocop/cop/graphql/heredoc.rb index 19f92d9d..030a10a5 100644 --- a/lib/rubocop/cop/graphql/heredoc.rb +++ b/lib/rubocop/cop/graphql/heredoc.rb @@ -5,7 +5,7 @@ module RuboCop module Cop module GraphQL # Public: Cop for enforcing non-interpolated GRAPHQL heredocs. - class Heredoc < Cop + class Heredoc < Base def on_dstr(node) check_str(node) end diff --git a/lib/rubocop/cop/graphql/overfetch.rb b/lib/rubocop/cop/graphql/overfetch.rb index bd98084d..c1a398c5 100644 --- a/lib/rubocop/cop/graphql/overfetch.rb +++ b/lib/rubocop/cop/graphql/overfetch.rb @@ -8,7 +8,7 @@ module RuboCop module Cop module GraphQL # Public: Rubocop for catching overfetched fields in ERB templates. - class Overfetch < Cop + class Overfetch < Base if defined?(RangeHelp) # rubocop 0.53 moved the #source_range method into this module include RangeHelp From ec817bb4850622005bc79c656a682c669ac5e558 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sun, 6 Apr 2025 14:17:07 +0100 Subject: [PATCH 2/4] Bump RuboCop to 1.73.2 --- graphql-client.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphql-client.gemspec b/graphql-client.gemspec index b5324df3..dea5a8c4 100644 --- a/graphql-client.gemspec +++ b/graphql-client.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| s.add_development_dependency "minitest", "~> 5.9" s.add_development_dependency "rake", "~> 13.2.1" s.add_development_dependency "rubocop-github" - s.add_development_dependency "rubocop", "~> 1.66.1" + s.add_development_dependency "rubocop", "~> 1.73.2" s.required_ruby_version = ">= 2.1.0" From 2fb9c8ffedf2693eeecd8c0424db84c96c2bb53f Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sun, 6 Apr 2025 14:22:53 +0100 Subject: [PATCH 3/4] `location` is not a valid keyword for `add_offense` ``` Scanning /Users/issyl0/repos/github/graphql-client/test/test_client.rb An error occurred while GraphQL/Heredoc cop was inspecting /Users/issyl0/repos/github/graphql-client/test/test_client.rb:724:19. unknown keyword: :location /Users/issyl0/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.73.2/lib/rubocop/cop/base.rb:201:in `add_offense' /Users/issyl0/repos/github/graphql-client/lib/rubocop/cop/graphql/heredoc.rb:22:in `block in check_str' ``` --- lib/rubocop/cop/graphql/heredoc.rb | 4 ++-- lib/rubocop/cop/graphql/overfetch.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/rubocop/cop/graphql/heredoc.rb b/lib/rubocop/cop/graphql/heredoc.rb index 030a10a5..43c2b4ec 100644 --- a/lib/rubocop/cop/graphql/heredoc.rb +++ b/lib/rubocop/cop/graphql/heredoc.rb @@ -19,11 +19,11 @@ def check_str(node) return unless node.location.expression.source =~ /^<<(-|~)?GRAPHQL/ node.each_child_node(:begin) do |begin_node| - add_offense(begin_node, location: :expression, message: "Do not interpolate variables into GraphQL queries, " \ + add_offense(begin_node, message: "Do not interpolate variables into GraphQL queries, " \ "used variables instead.") end - add_offense(node, location: :expression, message: "GraphQL heredocs should be quoted. <<-'GRAPHQL'") + add_offense(node, message: "GraphQL heredocs should be quoted. <<-'GRAPHQL'") end def autocorrect(node) diff --git a/lib/rubocop/cop/graphql/overfetch.rb b/lib/rubocop/cop/graphql/overfetch.rb index c1a398c5..182fe838 100644 --- a/lib/rubocop/cop/graphql/overfetch.rb +++ b/lib/rubocop/cop/graphql/overfetch.rb @@ -42,7 +42,7 @@ def investigate(processed_source) visitor.fields.each do |field, count| next if count > 0 - add_offense(nil, location: visitor.ranges[field], message: "GraphQL field '#{field}' query but was not used in template.") + add_offense(nil, message: "GraphQL field '#{field}' query but was not used in template.") end end From 77101cd6ebe10862f2429d85dbcad7daed45d436 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Mon, 7 Apr 2025 11:14:09 +0100 Subject: [PATCH 4/4] Autofix new RuboCop offenses --- test/test_client_errors.rb | 2 +- test/test_client_schema.rb | 2 +- test/test_query_result.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_client_errors.rb b/test/test_client_errors.rb index 3937d48b..f7f49af7 100644 --- a/test/test_client_errors.rb +++ b/test/test_client_errors.rb @@ -310,7 +310,7 @@ def test_errors_collection "errors" => [ { "message" => "b00m", - "locations" => [{"line" => 1, "column" => 3}], + "locations" => [{ "line" => 1, "column" => 3 }], "path" => ["nullableError"] } ] diff --git a/test/test_client_schema.rb b/test/test_client_schema.rb index 34d681e6..bb8d7fbb 100644 --- a/test/test_client_schema.rb +++ b/test/test_client_schema.rb @@ -61,7 +61,7 @@ def test_dump_schema_io def test_dump_schema_context conn = FakeConn.new - GraphQL::Client.dump_schema(conn, StringIO.new, context: { user_id: 1}) + GraphQL::Client.dump_schema(conn, StringIO.new, context: { user_id: 1 }) assert_equal({ user_id: 1 }, conn.context) end end diff --git a/test/test_query_result.rb b/test/test_query_result.rb index ed6cd83e..0930eeea 100644 --- a/test/test_query_result.rb +++ b/test/test_query_result.rb @@ -270,7 +270,7 @@ def test_snakecase_field_aliases GRAPHQL person = Temp::Person.new(@client.query(Temp::Query).data.me) - raw_result = {"firstName"=>"Joshua", "lastName"=>"Peek"} + raw_result = { "firstName" => "Joshua", "lastName" => "Peek" } assert_equal raw_result, person.to_h assert_equal raw_result, person.to_hash