Skip to content

Commit a33ddc7

Browse files
committed
use PRISM_PARSER in rails/prefer_nor_conditions
1 parent ec6253d commit a33ddc7

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/rails/prefer_nor_conditions.rb

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
Synvert::Rewriter.new 'rails', 'prefer_nor_conditions' do
4-
configure(parser: Synvert::PARSER_PARSER)
4+
configure(parser: Synvert::PRISM_PARSER)
55

66
description <<~EOS
77
Prefer NOR conditions
@@ -20,10 +20,13 @@
2020
if_gem 'rails', '>= 6.0'
2121

2222
within_files Synvert::ALL_RUBY_FILES + Synvert::ALL_RAKE_FILES do
23-
find_node '.send[receiver=.send[message=where][arguments.size=0]][message=not][arguments.size=1][arguments.0=.hash[pairs.length>1]]' do
24-
new_source = node.arguments[0].pairs.map { |pair| "where.not(#{pair.to_source})" }
23+
with_node node_type: 'call_node',
24+
receiver: { node_type: 'call_node', name: 'where', arguments: nil },
25+
name: 'not',
26+
arguments: { node_type: 'arguments_node', arguments: { size: 1, first: { node_type: 'keyword_hash_node', elements: { length: { gt: 1 } } } } } do
27+
new_source = node.arguments.arguments.first.elements.map { |element| "where.not(#{element.to_source})" }
2528
.join('.')
26-
replace 'receiver.message', :message, :parentheses, with: new_source
29+
replace 'receiver.message', :closing, with: new_source
2730
end
2831
end
2932
end

0 commit comments

Comments
 (0)