From f3191f8a7208a26bff4e58ee5bb77a6d64e078f2 Mon Sep 17 00:00:00 2001 From: sue445 Date: Wed, 20 Oct 2021 22:02:51 +0900 Subject: [PATCH] Allow variable to find_xquery --- lib/rubocop/cop/isucon/mixin/mysql2_methods.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/rubocop/cop/isucon/mixin/mysql2_methods.rb b/lib/rubocop/cop/isucon/mixin/mysql2_methods.rb index 0c0f7440..8c5d6221 100644 --- a/lib/rubocop/cop/isucon/mixin/mysql2_methods.rb +++ b/lib/rubocop/cop/isucon/mixin/mysql2_methods.rb @@ -9,17 +9,19 @@ module Mysql2Methods extend NodePattern::Macros def_node_search :find_xquery, <<~PATTERN - (send (send nil? _) {:xquery | :query} (${str dstr} $...) ...) + (send (send nil? _) {:xquery | :query} (${str dstr lvar ivar cvar} $...) ...) PATTERN # @param node [RuboCop::AST::Node] # @yieldparam type [Symbol] Node type. one of `:str`, `:dstr` - # @yieldparam root_gda [RuboCop::Isucon::GDA::Client] + # @yieldparam root_gda [RuboCop::Isucon::GDA::Client,nil] + # + # @note If arguments of `db.xquery` isn't string, `root_gda` is `nil` def with_xquery(node) find_xquery(node) do |type, params| sql = xquery_param(type: type, params: params) - root_gda = RuboCop::Isucon::GDA::Client.new(sql) + root_gda = sql ? RuboCop::Isucon::GDA::Client.new(sql) : nil yield type, root_gda end