SampleCommentsCreator#last_comment_date doesn't depend on instance state (maybe move it to another class?) Open
def last_comment_date(topic)
- Read upRead up
- Exclude checks
A Utility Function is any instance method that has no dependency on the state of the instance.
Inconsistent indentation detected. Open
def members
@_members ||= (group.members - [prevy_bot]).to_a
end
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
COMMENT_SEEDS = YAML.load_file("db/seeds/terry_pratchett_quotes.yml")
- Read upRead up
- Exclude checks
Checks if uses of quotes match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
"No special symbols"
"No string interpolation"
"Just text"
# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"
Example: EnforcedStyle: double_quotes
# bad
'Just some text'
'No special chars or interpolation'
# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"
Inconsistent indentation detected. Open
def prevy_bot
@_prevy_bot ||= SampleUser.prevy_bot
end
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Inconsistent indentation detected. Open
def select_commenters_for(topic)
topic_creator = topic.user
@commenters = members.shuffle[0..comments_count] - [topic_creator]
end
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Inconsistent indentation detected. Open
def comments_count
rand(MIN_COMMENTS..MAX_COMMENTS) - 1
end
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Inconsistent indentation detected. Open
def build_comments_for(topic)
comment_seeds = COMMENT_SEEDS.shuffle
@commenters.each do |commenter|
comment = comment_seeds.pop
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Inconsistent indentation detected. Open
attr_reader :group, :topics
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Inconsistent indentation detected. Open
def update_topics_last_commented_at
topics.each do |topic|
topic.update_attribute(:last_commented_at, last_comment_date(topic))
end
end
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Inconsistent indentation detected. Open
def update_topics_comments_count
ActiveRecord::Base.connection.execute <<~SQL
UPDATE topics
SET comments_count = (SELECT count(1)
FROM topic_comments
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Inconsistent indentation detected. Open
def build_comments
topics.each do |topic|
select_commenters_for topic
build_comments_for topic
end
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Inconsistent indentation detected. Open
def run_comments_before_create_callbacks
@comments.each do |comment|
comment.run_callbacks(:create) { false }
end
end
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Prefer ranges when generating random numbers instead of integers with offsets. Open
rand(MIN_COMMENTS..MAX_COMMENTS) - 1
- Read upRead up
- Exclude checks
This cop checks for the use of randomly generated numbers, added/subtracted with integer literals, as well as those with Integer#succ and Integer#pred methods. Prefer using ranges instead, as it clearly states the intentions.
Example:
# bad
rand(6) + 1
1 + rand(6)
rand(6) - 1
1 - rand(6)
rand(6).succ
rand(6).pred
Random.rand(6) + 1
Kernel.rand(6) + 1
rand(0..5) + 1
# good
rand(1..6)
rand(1...7)
Inconsistent indentation detected. Open
def new_comment_for(topic, commenter, comment)
created_at_date = CREATION_DATE + rand(ONE_MINUTE..TWENTY_THREE_HOURS)
topic.comments.new(
user: commenter,
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Inconsistent indentation detected. Open
def last_comment_date(topic)
topic.comments.last.created_at
end
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Inconsistent indentation detected. Open
def create_comments
build_comments
run_comments_before_create_callbacks
TopicComment.import(@comments)
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end