Skip to content

Commit

Permalink
Merge pull request #1178 from koic/require_rubocop_ast_1_30
Browse files Browse the repository at this point in the history
Require RuboCop AST 1.30.0+
  • Loading branch information
koic authored Nov 5, 2023
2 parents 4c1d89f + af55bb1 commit dc6cebc
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 20 deletions.
1 change: 1 addition & 0 deletions changelog/change_require_rubocop_ast_1_30.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1178](https://github.com/rubocop/rubocop-rails/pull/1178): Require RuboCop AST 1.30.0+. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/after_commit_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def on_class(class_node)
seen_callback_names = {}

each_after_commit_callback(class_node) do |node|
callback_name = node.arguments[0].value
callback_name = node.first_argument.value
if seen_callback_names.key?(callback_name)
add_offense(node, message: format(MSG, name: callback_name))
else
Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/cop/rails/bulk_change_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def combinable_transformations
# @param node [RuboCop::AST::SendNode]
def add_offense_for_alter_methods(node)
# arguments: [{(sym :table)(str "table")} ...]
table_node = node.arguments[0]
table_node = node.first_argument
return unless table_node.is_a? RuboCop::AST::BasicLiteralNode

message = format(MSG_FOR_ALTER_METHODS, table: table_node.value)
Expand All @@ -234,10 +234,10 @@ def initialize
# @param new_node [RuboCop::AST::SendNode]
def process(new_node)
# arguments: [{(sym :table)(str "table")} ...]
table_node = new_node.arguments[0]
table_node = new_node.first_argument
if table_node.is_a? RuboCop::AST::BasicLiteralNode
flush unless @nodes.all? do |node|
node.arguments[0].value.to_s == table_node.value.to_s
node.first_argument.value.to_s == table_node.value.to_s
end
@nodes << new_node
else
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/dangerous_column_names.rb
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def column_name_node_from(node)
when :rename_column
node.arguments[2]
when *COLUMN_TYPE_METHOD_NAMES
node.arguments[0]
node.first_argument
end
end

Expand Down
10 changes: 5 additions & 5 deletions lib/rubocop/cop/rails/file_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ def autocorrect_slash_after_rails_root_in_dstr(corrector, node, rails_root_index

def autocorrect_extension_after_rails_root_join_in_dstr(corrector, node, rails_root_index, extension_node)
rails_root_node = node.children[rails_root_index].children.first
return unless rails_root_node.arguments.last.str_type?
return unless rails_root_node.last_argument.str_type?

corrector.insert_before(rails_root_node.arguments.last.location.end, extension_node.source)
corrector.insert_before(rails_root_node.last_argument.location.end, extension_node.source)
corrector.remove(extension_node)
end

Expand All @@ -174,7 +174,7 @@ def autocorrect_file_join(corrector, node)
corrector.remove(
range_with_surrounding_space(
range_with_surrounding_comma(
node.arguments.first.source_range,
node.first_argument.source_range,
:right
),
side: :right
Expand All @@ -187,7 +187,7 @@ def autocorrect_file_join(corrector, node)
end

def autocorrect_rails_root_join_with_string_arguments(corrector, node)
corrector.replace(node.arguments.first, %("#{node.arguments.map(&:value).join('/')}"))
corrector.replace(node.first_argument, %("#{node.arguments.map(&:value).join('/')}"))
node.arguments[1..].each do |argument|
corrector.remove(
range_with_surrounding_comma(
Expand Down Expand Up @@ -221,7 +221,7 @@ def find_rails_root_index(node)
end

def append_argument(corrector, node, argument_source)
corrector.insert_after(node.arguments.last, %(, "#{argument_source}"))
corrector.insert_after(node.last_argument, %(, "#{argument_source}"))
end

def replace_with_rails_root_join(corrector, node, argument_source)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/inverse_of.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def options_contain_inverse_of?(options)

def with_options_arguments(recv, node)
blocks = node.each_ancestor(:block).select do |block|
block.send_node.command?(:with_options) && same_context_in_with_options?(block.arguments.first, recv)
block.send_node.command?(:with_options) && same_context_in_with_options?(block.first_argument, recv)
end
blocks.flat_map { |n| n.send_node.arguments }
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/rails/rake_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def correct_task_dependency(task_name)
end

def task_name(node)
first_arg = node.arguments[0]
first_arg = node.first_argument
case first_arg&.type
when :sym, :str
first_arg.value.to_sym
Expand All @@ -97,7 +97,7 @@ def with_arguments?(node)
end

def with_dependencies?(node)
first_arg = node.arguments[0]
first_arg = node.first_argument
return false unless first_arg

if first_arg.hash_type?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def redundant_receiver?(send_nodes, node)
else
return false if node.arguments.empty?

arg = node.arguments.first
arg = node.first_argument
->(n) { same_value?(arg, n.receiver) }
end

Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/rails/reversible_migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@ def reversible_change_table_call?(node)
when :change
false
when :remove
target_rails_version >= 6.1 && all_hash_key?(node.arguments.last, :type)
target_rails_version >= 6.1 && all_hash_key?(node.last_argument, :type)
when :change_default, :change_column_default, :change_table_comment,
:change_column_comment
all_hash_key?(node.arguments.last, :from, :to)
all_hash_key?(node.last_argument, :from, :to)
else
true
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/unique_validation_without_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def class_node(node)
end

def uniqueness_part(node)
pairs = node.arguments.last
pairs = node.last_argument
return unless pairs&.hash_type?

pairs.each_pair.find do |pair|
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def on_send(node)
range = node.loc.selector

add_offense(range, message: message(node)) do |corrector|
last_argument = node.arguments.last
last_argument = node.last_argument
return if !last_argument.literal? && !last_argument.splat_type? && !frozen_array_argument?(last_argument)

corrector.replace(range, 'validates')
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/rails/schema_loader/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def initialize(node)
private

def analyze_keywords!(node)
pairs = node.arguments.last
pairs = node.last_argument
return unless pairs.hash_type?

pairs.each_pair do |k, v|
Expand Down Expand Up @@ -158,7 +158,7 @@ def build_columns_or_expr(columns)
end

def analyze_keywords!(node)
pairs = node.arguments.last
pairs = node.last_argument
return unless pairs.hash_type?

pairs.each_pair do |k, v|
Expand Down
1 change: 1 addition & 0 deletions rubocop-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ Gem::Specification.new do |s|
# introduced in rack 1.1
s.add_runtime_dependency 'rack', '>= 1.1'
s.add_runtime_dependency 'rubocop', '>= 1.33.0', '< 2.0'
s.add_runtime_dependency 'rubocop-ast', '>= 1.30.0', '< 2.0'
end

0 comments on commit dc6cebc

Please sign in to comment.