浏览代码

Fix RuboCop offense Performance/BlockGivenWithExplicitBlock (#38146).


git-svn-id: https://svn.redmine.org/redmine/trunk@22027 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/5.1.0
Go MAEDA 1年前
父节点
当前提交
3942177f49

+ 0
- 13
.rubocop_todo.yml 查看文件

@@ -486,19 +486,6 @@ Naming/VariableNumber:
- '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:

+ 3
- 3
app/controllers/account_controller.rb 查看文件

@@ -378,7 +378,7 @@ class AccountController < ApplicationController
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

@@ -394,7 +394,7 @@ class AccountController < ApplicationController
flash[:notice] = l(:notice_account_activated)
redirect_to my_account_path
else
yield if block_given?
yield if block
end
end

@@ -407,7 +407,7 @@ class AccountController < ApplicationController
Mailer.deliver_account_activation_request(user)
account_pending(user)
else
yield if block_given?
yield if block
end
end


+ 1
- 1
app/controllers/application_controller.rb 查看文件

@@ -552,7 +552,7 @@ class ApplicationController < ActionController::Base
else
if args.any?
redirect_to *args
elsif block_given?
elsif block
yield
else
raise "#redirect_to_referer_or takes arguments or a block"

+ 2
- 2
app/helpers/application_helper.rb 查看文件

@@ -252,7 +252,7 @@ module ApplicationHelper

# 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
@@ -440,7 +440,7 @@ module ApplicationHelper
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

+ 1
- 1
app/models/mailer.rb 查看文件

@@ -703,7 +703,7 @@ class Mailer < ActionMailer::Base
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|

+ 2
- 2
app/models/user.rb 查看文件

@@ -750,7 +750,7 @@ class User < Principal
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?
@@ -769,7 +769,7 @@ class User < Principal
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

+ 1
- 1
lib/redmine/scm/adapters/abstract_adapter.rb 查看文件

@@ -267,7 +267,7 @@ module Redmine
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)

+ 1
- 1
lib/redmine/views/builders.rb 查看文件

@@ -34,7 +34,7 @@ module Redmine
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

+ 2
- 2
lib/redmine/views/builders/structure.rb 查看文件

@@ -58,7 +58,7 @@ module Redmine
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)
@@ -68,7 +68,7 @@ module Redmine
end
end
end
if block_given?
if block
@struct << (args.first.is_a?(Hash) ? args.first : {})
yield(self)
ret = @struct.pop

+ 2
- 2
lib/redmine/wiki_formatting/macros.rb 查看文件

@@ -84,7 +84,7 @@ module Redmine
# 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.
@@ -154,7 +154,7 @@ module Redmine
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


正在加载...
取消
保存