From 3494264404878cfffe7ec33cc2658d0304f08a2f Mon Sep 17 00:00:00 2001 From: Tim Lange Date: Thu, 21 Mar 2019 15:53:44 +0100 Subject: [PATCH] Enabled rubocop/lint (#2130) * WIP: Enabled rubocop/lint * FIX: Fixed failing test * FIX: Small change to return * FIX: Changed indent --- .rubocop.yml | 101 ------------------ Gemfile | 2 - app/controllers/articles_controller.rb | 6 +- app/controllers/comments_controller.rb | 6 +- app/controllers/stories_controller.rb | 6 +- app/controllers/users_controller.rb | 2 +- app/controllers/video_states_controller.rb | 3 +- app/helpers/application_helper.rb | 2 +- app/labor/podcast_feed.rb | 2 +- app/liquid_tags/null_tag.rb | 4 +- app/liquid_tags/podcast_tag.rb | 2 +- app/models/article.rb | 2 +- app/models/chat_channel.rb | 2 +- app/models/mention.rb | 2 +- app/models/message.rb | 4 +- app/models/podcast_episode.rb | 3 +- app/models/user.rb | 2 - app/services/article_api_index_service.rb | 4 +- app/services/rss_reader/assembler.rb | 2 +- app/views/api/v0/articles/show.json.jbuilder | 8 +- app/views/articles/feed.rss.builder | 2 +- app/views/chat_channels/index.json.jbuilder | 2 +- config/environments/development.rb | 4 - config/environments/production.rb | 4 - db/seeds.rb | 10 +- lib/tasks/db.rake | 2 - .../comments/user_fills_out_comment_spec.rb | 2 - .../user_updates_org_settings_spec.rb | 2 - .../user_views_and_closes_onboarding_spec.rb | 1 - spec/labor/badge_rewarder_spec.rb | 3 - spec/labor/flare_tag_spec.rb | 4 +- spec/labor/mailchimp_bot_spec.rb | 2 - spec/models/article_spec.rb | 4 +- spec/models/chat_channel_spec.rb | 2 - spec/models/mention_spec.rb | 2 - spec/models/reaction_spec.rb | 2 - spec/models/user_spec.rb | 4 +- .../requests/additional_content_boxes_spec.rb | 2 +- spec/requests/api_secrets_create_spec.rb | 2 +- spec/requests/api_secrets_destroy_spec.rb | 4 +- spec/requests/articles_api_spec.rb | 2 - spec/requests/articles_create_spec.rb | 2 - spec/requests/articles_update_spec.rb | 2 - spec/requests/blocks_spec.rb | 2 - .../requests/chat_channel_memberships_spec.rb | 2 - spec/requests/chat_channels_spec.rb | 8 +- spec/requests/stories_show_spec.rb | 2 - spec/requests/stripe_subscriptions_spec.rb | 2 - spec/requests/tags_api_spec.rb | 2 - spec/routing/all_routes_spec.rb | 2 - spec/services/membership_service_spec.rb | 2 +- .../suggester/articles/boosted_spec.rb | 2 +- .../suggester/articles/classic_spec.rb | 2 - spec/views/articles_spec.rb | 4 - 54 files changed, 49 insertions(+), 212 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index f3a14ea6f..c803cc8dc 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -247,107 +247,6 @@ Layout/InitialIndentation: Checks the indentation of the first non-blank non-comment line in a file. Enabled: false -# Lint - -Lint/AmbiguousOperator: - Description: >- - Checks for ambiguous operators in the first argument of a - method invocation without parentheses. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-as-args' - Enabled: false - -Lint/AmbiguousRegexpLiteral: - Description: >- - Checks for ambiguous regexp literals in the first argument of - a method invocation without parenthesis. - Enabled: false - -Lint/AssignmentInCondition: - Description: "Don't use assignment in conditions." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition' - Enabled: false - -Lint/CircularArgumentReference: - Description: "Don't refer to the keyword argument in the default value." - Enabled: false - -Lint/DeprecatedClassMethods: - Description: 'Check for deprecated class method calls.' - Enabled: false - -Lint/DuplicatedKey: - Description: 'Check for duplicate keys in hash literals.' - Enabled: false - -Lint/EachWithObjectArgument: - Description: 'Check for immutable argument given to each_with_object.' - Enabled: false - -Lint/ElseLayout: - Description: 'Check for odd code arrangement in an else block.' - Enabled: false - -Lint/FormatParameterMismatch: - Description: 'The number of parameters to format/sprint must match the fields.' - Enabled: false - -Lint/HandleExceptions: - Description: "Don't suppress exception." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions' - Enabled: false - -Lint/LiteralAsCondition: - Description: 'Checks of literals used in conditions.' - Enabled: false - -Lint/LiteralInInterpolation: - Description: 'Checks for literals used in interpolation.' - Enabled: false - -Lint/Loop: - Description: >- - Use Kernel#loop with break rather than begin/end/until or - begin/end/while for post-loop tests. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#loop-with-break' - Enabled: false - -Lint/NestedMethodDefinition: - Description: 'Do not use nested method definitions.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-nested-methods' - Enabled: false - -Lint/NonLocalExitFromIterator: - Description: 'Do not use return in iterator to cause non-local exit.' - Enabled: false - -Lint/ParenthesesAsGroupedExpression: - Description: >- - Checks for method calls with a space before the opening - parenthesis. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-no-spaces' - Enabled: false - -Lint/RequireParentheses: - Description: >- - Use parentheses in the method call to avoid confusion - about precedence. - Enabled: false - -Lint/UnderscorePrefixedVariableName: - Description: 'Do not use prefix `_` for a variable that is used.' - Enabled: false - -Lint/UnneededCopDisableDirective: - Description: >- - Checks for rubocop:disable comments that can be removed. - Note: this cop is not disabled when disabling all cops. - It must be explicitly disabled. - Enabled: false - -Lint/Void: - Description: 'Possible use of operator/literal/variable in void context.' - Enabled: false - # Performance Performance/CaseWhenSplat: diff --git a/Gemfile b/Gemfile index c78f17144..4fcd4cec7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,3 @@ -# rubocop:disable LineLength source "https://rubygems.org" ruby "2.6.1" @@ -157,4 +156,3 @@ group :test do gem "webmock", "~> 3.5" gem "zonebie", "~> 0.6.1" end -# rubocop:enable LineLength diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 4f56fbf22..ddc6f3e73 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -15,9 +15,9 @@ class ArticlesController < ApplicationController page(params[:page].to_i).per(12) if params[:username] - if @user = User.find_by_username(params[:username]) + if (@user = User.find_by_username(params[:username])) @articles = @articles.where(user_id: @user.id) - elsif @user = Organization.find_by_slug(params[:username]) + elsif (@user = Organization.find_by_slug(params[:username])) @articles = @articles.where(organization_id: @user.id).includes(:user) else render body: nil @@ -129,7 +129,7 @@ class ArticlesController < ApplicationController Notification.remove_all_without_delay(notifiable_id: @article.id, notifiable_type: "Article", action: "Published") path = "/#{@article.username}/#{@article.slug}?preview=#{@article.password}" end - redirect_to (params[:destination] || path) + redirect_to(params[:destination] || path) else render :edit end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 6e4fb3eb1..cc1283dbf 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -91,9 +91,9 @@ class CommentsController < ApplicationController github_username: current_user.github_username } } - elsif @comment = Comment.where(body_markdown: @comment.body_markdown, - commentable_id: @comment.commentable.id, - ancestry: @comment.ancestry)[1] + elsif (@comment = Comment.where(body_markdown: @comment.body_markdown, + commentable_id: @comment.commentable.id, + ancestry: @comment.ancestry)[1]) @comment.destroy render json: { status: "comment already exists" } return diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 20e95739e..4f504d017 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -20,9 +20,9 @@ class StoriesController < ApplicationController def show @story_show = true add_param_context(:username, :slug) - if @article = Article.find_by_path("/#{params[:username].downcase}/#{params[:slug]}")&.decorate + if (@article = Article.find_by_path("/#{params[:username].downcase}/#{params[:slug]}")&.decorate) handle_article_show - elsif @article = Article.find_by_slug(params[:slug])&.decorate + elsif (@article = Article.find_by_slug(params[:slug])&.decorate) handle_possible_redirect else @podcast = Podcast.find_by_slug(params[:username]) || not_found @@ -58,7 +58,7 @@ class StoriesController < ApplicationController if @user&.articles&.find_by_slug(params[:slug]) redirect_to "/#{@user.username}/#{params[:slug]}" return - elsif @organization = @article.organization + elsif (@organization = @article.organization) redirect_to "/#{@organization.slug}/#{params[:slug]}" return end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8c695ca87..c12d2aa1b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -90,7 +90,7 @@ class UsersController < ApplicationController def join_org authorize User - if @organization = Organization.find_by_secret(params[:org_secret]) + if (@organization = Organization.find_by_secret(params[:org_secret])) current_user.update(organization_id: @organization.id) redirect_to "/settings/organization", notice: "You have joined the #{@organization.name} organization." diff --git a/app/controllers/video_states_controller.rb b/app/controllers/video_states_controller.rb index e9885f7bd..c083198ba 100644 --- a/app/controllers/video_states_controller.rb +++ b/app/controllers/video_states_controller.rb @@ -12,7 +12,8 @@ class VideoStatesController < ApplicationController logger.info "VIDEO STATES: #{params}" request_json = JSON.parse(request.raw_post, symbolize_names: true) logger.info "VIDEO STATES: #{request_json}" - rescue StandardError + rescue StandardError => e + Rails.logger.warn(e) end request_json = JSON.parse(request.raw_post, symbolize_names: true) message_json = JSON.parse(request_json[:Message], symbolize_names: true) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index dcdcaa138..44b9ac979 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -139,7 +139,7 @@ module ApplicationHelper def tag_colors(tag) Rails.cache.fetch("view-helper-#{tag}/tag_colors", expires_in: 5.hours) do - if found_tag = Tag.select(%i[bg_color_hex text_color_hex]).find_by_name(tag) + if (found_tag = Tag.select(%i[bg_color_hex text_color_hex]).find_by_name(tag)) { background: found_tag.bg_color_hex, color: found_tag.text_color_hex } else { background: "#d6d9e0", color: "#606570" } diff --git a/app/labor/podcast_feed.rb b/app/labor/podcast_feed.rb index 5b1a352f5..19bf5dfef 100644 --- a/app/labor/podcast_feed.rb +++ b/app/labor/podcast_feed.rb @@ -14,7 +14,7 @@ class PodcastFeed feed.items.first(num).each do |item| if !existing_episode(item, podcast) create_new_episode(item, podcast) - elsif ep = existing_episode(item, podcast).first + elsif (ep = existing_episode(item, podcast).first) update_existing_episode(ep, item, podcast) end end diff --git a/app/liquid_tags/null_tag.rb b/app/liquid_tags/null_tag.rb index 14a3dbd93..bb7993f6c 100644 --- a/app/liquid_tags/null_tag.rb +++ b/app/liquid_tags/null_tag.rb @@ -1,6 +1,6 @@ class NullTag < Liquid::Block - def initialize(_tag_name, _markup, _options) - raise StandardError, "Liquid##{_tag_name} tag is disabled" + def initialize(tag_name, _markup, _options) + raise StandardError, "Liquid##{tag_name} tag is disabled" end end diff --git a/app/liquid_tags/podcast_tag.rb b/app/liquid_tags/podcast_tag.rb index d2ea8c909..aefd579de 100644 --- a/app/liquid_tags/podcast_tag.rb +++ b/app/liquid_tags/podcast_tag.rb @@ -13,7 +13,7 @@ class PodcastTag < LiquidTagBase def initialize(_tag_name, link, _tokens) @episode = fetch_podcast(link) - @podcast + @podcast ||= Podcast.new end def render(_context) diff --git a/app/models/article.rb b/app/models/article.rb index b9bcee439..1a32665ad 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -410,8 +410,8 @@ class Article < ApplicationRecord HTTParty.get(url).body.split("#EXTINF:").each do |chunk| duration += chunk.split(",")[0].to_f end - duration self.video_duration_in_seconds = duration + duration end rescue StandardError => e puts e.message diff --git a/app/models/chat_channel.rb b/app/models/chat_channel.rb index ba6018533..26d0fe70d 100644 --- a/app/models/chat_channel.rb +++ b/app/models/chat_channel.rb @@ -71,7 +71,7 @@ class ChatChannel < ApplicationRecord slug = contrived_name.to_s.downcase.tr(" ", "-").gsub(/[^\w-]/, "").tr("_", "") + "-" + rand(100_000).to_s(26) end - if channel = ChatChannel.find_by_slug(slug) + if (channel = ChatChannel.find_by_slug(slug)) channel.status = "active" channel.save else diff --git a/app/models/mention.rb b/app/models/mention.rb index bc590995b..222d3f7c6 100644 --- a/app/models/mention.rb +++ b/app/models/mention.rb @@ -20,7 +20,7 @@ class Mention < ApplicationRecord mentions = [] doc.css(".comment-mentioned-user").each do |link| username = link.text.gsub("@", "").downcase - if user = User.find_by_username(username) + if (user = User.find_by_username(username)) usernames << username mentions << create_mention(user) end diff --git a/app/models/message.rb b/app/models/message.rb index eec7c2f7f..012ca75c4 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -26,7 +26,7 @@ class Message < ApplicationRecord where.not(user_id: user.id).pluck(:user_id) PushNotificationSubscription.where(user_id: receiver_ids).find_each do |sub| - return if no_push_necessary?(sub) + break if no_push_necessary?(sub) Webpush.payload_send( endpoint: sub.endpoint, @@ -76,7 +76,7 @@ class Message < ApplicationRecord doc = Nokogiri::HTML(html) rich_style = "border: 1px solid #0a0a0a; border-radius: 3px; padding: 8px;" doc.css("a").each do |a| - if article = rich_link_article(a) + if (article = rich_link_article(a)) html += "

diff --git a/app/models/podcast_episode.rb b/app/models/podcast_episode.rb index 21828016a..0194fdb05 100644 --- a/app/models/podcast_episode.rb +++ b/app/models/podcast_episode.rb @@ -128,7 +128,8 @@ class PodcastEpisode < ApplicationRecord cache_buster.bust("/" + podcast_slug) cache_buster.bust("/pod") cache_buster.bust(path) - rescue StandardError + rescue StandardError => e + Rails.logger.warn(e) end purge purge_all diff --git a/app/models/user.rb b/app/models/user.rb index dc2f3caa9..d11186709 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -70,7 +70,6 @@ class User < ApplicationRecord validates :bg_color_hex, format: /\A#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\z/, allow_blank: true validates :website_url, :employer_url, :mastodon_url, url: { allow_blank: true, no_local: true, schemes: %w[https http] } - # rubocop:disable Metrics/LineLength validates :facebook_url, format: /\A(http(s)?:\/\/)?(www.facebook.com|facebook.com)\/.*\Z/, allow_blank: true @@ -94,7 +93,6 @@ class User < ApplicationRecord validates :gitlab_url, allow_blank: true, format: /\A(http(s)?:\/\/)?(www.gitlab.com|gitlab.com)\/.*\Z/ - # rubocop:enable Metrics/LineLength validates :shirt_gender, inclusion: { in: %w[unisex womens], message: "%{value} is not a valid shirt style" }, diff --git a/app/services/article_api_index_service.rb b/app/services/article_api_index_service.rb index e7b56244a..0126d3f06 100644 --- a/app/services/article_api_index_service.rb +++ b/app/services/article_api_index_service.rb @@ -30,14 +30,14 @@ class ArticleApiIndexService else 30 end - if user = User.find_by_username(username) + if (user = User.find_by_username(username)) user.articles. where(published: true). includes(:user). order("published_at DESC"). page(page). per(num) - elsif organization = Organization.find_by_slug(username) + elsif (organization = Organization.find_by_slug(username)) organization.articles. where(published: true). includes(:user). diff --git a/app/services/rss_reader/assembler.rb b/app/services/rss_reader/assembler.rb index d8027ed8b..84c89ec23 100644 --- a/app/services/rss_reader/assembler.rb +++ b/app/services/rss_reader/assembler.rb @@ -67,7 +67,7 @@ class RssReader possible_link = a_tag[0].inner_html if /medium\.com\/media\/.+\/href/.match?(possible_link) real_link = HTTParty.head(possible_link).request.last_uri.to_s - return unless real_link.include?("gist.github.com") + return nil unless real_link.include?("gist.github.com") iframe.name = "p" iframe.keys.each { |attr| iframe.remove_attribute(attr) } diff --git a/app/views/api/v0/articles/show.json.jbuilder b/app/views/api/v0/articles/show.json.jbuilder index 4e5757041..f5d5710ad 100644 --- a/app/views/api/v0/articles/show.json.jbuilder +++ b/app/views/api/v0/articles/show.json.jbuilder @@ -14,11 +14,9 @@ json.canonical_url @article.processed_canonical_url json.comments_count @article.comments_count json.positive_reactions_count @article.positive_reactions_count -json.body_html @article.processed_html -json.ltag_style (@article.liquid_tags_used.map do |ltag| - Rails.application.assets["ltags/#{ltag}.css"].to_s.html_safe - end) -json.ltag_script (@article.liquid_tags_used.map { |ltag| ltag.script.html_safe }) +json.body_html @article.processed_html +json.ltag_style(@article.liquid_tags_used.map { |ltag| Rails.application.assets["ltags/#{ltag}.css"].to_s.html_safe }) +json.ltag_script(@article.liquid_tags_used.map { |ltag| ltag.script.html_safe }) json.user do json.name @article.user.name diff --git a/app/views/articles/feed.rss.builder b/app/views/articles/feed.rss.builder index 04d388067..bd61d00aa 100644 --- a/app/views/articles/feed.rss.builder +++ b/app/views/articles/feed.rss.builder @@ -12,7 +12,7 @@ xml.rss version: "2.0" do @articles.each do |article| xml.item do xml.title article.title - xml.author @user && @user.class.name == "User" ? @user.name : article.user.name + xml.author(@user && @user.class.name == "User" ? @user.name : article.user.name) xml.pubDate article.published_at.to_s(:rfc822) if article.published_at xml.link "https://dev.to#{article.path}" xml.guid "https://dev.to#{article.path}" diff --git a/app/views/chat_channels/index.json.jbuilder b/app/views/chat_channels/index.json.jbuilder index 93e6dbdf2..5a9bed1af 100644 --- a/app/views/chat_channels/index.json.jbuilder +++ b/app/views/chat_channels/index.json.jbuilder @@ -1,4 +1,4 @@ -json.array! (@chat_channels_memberships.sort_by { |m| m.chat_channel.last_message_at }.reverse!) do |membership| +json.array!(@chat_channels_memberships.sort_by { |m| m.chat_channel.last_message_at }.reverse!) do |membership| json.id membership.chat_channel.id membership.chat_channel.current_user = current_user json.slug membership.chat_channel.slug diff --git a/config/environments/development.rb b/config/environments/development.rb index ad3b97cbd..484f5b7b9 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,5 +1,3 @@ -# rubocop:disable Metrics/BlockLength -# def yarn_integrity_enabled? ENV.fetch("YARN_INTEGRITY_ENABLED", "true") == "true" end @@ -100,5 +98,3 @@ Rails.application.configure do Bullet.console = true end end - -# rubocop:enable Metrics/BlockLength diff --git a/config/environments/production.rb b/config/environments/production.rb index 9926e830a..a00d66969 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,5 +1,3 @@ -# rubocop:disable Metrics/BlockLength - Rails.application.configure do # Verifies that versions and hashed value of the package contents in the project's package.json config.webpacker.check_yarn_integrity = false @@ -127,5 +125,3 @@ Rails.application.configure do config.middleware.use Rack::HostRedirect, "practicaldev.herokuapp.com" => "dev.to" end - -# rubocop:enable Metrics/BlockLength diff --git a/db/seeds.rb b/db/seeds.rb index 59be3a957..e70841d80 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -127,7 +127,7 @@ podcast_objects = [ twitter_username: "CodingBlocks", website_url: "http://codingblocks.net", main_color_hex: "111111", - overcast_url: "https://overcast.fm/itunes769189585/coding-blocks-software-and-web-programming-security-best-practices-microsoft-net", # rubocop:disable Metrics/LineLength + overcast_url: "https://overcast.fm/itunes769189585/coding-blocks-software-and-web-programming-security-best-practices-microsoft-net", android_url: "http://subscribeonandroid.com/feeds.podtrac.com/c8yBGHRafqhz", image: Rack::Test::UploadedFile.new(image_file, "image/jpeg") }, @@ -139,7 +139,7 @@ podcast_objects = [ twitter_username: "TalkPython", website_url: "https://talkpython.fm", main_color_hex: "181a1c", - overcast_url: "https://overcast.fm/itunes979020229/talk-python-to-me-python-conversations-for-passionate-developers", # rubocop:disable Metrics/LineLength + overcast_url: "https://overcast.fm/itunes979020229/talk-python-to-me-python-conversations-for-passionate-developers", android_url: "https://subscribeonandroid.com/talkpython.fm/episodes/rss", image: Rack::Test::UploadedFile.new(image_file, "image/jpeg") }, @@ -147,7 +147,7 @@ podcast_objects = [ title: "Developer on Fire", description: "", feed_url: "http://developeronfire.com/rss.xml", - itunes_url: "https://itunes.apple.com/us/podcast/developer-on-fire/id1006105326", # rubocop:disable Metrics/LineLength + itunes_url: "https://itunes.apple.com/us/podcast/developer-on-fire/id1006105326", slug: "developeronfire", twitter_username: "raelyard", website_url: "http://developeronfire.com", @@ -160,7 +160,7 @@ podcast_objects = [ title: "Building Programmers", description: "", feed_url: "https://building.fireside.fm/rss", - itunes_url: "https://itunes.apple.com/us/podcast/building-programmers/id1149043456", # rubocop:disable Metrics/LineLength + itunes_url: "https://itunes.apple.com/us/podcast/building-programmers/id1149043456", slug: "buildingprogrammers", twitter_username: "run_kmc", website_url: "https://building.fireside.fm", @@ -181,7 +181,7 @@ p "7/9 Creating Broadcasts" Broadcast.create!( title: "Welcome Notification", - processed_html: "Welcome to dev.to! Start by introducing yourself in the welcome thread.", # rubocop:disable Metrics/LineLength + processed_html: "Welcome to dev.to! Start by introducing yourself in the welcome thread.", type_of: "Onboarding", sent: true, ) diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 4260d8b35..8ce314585 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -1,4 +1,3 @@ -# rubocop:disable Metrics/LineLength # namespace :db do # # desc "Copy production database to local" @@ -29,4 +28,3 @@ # pg_restore --verbose --no-acl --no-owner -t articles -t users -t podcasts -t podcast_episodes -t sponsors -t identities -t organizations -h localhost -d PracticalDeveloper_development latest.dump # rake db:migrate # pg_restore --verbose --clean --no-acl --no-owner -t articles -t users -t podcasts -t podcast_episodes -t sponsors -t identities -t organizations -h localhost -d PracticalDeveloper_development latest.dump -# rubocop:enable Metrics/LineLength diff --git a/spec/features/comments/user_fills_out_comment_spec.rb b/spec/features/comments/user_fills_out_comment_spec.rb index 8b7526acf..40641f626 100644 --- a/spec/features/comments/user_fills_out_comment_spec.rb +++ b/spec/features/comments/user_fills_out_comment_spec.rb @@ -18,7 +18,6 @@ RSpec.describe "Creating Comment", type: :feature, js: true do expect(page).to have_text(raw_comment) end - # rubocop:disable RSpec/ExampleLength it "User fill out commen box then click previews and submit" do visit user.path visit article.path.to_s @@ -43,5 +42,4 @@ RSpec.describe "Creating Comment", type: :feature, js: true do find(:xpath, "//div[contains(@class, 'reply-actions')]/input[@name='commit']").click expect(page).to have_text(raw_comment) end - # rubocop:enable RSpec/ExampleLength end diff --git a/spec/features/organization/user_updates_org_settings_spec.rb b/spec/features/organization/user_updates_org_settings_spec.rb index cb198d7fb..99fb0279c 100644 --- a/spec/features/organization/user_updates_org_settings_spec.rb +++ b/spec/features/organization/user_updates_org_settings_spec.rb @@ -8,7 +8,6 @@ RSpec.describe "Organization setting page(/settings/organization)", type: :featu sign_in user end - # rubocop:disable RSpec/ExampleLength it "user creates an organization" do visit "settings/organization" fill_in "organization[name]", with: "Organization Name" @@ -33,5 +32,4 @@ RSpec.describe "Organization setting page(/settings/organization)", type: :featu page.driver.browser.switch_to.alert.accept expect(page).not_to have_text(user2.name) end - # rubocop:enable RSpec/ExampleLength end diff --git a/spec/features/user_views_and_closes_onboarding_spec.rb b/spec/features/user_views_and_closes_onboarding_spec.rb index 79208c02e..5b1f59649 100644 --- a/spec/features/user_views_and_closes_onboarding_spec.rb +++ b/spec/features/user_views_and_closes_onboarding_spec.rb @@ -1,4 +1,3 @@ -# rubocop:disable Metrics/LineLength # require "rails_helper" # describe "User views and closes onboarding", type: :feature, js: true do diff --git a/spec/labor/badge_rewarder_spec.rb b/spec/labor/badge_rewarder_spec.rb index 6d249059b..14bfc6f57 100644 --- a/spec/labor/badge_rewarder_spec.rb +++ b/spec/labor/badge_rewarder_spec.rb @@ -1,4 +1,3 @@ -# rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations require "rails_helper" RSpec.describe BadgeRewarder do @@ -120,5 +119,3 @@ RSpec.describe BadgeRewarder do end end end - -# rubocop:enable RSpec/ExampleLength, RSpec/MultipleExpectations diff --git a/spec/labor/flare_tag_spec.rb b/spec/labor/flare_tag_spec.rb index d6f354293..7472f0b4c 100644 --- a/spec/labor/flare_tag_spec.rb +++ b/spec/labor/flare_tag_spec.rb @@ -26,8 +26,8 @@ RSpec.describe FlareTag do end describe "#flare_tag_hash" do - let (:tag) { create(:tag, name: "ama", bg_color_hex: "#f3f3f3", text_color_hex: "#cccccc") } - let (:valid_article) { create(:article, tags: tag.name) } + let(:tag) { create(:tag, name: "ama", bg_color_hex: "#f3f3f3", text_color_hex: "#cccccc") } + let(:valid_article) { create(:article, tags: tag.name) } it "returns nil if an article doesn't have a flare tag" do expect(described_class.new(article).tag_hash).to be nil diff --git a/spec/labor/mailchimp_bot_spec.rb b/spec/labor/mailchimp_bot_spec.rb index ea8e3a479..f0ca1f415 100644 --- a/spec/labor/mailchimp_bot_spec.rb +++ b/spec/labor/mailchimp_bot_spec.rb @@ -87,7 +87,6 @@ RSpec.describe MailchimpBot do expect(described_class.new(user).upsert_to_membership_newsletter).to be(false) end - # rubocop:disable RSpec/ExampleLength context "when user is a sustaining member" do it "send proper information" do user.update(monthly_dues: 2500, email_membership_newsletter: true) @@ -110,7 +109,6 @@ RSpec.describe MailchimpBot do with(hash_including(body: hash_including(status: "unsubscribed"))) end end - # rubocop:enable RSpec/ExampleLength end describe "#unsubscribe_all_newsletters" do diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index 79fa9327b..09e4ce329 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -1,4 +1,3 @@ -# rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations require "rails_helper" RSpec.describe Article, type: :model do @@ -117,7 +116,7 @@ RSpec.describe Article, type: :model do context "when unpublished" do it "creates proper slug with this-is-the-slug format" do - expect(article0.slug).to match /(.*-){4,}/ + expect(article0.slug).to match(/(.*-){4,}/) end it "modifies slug on create if proposed slug already exists on the user" do @@ -464,4 +463,3 @@ RSpec.describe Article, type: :model do include_examples "#sync_reactions_count", :article end -# rubocop:enable RSpec/ExampleLength, RSpec/MultipleExpectations diff --git a/spec/models/chat_channel_spec.rb b/spec/models/chat_channel_spec.rb index 5044eb885..3b17fb1c5 100644 --- a/spec/models/chat_channel_spec.rb +++ b/spec/models/chat_channel_spec.rb @@ -1,4 +1,3 @@ -# rubocop:disable RSpec/MultipleExpectations require "rails_helper" RSpec.describe ChatChannel, type: :model do @@ -33,4 +32,3 @@ RSpec.describe ChatChannel, type: :model do expect(chat_channel.channel_users.size).to eq(1) end end -# rubocop:enable RSpec/MultipleExpectations diff --git a/spec/models/mention_spec.rb b/spec/models/mention_spec.rb index c8b0a53cc..c2f817fd7 100644 --- a/spec/models/mention_spec.rb +++ b/spec/models/mention_spec.rb @@ -1,4 +1,3 @@ -# rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations require "rails_helper" RSpec.describe Mention, type: :model do @@ -72,4 +71,3 @@ RSpec.describe Mention, type: :model do expect(Mention.all.size).to eq(0) end end -# rubocop:enable RSpec/ExampleLength, RSpec/MultipleExpectations diff --git a/spec/models/reaction_spec.rb b/spec/models/reaction_spec.rb index 0b2411cc9..428e90cff 100644 --- a/spec/models/reaction_spec.rb +++ b/spec/models/reaction_spec.rb @@ -1,4 +1,3 @@ -# rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations require "rails_helper" RSpec.describe Reaction, type: :model do @@ -85,4 +84,3 @@ RSpec.describe Reaction, type: :model do end end end -# rubocop:enable RSpec/ExampleLength, RSpec/MultipleExpectations diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index a562327d2..e65612a8a 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,4 +1,3 @@ -# rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations require "rails_helper" RSpec.describe User, type: :model do @@ -8,7 +7,7 @@ RSpec.describe User, type: :model do let(:article) { create(:article, user_id: user.id) } let(:tag) { create(:tag) } let(:org) { create(:organization) } - let (:second_org) { create(:organization) } + let(:second_org) { create(:organization) } before { mock_auth_hash } @@ -586,4 +585,3 @@ RSpec.describe User, type: :model do end end end -# rubocop:enable RSpec/ExampleLength, RSpec/MultipleExpectations diff --git a/spec/requests/additional_content_boxes_spec.rb b/spec/requests/additional_content_boxes_spec.rb index 1998d2742..870800480 100644 --- a/spec/requests/additional_content_boxes_spec.rb +++ b/spec/requests/additional_content_boxes_spec.rb @@ -22,7 +22,7 @@ RSpec.describe "AdditionalContentBoxes", type: :request do it "returns boosted article if available" do organization = create(:organization) create(:article, published: true, featured: true) - boosted_sugg = create(:article, tags: [tag.name], featured: true, boosted_additional_articles: true, organization_id: organization.id) # rubocop:disable Metrics/LineLength + boosted_sugg = create(:article, tags: [tag.name], featured: true, boosted_additional_articles: true, organization_id: organization.id) get "/additional_content_boxes?article_id=#{regular_article.id}&state=include_sponsors" expect(response.body).to include CGI.escapeHTML(boosted_sugg.title) end diff --git a/spec/requests/api_secrets_create_spec.rb b/spec/requests/api_secrets_create_spec.rb index cd0446006..005d1b294 100644 --- a/spec/requests/api_secrets_create_spec.rb +++ b/spec/requests/api_secrets_create_spec.rb @@ -31,7 +31,7 @@ RSpec.describe "ApiSecretsCreate", type: :request do it "does not create the ApiSecret" do expect { post "/users/api_secrets", params: { api_secret: invalid_params } }. - not_to (change { user.api_secrets.count }) + not_to(change { user.api_secrets.count }) end it "flashes an error message" do diff --git a/spec/requests/api_secrets_destroy_spec.rb b/spec/requests/api_secrets_destroy_spec.rb index 3c4203898..4d3db9035 100644 --- a/spec/requests/api_secrets_destroy_spec.rb +++ b/spec/requests/api_secrets_destroy_spec.rb @@ -10,7 +10,7 @@ RSpec.describe "ApiSecretsDestroy", type: :request do context "when delete succeeds" do it "deletes the ApiSecret for the user" do expect { delete "/users/api_secrets", params: { id: api_secret.id } }. - to change { user.api_secrets.count }.by -1 + to change { user.api_secrets.count }.by(-1) end it "flashes a notice" do @@ -28,7 +28,7 @@ RSpec.describe "ApiSecretsDestroy", type: :request do it "does not delete the ApiSecret" do expect { delete "/users/api_secrets", params: { id: api_secret.id } }. - not_to (change { user.api_secrets.count }) + not_to(change { user.api_secrets.count }) end it "flashes an error message" do diff --git a/spec/requests/articles_api_spec.rb b/spec/requests/articles_api_spec.rb index 833af64d2..fbc9a9e4f 100644 --- a/spec/requests/articles_api_spec.rb +++ b/spec/requests/articles_api_spec.rb @@ -26,7 +26,6 @@ RSpec.describe "ArticlesApi", type: :request do expect(JSON.parse(response.body).size).to eq(2) end - # rubocop:disable RSpec/ExampleLength it "returns organization articles if username param is present" do org = create(:organization) create(:article, user_id: user1.id) @@ -37,7 +36,6 @@ RSpec.describe "ArticlesApi", type: :request do get "/api/articles?username=#{org.slug}" expect(JSON.parse(response.body).size).to eq(2) end - # rubocop:enable RSpec/ExampleLength it "returns tag articles if tag param is present" do article = create(:article) diff --git a/spec/requests/articles_create_spec.rb b/spec/requests/articles_create_spec.rb index d5728210a..ada04d5d4 100644 --- a/spec/requests/articles_create_spec.rb +++ b/spec/requests/articles_create_spec.rb @@ -15,7 +15,6 @@ RSpec.describe "ArticlesCreate", type: :request do expect(Article.last.user_id).to eq(user.id) end - # rubocop:disable RSpec/ExampleLength it "creates article with front matter params" do post "/articles", params: { article: { @@ -61,5 +60,4 @@ RSpec.describe "ArticlesCreate", type: :request do } expect(Collection.last.slug).to eq("helloyo") end - # rubocop:enable RSpec/ExampleLength end diff --git a/spec/requests/articles_update_spec.rb b/spec/requests/articles_update_spec.rb index 2e8f1dafd..f683087fb 100644 --- a/spec/requests/articles_update_spec.rb +++ b/spec/requests/articles_update_spec.rb @@ -16,7 +16,6 @@ RSpec.describe "ArticlesUpdate", type: :request do expect(Article.last.title).to eq(new_title) end - # rubocop:disable RSpec/ExampleLength it "does not create a job opportunity if no hiring tag" do new_title = "NEW TITLE #{rand(100)}" put "/articles/#{article.id}", params: { @@ -38,5 +37,4 @@ RSpec.describe "ArticlesUpdate", type: :request do } expect(Article.last.job_opportunity.remoteness).to eq("on_premise") end - # rubocop:enable RSpec/ExampleLength end diff --git a/spec/requests/blocks_spec.rb b/spec/requests/blocks_spec.rb index 023a01c1f..109f05b8e 100644 --- a/spec/requests/blocks_spec.rb +++ b/spec/requests/blocks_spec.rb @@ -13,7 +13,6 @@ RSpec.describe "Blocks", type: :request do end end - # rubocop:disable RSpec/ExampleLength describe "POST blocks" do it "creates block from input data" do post "/blocks", params: { @@ -38,7 +37,6 @@ RSpec.describe "Blocks", type: :request do expect(Block.last.processed_css).to include("color: red") end end - # rubocop:enable RSpec/ExampleLength describe "DELETE blocks" do it "updates block from input data" do diff --git a/spec/requests/chat_channel_memberships_spec.rb b/spec/requests/chat_channel_memberships_spec.rb index a2efc9b6e..d4fe8fe49 100644 --- a/spec/requests/chat_channel_memberships_spec.rb +++ b/spec/requests/chat_channel_memberships_spec.rb @@ -1,4 +1,3 @@ -# rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations require "rails_helper" RSpec.describe "ChatChannelMemberships", type: :request do @@ -90,4 +89,3 @@ RSpec.describe "ChatChannelMemberships", type: :request do end end end -# rubocop:enable RSpec/ExampleLength, RSpec/MultipleExpectations diff --git a/spec/requests/chat_channels_spec.rb b/spec/requests/chat_channels_spec.rb index 8730ed42e..f4b83aebf 100644 --- a/spec/requests/chat_channels_spec.rb +++ b/spec/requests/chat_channels_spec.rb @@ -50,7 +50,7 @@ RSpec.describe "ChatChannels", type: :request do describe "get /chat_channels?state=pending" do it "returns pending channels" do - ChatChannelMembership.create(chat_channel_id: invite_channel.id, user_id: user.id, status: "pending") # rubocop:disable Metrics/LineLength + ChatChannelMembership.create(chat_channel_id: invite_channel.id, user_id: user.id, status: "pending") sign_in user get "/chat_channels?state=pending" expect(response.body).to include(invite_channel.slug) @@ -63,7 +63,7 @@ RSpec.describe "ChatChannels", type: :request do end it "returns no pending channels if not pending" do - ChatChannelMembership.create(chat_channel_id: invite_channel.id, user_id: user.id, status: "rejected") # rubocop:disable Metrics/LineLength + ChatChannelMembership.create(chat_channel_id: invite_channel.id, user_id: user.id, status: "rejected") sign_in user get "/chat_channels?state=pending" expect(response.body).not_to include(invite_channel.slug) @@ -93,7 +93,6 @@ RSpec.describe "ChatChannels", type: :request do end describe "POST /chat_channels" do - # rubocop:disable RSpec/MultipleExpectations it "creates chat_channel for current user" do post "/chat_channels", params: { chat_channel: { channel_name: "Hello Channel", slug: "hello-channel" } }, @@ -101,7 +100,6 @@ RSpec.describe "ChatChannels", type: :request do expect(ChatChannel.last.slug).to eq("hello-channel") expect(ChatChannel.last.active_users).to include(user) end - # rubocop:enable RSpec/MultipleExpectations it "returns errors if channel is invalid" do # slug should be taken @@ -146,7 +144,6 @@ RSpec.describe "ChatChannels", type: :request do end.to raise_error(Pundit::NotAuthorizedError) end - # rubocop:disable RSpec/ExampleLength it "raises NotAuthorizedError if user is logged in but not authorized" do sign_in user expect do @@ -155,7 +152,6 @@ RSpec.describe "ChatChannels", type: :request do headers: { HTTP_ACCEPT: "application/json" } end.to raise_error(Pundit::NotAuthorizedError) end - # rubocop:enable RSpec/ExampleLength context "when user is logged-in and authorized" do before do diff --git a/spec/requests/stories_show_spec.rb b/spec/requests/stories_show_spec.rb index e9c056c66..1fd3c90a9 100644 --- a/spec/requests/stories_show_spec.rb +++ b/spec/requests/stories_show_spec.rb @@ -79,7 +79,6 @@ RSpec.describe "StoriesShow", type: :request do expect(response.body).not_to include html_variant.html end - # rubocop:disable RSpec/ExampleLength it "renders articles of long length without breaking" do # This is a pretty weak test, just to exercise different lengths with no breakage article.update(title: (0...75).map { rand(65..90).chr }.join) @@ -90,7 +89,6 @@ RSpec.describe "StoriesShow", type: :request do get article.path expect(response.body).to include "title" end - # rubocop:enable RSpec/ExampleLength end context "when story is a user" do diff --git a/spec/requests/stripe_subscriptions_spec.rb b/spec/requests/stripe_subscriptions_spec.rb index 2f953c87d..fd902ff04 100644 --- a/spec/requests/stripe_subscriptions_spec.rb +++ b/spec/requests/stripe_subscriptions_spec.rb @@ -1,4 +1,3 @@ -# rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations require "rails_helper" RSpec.describe "StripeSubscriptions", type: :request do @@ -170,4 +169,3 @@ RSpec.describe "StripeSubscriptions", type: :request do end end end -# rubocop:enable RSpec/ExampleLength, RSpec/MultipleExpectations diff --git a/spec/requests/tags_api_spec.rb b/spec/requests/tags_api_spec.rb index 39eb3d856..2ac791817 100644 --- a/spec/requests/tags_api_spec.rb +++ b/spec/requests/tags_api_spec.rb @@ -1,4 +1,3 @@ -# rubocop:disable RSpec/MultipleExpectations require "rails_helper" RSpec.describe "ArticlesApi", type: :request do @@ -22,4 +21,3 @@ RSpec.describe "ArticlesApi", type: :request do end end end -# rubocop:enable RSpec/MultipleExpectations diff --git a/spec/routing/all_routes_spec.rb b/spec/routing/all_routes_spec.rb index 362dbb054..bf6334eef 100644 --- a/spec/routing/all_routes_spec.rb +++ b/spec/routing/all_routes_spec.rb @@ -20,7 +20,6 @@ RSpec.describe "all routes", type: :routing do ) end - # rubocop:disable RSpec/ExampleLength it "renders a user's story successfully" do expect(get: "/ben/this-is-a-slug").to route_to( controller: "stories", @@ -29,7 +28,6 @@ RSpec.describe "all routes", type: :routing do username: "ben", ) end - # rubocop:enable RSpec/ExampleLength context "when redirected routes" do include RSpec::Rails::RequestExampleGroup diff --git a/spec/services/membership_service_spec.rb b/spec/services/membership_service_spec.rb index 073cfba14..485a37dcb 100644 --- a/spec/services/membership_service_spec.rb +++ b/spec/services/membership_service_spec.rb @@ -40,7 +40,7 @@ RSpec.describe MembershipService do ) user_one.update(stripe_id_code: customer.id) plan = Stripe::Plan.create( - id: "membership-#{1200}", + id: "membership-1200", currency: "usd", interval: "month", name: "Monthly DEV Membership", diff --git a/spec/services/suggester/articles/boosted_spec.rb b/spec/services/suggester/articles/boosted_spec.rb index 58501c5f9..204def76a 100644 --- a/spec/services/suggester/articles/boosted_spec.rb +++ b/spec/services/suggester/articles/boosted_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Suggester::Articles::Boosted do it "returns an article" do user.follow(tag) - article2 = create(:article, tags: [tag.name], featured: true, boosted_additional_articles: true, organization_id: organization.id) # rubocop:disable Metrics/LineLength + article2 = create(:article, tags: [tag.name], featured: true, boosted_additional_articles: true, organization_id: organization.id) suggested_id = described_class.new(tag.name, area: "additional_articles").suggest.id expect(suggested_id).to eq article2.id end diff --git a/spec/services/suggester/articles/classic_spec.rb b/spec/services/suggester/articles/classic_spec.rb index a34aaf190..3d9fd467e 100644 --- a/spec/services/suggester/articles/classic_spec.rb +++ b/spec/services/suggester/articles/classic_spec.rb @@ -18,7 +18,6 @@ RSpec.describe Suggester::Articles::Classic do expect(described_class.new(article).get).to eq [] end - # rubocop:disable RSpec/ExampleLength it "returns single article if multiple qualify" do user.follow(tag) create(:reaction, user_id: user.id, reactable_id: article.id) @@ -31,5 +30,4 @@ RSpec.describe Suggester::Articles::Classic do create(:reaction, user_id: user2.id, reactable_id: article2.id, category: "unicorn") expect(described_class.new(article).get.first&.id).to eq article.id end - # rubocop:enable RSpec/ExampleLength end diff --git a/spec/views/articles_spec.rb b/spec/views/articles_spec.rb index 991c42d78..baf819efc 100644 --- a/spec/views/articles_spec.rb +++ b/spec/views/articles_spec.rb @@ -1,4 +1,3 @@ -# rubocop:disable RSpec/MultipleExpectations require "rails_helper" describe "articles/show", type: :view do @@ -49,7 +48,6 @@ describe "articles/show", type: :view do expect(rendered).to have_css("input#submit-button") end - # rubocop:disable RSpec/ExampleLength it "shows user comments of the article" do without_partial_double_verification do allow(view).to receive(:comment_class) { |a, b| helper.comment_class(a, b) } @@ -61,7 +59,6 @@ describe "articles/show", type: :view do expect(rendered).to have_text(comment1.body_html) expect(rendered).to have_text(comment2.body_html) end - # rubocop:enable RSpec/ExampleLength end # note fully implemented yet @@ -75,4 +72,3 @@ end # end # # end -# rubocop:enable RSpec/MultipleExpectations