From 66ddcbca02cb298dbb41099cdfe4624d720537ab Mon Sep 17 00:00:00 2001 From: rhymes Date: Tue, 14 May 2019 01:21:24 +0200 Subject: [PATCH] Upgrade rubocop and rubocop-performance (#2802) [ci skip] --- .rubocop_todo.yml | 42 +++++++------------ Gemfile | 2 +- Gemfile.lock | 4 +- app/controllers/articles_controller.rb | 17 ++++---- .../reading_list_items_controller.rb | 2 +- app/labor/markdown_parser.rb | 1 + app/models/reaction.rb | 1 + .../article_with_video_creation_service.rb | 1 - docs/Gemfile | 2 +- spec/requests/reading_list_items_spec.rb | 2 +- 10 files changed, 33 insertions(+), 41 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f34fdfe619a0c..4f3f6442e23fb 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2019-04-10 05:04:16 +0200 using RuboCop version 0.67.2. +# on 2019-05-14 00:36:38 +0200 using RuboCop version 0.69.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 @@ -10,9 +10,9 @@ # Configuration parameters: CountComments, ExcludedMethods. # ExcludedMethods: refine Metrics/BlockLength: - Max: 69 + Max: 63 -# Offense count: 21 +# Offense count: 20 Metrics/PerceivedComplexity: Max: 13 @@ -21,52 +21,42 @@ RSpec/AnyInstance: Exclude: - 'spec/requests/stripe_cancellations_spec.rb' -# Offense count: 145 +# Offense count: 185 # Configuration parameters: AggregateFailuresByDefault. RSpec/MultipleExpectations: Max: 6 -# Offense count: 16 +# Offense count: 15 Rails/OutputSafety: Exclude: - 'app/controllers/stripe_subscriptions_controller.rb' - 'app/helpers/application_helper.rb' - 'app/helpers/comments_helper.rb' - 'app/labor/markdown_parser.rb' - - 'app/liquid_tags/dev_comment_tag.rb' - 'app/liquid_tags/github_tag/github_issue_tag.rb' - 'app/liquid_tags/liquid_tag_base.rb' - - 'app/liquid_tags/tweet_tag.rb' - 'app/models/comment.rb' - 'app/models/display_ad.rb' - 'app/models/message.rb' - 'app/views/api/v0/articles/show.json.jbuilder' - 'app/views/articles/feed.rss.builder' -# Offense count: 15 +# Offense count: 17 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, EnforcedStyle. # SupportedStyles: nested, compact Style/ClassAndModuleChildren: + Enabled: false + +# Offense count: 1 +# Configuration parameters: MinBodyLength. +Style/GuardClause: Exclude: - - 'app/controllers/api/v0/api_controller.rb' - - 'app/controllers/internal/application_controller.rb' - - 'app/controllers/internal/articles_controller.rb' - - 'app/controllers/internal/broadcasts_controller.rb' - - 'app/controllers/internal/buffer_updates_controller.rb' - - 'app/controllers/internal/comments_controller.rb' - - 'app/controllers/internal/dogfood_controller.rb' - - 'app/controllers/internal/feedback_messages_controller.rb' - - 'app/controllers/internal/members_controller.rb' - - 'app/controllers/internal/reactions_controller.rb' - - 'app/controllers/internal/tags_controller.rb' - - 'app/controllers/internal/users_controller.rb' - - 'app/controllers/internal/welcome_controller.rb' - - 'app/controllers/notifications/counts_controller.rb' - - 'app/controllers/notifications/reads_controller.rb' + - 'app/models/article.rb' -# Offense count: 1754 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# Offense count: 2101 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: - Max: 279 + Max: 278 diff --git a/Gemfile b/Gemfile index 2afbbd20a8dde..22640a4ee6a62 100644 --- a/Gemfile +++ b/Gemfile @@ -117,9 +117,9 @@ group :development do gem "pry", "~> 0.12" # An IRB alternative and runtime developer console gem "pry-rails", "~> 0.3" # Use Pry as your rails console gem "web-console", "~> 3.7" # Rails Console on the Browser + gem "yard", "~> 0.9.19" # YARD is a documentation generation tool for the Ruby programming language gem "yard-activerecord", "~> 0.0.16" # YARD extension that handles and interprets methods used when developing applications with ActiveRecord gem "yard-activesupport-concern", "~> 0.0.1" # YARD extension that brings support for modules making use of ActiveSupport::Concern - gem "yard", "~> 0.9.19" # YARD is a documentation generation tool for the Ruby programming language end group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index a2d218e3f4afe..d3fcb34f4d089 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -646,8 +646,8 @@ GEM rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 1.7) - rubocop-performance (1.1.0) - rubocop (>= 0.67.0) + rubocop-performance (1.3.0) + rubocop (>= 0.68.0) rubocop-rspec (1.33.0) rubocop (>= 0.60.0) ruby-prof (0.17.0) diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 5875bd8ee6ce2..089335e38f0c2 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -104,14 +104,15 @@ def preview if @article format.json { render json: @article.errors, status: :unprocessable_entity } else - format.json { render json: { - processed_html: processed_html, - title: parsed["title"], - tags: (Article.new.tag_list.add(parsed["tags"], parser: ActsAsTaggableOn::TagParser) if parsed["tags"]), - cover_image: (ApplicationController.helpers.cloud_cover_url(parsed["cover_image"]) if parsed["cover_image"]) - }, - status: 200 - } + format.json do + render json: { + processed_html: processed_html, + title: parsed["title"], + tags: (Article.new.tag_list.add(parsed["tags"], parser: ActsAsTaggableOn::TagParser) if parsed["tags"]), + cover_image: (ApplicationController.helpers.cloud_cover_url(parsed["cover_image"]) if parsed["cover_image"]) + }, + status: 200 + end end end end diff --git a/app/controllers/reading_list_items_controller.rb b/app/controllers/reading_list_items_controller.rb index 96996ea1c779d..fbdd5916a30c6 100644 --- a/app/controllers/reading_list_items_controller.rb +++ b/app/controllers/reading_list_items_controller.rb @@ -1,5 +1,4 @@ class ReadingListItemsController < ApplicationController - def index @reading_list_items_index = true set_view @@ -9,6 +8,7 @@ def index def update @reaction = Reaction.find(params[:id]) raise if @reaction.user_id != current_user.id # Lazy but I'm tired. HACK + @reaction.status = params[:current_status] == "archived" ? "valid" : "archived" @reaction.save head :ok diff --git a/app/labor/markdown_parser.rb b/app/labor/markdown_parser.rb index 8b678f992ece4..c375f65d6f1d3 100644 --- a/app/labor/markdown_parser.rb +++ b/app/labor/markdown_parser.rb @@ -90,6 +90,7 @@ def prefix_all_images(html, width = 880) next unless src # allow image to render as-is next if allowed_image_host?(src) + img["loading"] = "lazy" img["src"] = if giphy_img?(src) src.gsub("https://media.", "https://i.") diff --git a/app/models/reaction.rb b/app/models/reaction.rb index fea8c2ec511b6..287688f6e67ac 100644 --- a/app/models/reaction.rb +++ b/app/models/reaction.rb @@ -111,6 +111,7 @@ def remove_from_index def reactable_user return unless category == "readinglist" + { username: reactable.user_username, name: reactable.user_name, diff --git a/app/services/article_with_video_creation_service.rb b/app/services/article_with_video_creation_service.rb index f7bb6fac633f1..3f306a8675569 100644 --- a/app/services/article_with_video_creation_service.rb +++ b/app/services/article_with_video_creation_service.rb @@ -11,7 +11,6 @@ def initialize(article_params, current_user) def create! Article.create! do |article| - article = initial_article_with_params(article) article.processed_html = "" article.user_id = @current_user.id diff --git a/docs/Gemfile b/docs/Gemfile index c022a49e0b891..3283533006bef 100644 --- a/docs/Gemfile +++ b/docs/Gemfile @@ -5,6 +5,6 @@ source "https://rubygems.org" git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } gem "activerecord", "~> 5.2.3" # Databases on Rails +gem "yard", "~> 0.9.19" # YARD is a documentation generation tool for the Ruby programming language gem "yard-activerecord", "~> 0.0.16" # YARD extension that handles and interprets methods used when developing applications with ActiveRecord gem "yard-activesupport-concern", "~> 0.0.1" # YARD extension that brings support for modules making use of ActiveSupport::Concern -gem "yard", "~> 0.9.19" # YARD is a documentation generation tool for the Ruby programming language diff --git a/spec/requests/reading_list_items_spec.rb b/spec/requests/reading_list_items_spec.rb index 9b54ce71775ce..a99b6dfc59758 100644 --- a/spec/requests/reading_list_items_spec.rb +++ b/spec/requests/reading_list_items_spec.rb @@ -15,7 +15,7 @@ expect(reaction.reload.status).to eq("archived") end it "unarchives an item if current_status is passed as archived" do - put "/reading_list_items/#{reaction.id}", params: {current_status: "archived"} + put "/reading_list_items/#{reaction.id}", params: { current_status: "archived" } expect(reaction.reload.status).to eq("valid") end end