Patch #38146 » 0002-Fix-RuboCop-offense-Performance-BlockGivenWithExplic.patch
| .rubocop_todo.yml | ||
|---|---|---|
| 486 | 486 |
- 'test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb' |
| 487 | 487 |
- 'test/unit/project_test.rb' |
| 488 | 488 | |
| 489 |
# This cop supports safe autocorrection (--autocorrect). |
|
| 490 |
Performance/BlockGivenWithExplicitBlock: |
|
| 491 |
Exclude: |
|
| 492 |
- 'app/controllers/account_controller.rb' |
|
| 493 |
- 'app/controllers/application_controller.rb' |
|
| 494 |
- 'app/helpers/application_helper.rb' |
|
| 495 |
- 'app/models/mailer.rb' |
|
| 496 |
- 'app/models/user.rb' |
|
| 497 |
- 'lib/redmine/scm/adapters/abstract_adapter.rb' |
|
| 498 |
- 'lib/redmine/views/builders.rb' |
|
| 499 |
- 'lib/redmine/views/builders/structure.rb' |
|
| 500 |
- 'lib/redmine/wiki_formatting/macros.rb' |
|
| 501 | ||
| 502 | 489 |
# Configuration parameters: MinSize. |
| 503 | 490 |
Performance/CollectionLiteralInLoop: |
| 504 | 491 |
Exclude: |
| app/controllers/account_controller.rb | ||
|---|---|---|
| 378 | 378 |
flash[:notice] = l(:notice_account_register_done, :email => ERB::Util.h(user.mail)) |
| 379 | 379 |
redirect_to signin_path |
| 380 | 380 |
else |
| 381 |
yield if block_given?
|
|
| 381 |
yield if block |
|
| 382 | 382 |
end |
| 383 | 383 |
end |
| 384 | 384 | |
| ... | ... | |
| 394 | 394 |
flash[:notice] = l(:notice_account_activated) |
| 395 | 395 |
redirect_to my_account_path |
| 396 | 396 |
else |
| 397 |
yield if block_given?
|
|
| 397 |
yield if block |
|
| 398 | 398 |
end |
| 399 | 399 |
end |
| 400 | 400 | |
| ... | ... | |
| 407 | 407 |
Mailer.deliver_account_activation_request(user) |
| 408 | 408 |
account_pending(user) |
| 409 | 409 |
else |
| 410 |
yield if block_given?
|
|
| 410 |
yield if block |
|
| 411 | 411 |
end |
| 412 | 412 |
end |
| 413 | 413 | |
| app/controllers/application_controller.rb | ||
|---|---|---|
| 552 | 552 |
else |
| 553 | 553 |
if args.any? |
| 554 | 554 |
redirect_to *args |
| 555 |
elsif block_given?
|
|
| 555 |
elsif block |
|
| 556 | 556 |
yield |
| 557 | 557 |
else |
| 558 | 558 |
raise "#redirect_to_referer_or takes arguments or a block" |
| app/helpers/application_helper.rb | ||
|---|---|---|
| 252 | 252 | |
| 253 | 253 |
# Helper that formats object for html or text rendering |
| 254 | 254 |
def format_object(object, html=true, &block) |
| 255 |
if block_given?
|
|
| 255 |
if block |
|
| 256 | 256 |
object = yield object |
| 257 | 257 |
end |
| 258 | 258 |
case object.class.name |
| ... | ... | |
| 440 | 440 |
classes = (ancestors.empty? ? 'root' : 'child') |
| 441 | 441 |
classes += ' archived' if project.archived? |
| 442 | 442 |
s << "<li class='#{classes}'><div class='#{classes}'>"
|
| 443 |
s << h(block_given? ? capture(project, &block) : project.name)
|
|
| 443 |
s << h(block ? capture(project, &block) : project.name) |
|
| 444 | 444 |
s << "</div>\n" |
| 445 | 445 |
ancestors << project |
| 446 | 446 |
end |
| app/models/mailer.rb | ||
|---|---|---|
| 703 | 703 |
headers[:references] = @references_objects.collect {|o| "<#{self.class.references_for(o, @user)}>"}.join(' ')
|
| 704 | 704 |
end |
| 705 | 705 | |
| 706 |
if block_given?
|
|
| 706 |
if block |
|
| 707 | 707 |
super headers, &block |
| 708 | 708 |
else |
| 709 | 709 |
super headers do |format| |
| app/models/user.rb | ||
|---|---|---|
| 750 | 750 |
roles.any? do |role| |
| 751 | 751 |
(context.is_public? || role.member?) && |
| 752 | 752 |
role.allowed_to?(action) && |
| 753 |
(block_given? ? yield(role, self) : true)
|
|
| 753 |
(block ? yield(role, self) : true) |
|
| 754 | 754 |
end |
| 755 | 755 |
elsif context && context.is_a?(Array) |
| 756 | 756 |
if context.empty? |
| ... | ... | |
| 769 | 769 |
roles = self.roles.to_a | [builtin_role] |
| 770 | 770 |
roles.any? do |role| |
| 771 | 771 |
role.allowed_to?(action) && |
| 772 |
(block_given? ? yield(role, self) : true)
|
|
| 772 |
(block ? yield(role, self) : true) |
|
| 773 | 773 |
end |
| 774 | 774 |
else |
| 775 | 775 |
false |
| lib/redmine/scm/adapters/abstract_adapter.rb | ||
|---|---|---|
| 267 | 267 |
IO.popen(cmd, mode) do |io| |
| 268 | 268 |
io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding)
|
| 269 | 269 |
io.close_write unless options[:write_stdin] |
| 270 |
yield(io) if block_given?
|
|
| 270 |
yield(io) if block |
|
| 271 | 271 |
end |
| 272 | 272 |
rescue => e |
| 273 | 273 |
msg = strip_credential(e.message) |
| lib/redmine/views/builders.rb | ||
|---|---|---|
| 34 | 34 |
response.status = 406 |
| 35 | 35 |
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" |
| 36 | 36 |
end |
| 37 |
if block_given?
|
|
| 37 |
if block |
|
| 38 | 38 |
yield(builder) |
| 39 | 39 |
else |
| 40 | 40 |
builder |
| lib/redmine/views/builders/structure.rb | ||
|---|---|---|
| 58 | 58 |
else |
| 59 | 59 |
value = encode_value(args.first) |
| 60 | 60 |
if @struct.last.is_a?(Array) |
| 61 |
if args.size == 1 && !block_given?
|
|
| 61 |
if args.size == 1 && !block |
|
| 62 | 62 |
@struct.last << value |
| 63 | 63 |
else |
| 64 | 64 |
@struct.last << (args.last || {}).merge(:value => value)
|
| ... | ... | |
| 68 | 68 |
end |
| 69 | 69 |
end |
| 70 | 70 |
end |
| 71 |
if block_given?
|
|
| 71 |
if block |
|
| 72 | 72 |
@struct << (args.first.is_a?(Hash) ? args.first : {})
|
| 73 | 73 |
yield(self) |
| 74 | 74 |
ret = @struct.pop |
| lib/redmine/wiki_formatting/macros.rb | ||
|---|---|---|
| 84 | 84 |
# end |
| 85 | 85 |
# end |
| 86 | 86 |
def register(&block) |
| 87 |
class_eval(&block) if block_given?
|
|
| 87 |
class_eval(&block) if block |
|
| 88 | 88 |
end |
| 89 | 89 | |
| 90 | 90 |
# Defines a new macro with the given name, options and block. |
| ... | ... | |
| 154 | 154 |
unless /\A\w+\z/.match?(name.to_s) |
| 155 | 155 |
raise "Invalid macro name: #{name} (only 0-9, A-Z, a-z and _ characters are accepted)"
|
| 156 | 156 |
end |
| 157 |
unless block_given?
|
|
| 157 |
unless block |
|
| 158 | 158 |
raise "Can not create a macro without a block!" |
| 159 | 159 |
end |
| 160 | 160 | |