debian-mirror-gitlab/rubocop/cop/database/establish_connection.rb

21 lines
555 B
Ruby
Raw Permalink Normal View History

2022-03-02 08:16:31 +05:30
# frozen_string_literal: true
module RuboCop
module Cop
module Database
2022-10-11 01:57:18 +05:30
class EstablishConnection < RuboCop::Cop::Base
2022-03-02 08:16:31 +05:30
MSG = "Don't establish new database connections, as this slows down " \
'tests and may result in new connections using an incorrect configuration'
def_node_matcher :establish_connection?, <<~PATTERN
(send (const ...) :establish_connection ...)
PATTERN
def on_send(node)
2022-10-11 01:57:18 +05:30
add_offense(node) if establish_connection?(node)
2022-03-02 08:16:31 +05:30
end
end
end
end
end