Showing 331 of 343 total issues
Space inside parentheses detected. Open
@backlog = ( @stories - @accepted_stories ).guaranteed_sort_by(&:position)
- Exclude checks
Use group[next_date] = accepted.fetch(next_date, group.fetch(next_date - 1.day, 0))
instead of group.merge!(next_date => accepted.fetch(next_date, group.fetch(next_date - 1.day, 0)))
. Open
group.merge!(next_date => accepted.fetch(next_date, group.fetch(next_date - 1.day, 0)))
- Read upRead up
- Exclude checks
This cop identifies places where Hash#merge!
can be replaced by
Hash#[]=
.
Example:
hash.merge!(a: 1)
hash.merge!({'key' => 'value'})
hash.merge!(a: 1, b: 2)
%w
-literals should be delimited by [
and ]
. Open
%w(started finished delivered accepted rejected).reduce({}) do |data, state|
- Read upRead up
- Exclude checks
This cop enforces the consistent usage of %
-literal delimiters.
Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.
Example:
# Style/PercentLiteralDelimiters:
# PreferredDelimiters:
# default: '[]'
# '%i': '()'
# good
%w[alpha beta] + %i(gamma delta)
# bad
%W(alpha #{beta})
# bad
%I(alpha beta)
Indent the right bracket the same as the start of the line where the left bracket is. Open
]
- Exclude checks
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
"Story Type", "Estimate", "Current State", "Started At", "Created at", "Accepted at",
- Exclude checks
Align .projects
with where("subject_type in ('Project', 'Story')")
on line 28. Open
.projects(ids)
- Exclude checks
Avoid multi-line chains of blocks. Open
end.map do |subject_type, activities|
- Read upRead up
- Exclude checks
This cop checks for chaining of a block after another block that spans multiple lines.
Example:
Thread.list.find_all do |t|
t.alive?
end.map do |t|
t.object_id
end
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if new_record? && password.blank? && password_confirmation.blank?
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
Tagging a string as html safe may be a security risk. Open
"window.CLOUDINARY_CONFIG = #{params.to_json};".html_safe,
- Read upRead up
- Exclude checks
This cop checks for the use of output safety calls like htmlsafe, raw, and safeconcat. These methods do not escape content. They simply return a SafeBuffer containing the content as is. Instead, use safe_join to join content and escape it and concat to concatenate content and escape it, ensuring its safety.
Example:
user_content = "hi"
# bad
"#{user_content}
".html_safe
=> ActiveSupport::SafeBuffer
"hi
"
# good
content_tag(:p, user_content)
=> ActiveSupport::SafeBuffer
"<b>hi</b>
"
# bad
out = ""
out << "#{user_content} "
out << "#{user_content} "
out.html_safe
=> ActiveSupport::SafeBuffer
"hi
hi "
# good
out = []
out << content_tag(:li, user_content)
out << content_tag(:li, user_content)
safe_join(out)
=> ActiveSupport::SafeBuffer
"<b>hi</b>
<b>hi</b> "
# bad
out = "trusted content
".html_safe
out.safe_concat(user_content)
=> ActiveSupport::SafeBuffer
"trusted_content
hi"
# good
out = "trusted content
".html_safe
out.concat(user_content)
=> ActiveSupport::SafeBuffer
"trusted_content
<b>hi</b>"
# safe, though maybe not good style
out = "trusted content"
result = out.concat(user_content)
=> String "trusted contenthi"
# because when rendered in ERB the String will be escaped:
<%= result %>
=> trusted content<b>hi</b>
# bad
(user_content + " " + content_tag(:span, user_content)).html_safe
=> ActiveSupport::SafeBuffer
"hi <span><b>hi</b></span>"
# good
safe_join([user_content, " ", content_tag(:span, user_content)])
=> ActiveSupport::SafeBuffer
"<b>hi</b> <span><b>hi</b></span>"
Redundant self
detected. Open
self.new(private_uri, bot_username).send(message)
- Read upRead up
- Exclude checks
This cop checks for redundant uses of self
.
self
is only needed when:
-
Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.
Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.
Example:
def bar :baz end
def foo(bar) self.bar # resolves name clash with argument end
def foo2 bar = 1 self.bar # resolves name clash with local variable end
-
Calling an attribute writer to prevent an local variable assignment
attr_writer :bar
def foo self.bar= 1 # Make sure above attr writer is called end
Special cases:
We allow uses of self
with operators because it would be awkward
otherwise.
Place the . on the next line, together with the method name. Open
@accepted_stories.
- Exclude checks
Line is too long. [122/100] Open
# with calculate_worst = false calculates the final project date based on the average velocity for the past 3 iterations
- Exclude checks
Use iterations.size.positive?
instead of iterations.size > 0
. Open
if iterations.size > 0
- Read upRead up
- Exclude checks
This cop checks for usage of comparison operators (==
,
>
, <
) to test numbers as zero, positive, or negative.
These can be replaced by their respective predicate methods.
The cop can also be configured to do the reverse.
The cop disregards nonzero?
as it its value is truthy or falsey,
but not true
and false
, and thus not always interchangeable with
!= 0
.
Example:
# EnforcedStyle: predicate (default)
# bad
foo == 0
0 > foo
bar.baz > 0
# good
foo.zero?
foo.negative?
bar.baz.positive?
Example:
# EnforcedStyle: comparison
# bad
foo.zero?
foo.negative?
bar.baz.positive?
# good
foo == 0
0 > foo
bar.baz > 0
Align .projects
with where("subject_type in ('Note', 'Task')")
on line 32. Open
.projects(ids)
- Exclude checks
Use find_by
instead of dynamic find_by_project_id
. Open
ownerships.find_by_project_id(project.id)&.is_owner
- Read upRead up
- Exclude checks
This cop checks dynamic find_by_*
methods.
Use find_by
instead of dynamic method.
See. https://github.com/bbatsov/rails-style-guide#find_by
Example:
# bad
User.find_by_name(name)
# bad
User.find_by_name_and_email(name)
# bad
User.find_by_email!(name)
# good
User.find_by(name: name)
# good
User.find_by(name: name, email: email)
# good
User.find_by!(email: email)
Place the . on the next line, together with the method name. Open
@accepted_stories = @stories.
- Exclude checks
Align reduce
with @accepted_stories.
on line 146. Open
reduce({}) do |group, iteration|
- Exclude checks
Space missing inside }. Open
data = (min_iteration..max_iteration).reduce({}) { |group, key| group.merge(key => 0)}
- Exclude checks
Space inside parentheses detected. Open
@backlog = ( @stories - @accepted_stories ).guaranteed_sort_by(&:position)
- Exclude checks
Space inside parentheses detected. Open
( days_apart / days_in_iteration ).floor + 1
- Exclude checks