Rubocop fixes (#6904)

* Run rubocop -a

* Regenerate rubocop todo

* Fix Lint/UselessAssignment

* Fix RSpec/RepeatedDescription

* Fix Style/GuardClause

* Fix Style/NumericPredicate

* Regenerate rubocop todo
This commit is contained in:
rhymes 2020-03-27 15:30:59 +01:00 committed by GitHub
parent f2696b6c80
commit d03c751c65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 43 deletions

View file

@ -7,33 +7,30 @@ require:
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-02-18 09:06:00 +0100 using RuboCop version 0.79.0.
# on 2020-03-27 09:48:49 +0100 using RuboCop version 0.79.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 241
# Offense count: 247
Metrics/AbcSize:
Max: 75
# Offense count: 10
# Offense count: 7
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 62
# Offense count: 8
# Offense count: 3
# Configuration parameters: Max.
RSpec/ExampleLength:
Exclude:
- 'spec/labor/badge_rewarder_spec.rb'
- 'spec/models/comment_spec.rb'
- 'spec/models/notification_spec.rb'
- 'spec/requests/api/v0/articles_spec.rb'
- 'spec/requests/display_ad_events_spec.rb'
# Offense count: 559
# Offense count: 717
# Configuration parameters: AggregateFailuresByDefault.
RSpec/MultipleExpectations:
Max: 8
@ -43,40 +40,38 @@ RSpec/SubjectStub:
Exclude:
- 'spec/models/article_spec.rb'
# Offense count: 1
# Offense count: 2
# Configuration parameters: Include.
# Include: app/helpers/**/*.rb
Rails/HelperInstanceVariable:
Exclude:
- 'app/helpers/application_helper.rb'
# Offense count: 16
# Offense count: 11
Rails/OutputSafety:
Exclude:
- 'app/helpers/application_helper.rb'
- 'app/helpers/comments_helper.rb'
- 'app/labor/markdown_parser.rb'
- 'app/liquid_tags/github_tag/github_issue_tag.rb'
- 'app/liquid_tags/liquid_tag_base.rb'
- 'app/models/comment.rb'
- 'app/models/display_ad.rb'
- 'app/models/message.rb'
- 'app/views/articles/feed.rss.builder'
# Offense count: 27
# Offense count: 26
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/UniqueValidationWithoutIndex:
Enabled: false
# Offense count: 32
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, EnforcedStyle.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
Enabled: false
# Offense count: 2
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'app/models/article.rb'
# Offense count: 3757
# Offense count: 4410
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https

View file

@ -601,9 +601,9 @@ class Article < ApplicationRecord
end
def past_or_present_date
if published_at && published_at > Time.current
errors.add(:date_time, "must be entered in DD/MM/YYYY format with current or past date")
end
return unless published_at && published_at > Time.current
errors.add(:date_time, "must be entered in DD/MM/YYYY format with current or past date")
end
def canonical_url_must_not_have_spaces
@ -639,9 +639,9 @@ class Article < ApplicationRecord
self.cached_organization = OpenStruct.new(set_cached_object(organization))
end
if user
self.cached_user = OpenStruct.new(set_cached_object(user))
end
return unless user
self.cached_user = OpenStruct.new(set_cached_object(user))
end
def set_cached_object(object)

View file

@ -6,7 +6,8 @@ Rails.logger.info "Seeding with multiplication factor: #{SEEDS_MULTIPLIER}"
##############################################################################
Rails.logger.info "#{counter += 1}. Creating Organizations"
counter += 1
Rails.logger.info "#{counter}. Creating Organizations"
3.times do
Organization.create!(
@ -27,7 +28,8 @@ end
num_users = 10 * SEEDS_MULTIPLIER
Rails.logger.info "#{counter += 1}. Creating #{num_users} Users"
counter += 1
Rails.logger.info "#{counter}. Creating #{num_users} Users"
User.clear_index!
@ -49,7 +51,7 @@ num_users.times do |i|
password: "password",
)
if i == 0
if i.zero?
user.add_role(:trusted) # guarantee at least one moderator
else
user.add_role(roles[rand(0..roles.length)]) # includes chance of having no role
@ -93,7 +95,8 @@ end
##############################################################################
Rails.logger.info "#{counter += 1}. Creating Tags"
counter += 1
Rails.logger.info "#{counter}. Creating Tags"
tags = %w[beginners career computerscience git go
java javascript linux productivity python security webdev]
@ -111,7 +114,8 @@ end
num_articles = 25 * SEEDS_MULTIPLIER
Rails.logger.info "#{counter += 1}. Creating #{num_articles} Articles"
counter += 1
Rails.logger.info "#{counter}. Creating #{num_articles} Articles"
Article.clear_index!
@ -145,7 +149,8 @@ end
num_comments = 30 * SEEDS_MULTIPLIER
Rails.logger.info "#{counter += 1}. Creating #{num_comments} Comments"
counter += 1
Rails.logger.info "#{counter}. Creating #{num_comments} Comments"
num_comments.times do
attributes = {
@ -160,7 +165,8 @@ end
##############################################################################
Rails.logger.info "#{counter += 1}. Creating Podcasts"
counter += 1
Rails.logger.info "#{counter}. Creating Podcasts"
image_file = Rails.root.join("spec/support/fixtures/images/image1.jpeg")
@ -228,7 +234,8 @@ end
##############################################################################
Rails.logger.info "#{counter += 1}. Creating Broadcasts and Welcome Thread"
counter += 1
Rails.logger.info "#{counter}. Creating Broadcasts and Welcome Thread"
# TODO: [@thepracticaldev/delightful] Remove this once we have launched welcome notifications.
Broadcast.create!(
@ -274,7 +281,8 @@ Article.create!(
##############################################################################
Rails.logger.info "#{counter += 1}. Creating Chat Channels and Messages"
counter += 1
Rails.logger.info "#{counter}. Creating Chat Channels and Messages"
%w[Workshop Meta General].each do |chan|
ChatChannel.create!(
@ -293,7 +301,8 @@ Message.create!(
##############################################################################
Rails.logger.info "#{counter += 1}. Creating HTML Variants"
counter += 1
Rails.logger.info "#{counter}. Creating HTML Variants"
HtmlVariant.create!(
name: rand(100).to_s,
@ -307,7 +316,8 @@ HtmlVariant.create!(
##############################################################################
Rails.logger.info "#{counter += 1}. Creating Badges"
counter += 1
Rails.logger.info "#{counter}. Creating Badges"
Badge.create!(
title: Faker::Lorem.word,
@ -317,7 +327,8 @@ Badge.create!(
##############################################################################
Rails.logger.info "#{counter += 1}. Creating FeedbackMessages"
counter += 1
Rails.logger.info "#{counter}. Creating FeedbackMessages"
mod = User.first
@ -356,7 +367,8 @@ end
##############################################################################
Rails.logger.info "#{counter += 1}. Creating Classified Listings"
counter += 1
Rails.logger.info "#{counter}. Creating Classified Listings"
users = User.order(Arel.sql("RANDOM()")).to_a
users.each { |user| Credit.add_to(user, rand(100)) }
@ -383,7 +395,8 @@ end
##############################################################################
Rails.logger.info "#{counter += 1}. Creating Pages"
counter += 1
Rails.logger.info "#{counter}. Creating Pages"
5.times do
Page.create!(

View file

@ -153,7 +153,7 @@ RSpec.describe "StoriesShow", type: :request do
expect(response.body).not_to include("noindex")
end
it "does not have noindex if article intermediate score and <code>" do
it "does not have noindex if article w/ intermediate score w/ 1 comment " do
article = create(:article, score: 3)
article.user.update_column(:comments_count, 1)
get article.path

View file

@ -153,7 +153,7 @@ RSpec.describe Articles::Feed, type: :service do
describe "all non-default experiments" do
it "returns articles for all experiments" do
new_story = create(:article, published_at: 10.minutes.ago, score: 10)
NON_DEFAULT_EXPERIMENTS.each do |method|
NON_DEFAULT_EXPERIMENTS.each do |_method|
stories = feed.default_home_feed_with_more_randomness_experiment
expect(stories).to include(old_story)
expect(stories).to include(new_story)

View file

@ -28,7 +28,7 @@ RSpec.describe Slack::Announcer, type: :service do
described_class.call(params)
expect(SlackClient).to have_received(:ping).
with(message, params.reject { |k| k == :message}).
with(message, params.reject { |k| k == :message }).
once
end
end