Patch #38146 » 0002-Fix-RuboCop-offense-Performance-BlockGivenWithExplic.patch
| .rubocop_todo.yml | ||
|---|---|---|
|
- 'test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb'
|
||
|
- 'test/unit/project_test.rb'
|
||
|
# This cop supports safe autocorrection (--autocorrect).
|
||
|
Performance/BlockGivenWithExplicitBlock:
|
||
|
Exclude:
|
||
|
- 'app/controllers/account_controller.rb'
|
||
|
- 'app/controllers/application_controller.rb'
|
||
|
- 'app/helpers/application_helper.rb'
|
||
|
- 'app/models/mailer.rb'
|
||
|
- 'app/models/user.rb'
|
||
|
- 'lib/redmine/scm/adapters/abstract_adapter.rb'
|
||
|
- 'lib/redmine/views/builders.rb'
|
||
|
- 'lib/redmine/views/builders/structure.rb'
|
||
|
- 'lib/redmine/wiki_formatting/macros.rb'
|
||
|
# Configuration parameters: MinSize.
|
||
|
Performance/CollectionLiteralInLoop:
|
||
|
Exclude:
|
||
| app/controllers/account_controller.rb | ||
|---|---|---|
|
flash[:notice] = l(:notice_account_register_done, :email => ERB::Util.h(user.mail))
|
||
|
redirect_to signin_path
|
||
|
else
|
||
|
yield if block_given?
|
||
|
yield if block
|
||
|
end
|
||
|
end
|
||
| ... | ... | |
|
flash[:notice] = l(:notice_account_activated)
|
||
|
redirect_to my_account_path
|
||
|
else
|
||
|
yield if block_given?
|
||
|
yield if block
|
||
|
end
|
||
|
end
|
||
| ... | ... | |
|
Mailer.deliver_account_activation_request(user)
|
||
|
account_pending(user)
|
||
|
else
|
||
|
yield if block_given?
|
||
|
yield if block
|
||
|
end
|
||
|
end
|
||
| app/controllers/application_controller.rb | ||
|---|---|---|
|
else
|
||
|
if args.any?
|
||
|
redirect_to *args
|
||
|
elsif block_given?
|
||
|
elsif block
|
||
|
yield
|
||
|
else
|
||
|
raise "#redirect_to_referer_or takes arguments or a block"
|
||
| app/helpers/application_helper.rb | ||
|---|---|---|
|
# Helper that formats object for html or text rendering
|
||
|
def format_object(object, html=true, &block)
|
||
|
if block_given?
|
||
|
if block
|
||
|
object = yield object
|
||
|
end
|
||
|
case object.class.name
|
||
| ... | ... | |
|
classes = (ancestors.empty? ? 'root' : 'child')
|
||
|
classes += ' archived' if project.archived?
|
||
|
s << "<li class='#{classes}'><div class='#{classes}'>"
|
||
|
s << h(block_given? ? capture(project, &block) : project.name)
|
||
|
s << h(block ? capture(project, &block) : project.name)
|
||
|
s << "</div>\n"
|
||
|
ancestors << project
|
||
|
end
|
||
| app/models/mailer.rb | ||
|---|---|---|
|
headers[:references] = @references_objects.collect {|o| "<#{self.class.references_for(o, @user)}>"}.join(' ')
|
||
|
end
|
||
|
if block_given?
|
||
|
if block
|
||
|
super headers, &block
|
||
|
else
|
||
|
super headers do |format|
|
||
| app/models/user.rb | ||
|---|---|---|
|
roles.any? do |role|
|
||
|
(context.is_public? || role.member?) &&
|
||
|
role.allowed_to?(action) &&
|
||
|
(block_given? ? yield(role, self) : true)
|
||
|
(block ? yield(role, self) : true)
|
||
|
end
|
||
|
elsif context && context.is_a?(Array)
|
||
|
if context.empty?
|
||
| ... | ... | |
|
roles = self.roles.to_a | [builtin_role]
|
||
|
roles.any? do |role|
|
||
|
role.allowed_to?(action) &&
|
||
|
(block_given? ? yield(role, self) : true)
|
||
|
(block ? yield(role, self) : true)
|
||
|
end
|
||
|
else
|
||
|
false
|
||
| lib/redmine/scm/adapters/abstract_adapter.rb | ||
|---|---|---|
|
IO.popen(cmd, mode) do |io|
|
||
|
io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding)
|
||
|
io.close_write unless options[:write_stdin]
|
||
|
yield(io) if block_given?
|
||
|
yield(io) if block
|
||
|
end
|
||
|
rescue => e
|
||
|
msg = strip_credential(e.message)
|
||
| lib/redmine/views/builders.rb | ||
|---|---|---|
|
response.status = 406
|
||
|
return "We couldn't handle your request, sorry. If you were trying to access the API, make sure to append .json or .xml to your request URL.\n"
|
||
|
end
|
||
|
if block_given?
|
||
|
if block
|
||
|
yield(builder)
|
||
|
else
|
||
|
builder
|
||
| lib/redmine/views/builders/structure.rb | ||
|---|---|---|
|
else
|
||
|
value = encode_value(args.first)
|
||
|
if @struct.last.is_a?(Array)
|
||
|
if args.size == 1 && !block_given?
|
||
|
if args.size == 1 && !block
|
||
|
@struct.last << value
|
||
|
else
|
||
|
@struct.last << (args.last || {}).merge(:value => value)
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
end
|
||
|
if block_given?
|
||
|
if block
|
||
|
@struct << (args.first.is_a?(Hash) ? args.first : {})
|
||
|
yield(self)
|
||
|
ret = @struct.pop
|
||
| lib/redmine/wiki_formatting/macros.rb | ||
|---|---|---|
|
# end
|
||
|
# end
|
||
|
def register(&block)
|
||
|
class_eval(&block) if block_given?
|
||
|
class_eval(&block) if block
|
||
|
end
|
||
|
# Defines a new macro with the given name, options and block.
|
||
| ... | ... | |
|
unless /\A\w+\z/.match?(name.to_s)
|
||
|
raise "Invalid macro name: #{name} (only 0-9, A-Z, a-z and _ characters are accepted)"
|
||
|
end
|
||
|
unless block_given?
|
||
|
unless block
|
||
|
raise "Can not create a macro without a block!"
|
||
|
end
|
||