From 3bfdeefad50c4d1fac26f633d36d054721c701b2 Mon Sep 17 00:00:00 2001 From: julesinberlin Date: Fri, 21 Feb 2020 22:22:39 +0100 Subject: [PATCH 1/4] Add rubocop --- .rubocop.yml | 13 +++++++++++++ Gemfile | 1 + Gemfile.lock | 16 ++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..859304a --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,13 @@ +inherit_from: .rubocop_todo.yml + +AllCops: + Exclude: + - 'config/initializers/devise.rb' + - 'db/schema*' + + +Style/Documentation: + Enabled: false + +Layout/LineLength: + IgnoredPatterns: ['(\A|\s)#'] diff --git a/Gemfile b/Gemfile index cfda8d1..7d2ea97 100644 --- a/Gemfile +++ b/Gemfile @@ -32,6 +32,7 @@ group :development, :test do gem 'pry-rails' gem 'rails-controller-testing' gem 'rspec-rails', '~> 3.8' + gem 'rubocop', '~> 0.79.0', require: false end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index c467d53..9784dcc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -39,6 +39,7 @@ GEM minitest (~> 5.1) tzinfo (~> 1.1) arel (8.0.0) + ast (2.4.0) autoprefixer-rails (9.5.0) execjs bcrypt (3.1.13) @@ -111,6 +112,7 @@ GEM i18n (1.7.0) concurrent-ruby (~> 1.0) ipaddress (0.8.3) + jaro_winkler (1.5.4) jbuilder (2.8.0) activesupport (>= 4.2.0) multi_json (>= 1.2) @@ -140,6 +142,9 @@ GEM nokogiri (1.10.5) mini_portile2 (~> 2.4.0) orm_adapter (0.5.0) + parallel (1.19.1) + parser (2.7.0.2) + ast (~> 2.4.0) pg (1.1.4) popper_js (1.14.5) pry (0.12.2) @@ -181,6 +186,7 @@ GEM method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) + rainbow (3.0.0) rake (13.0.0) rb-fsevent (0.10.3) rb-inotify (0.10.0) @@ -205,6 +211,14 @@ GEM rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) rspec-support (3.8.0) + rubocop (0.79.0) + jaro_winkler (~> 1.5.1) + parallel (~> 1.10) + parser (>= 2.7.0.1) + rainbow (>= 2.2.2, < 4.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 1.7) + ruby-progressbar (1.10.1) ruby_dep (1.5.0) sass (3.7.3) sass-listen (~> 4.0.0) @@ -234,6 +248,7 @@ GEM thread_safe (~> 0.1) uglifier (4.1.20) execjs (>= 0.3.0, < 3) + unicode-display_width (1.6.1) warden (1.2.8) rack (>= 2.0.6) web-console (3.7.0) @@ -270,6 +285,7 @@ DEPENDENCIES rails (~> 5.1.4) rails-controller-testing rspec-rails (~> 3.8) + rubocop (~> 0.79.0) sass-rails (~> 5.0) sprockets-rails turbolinks (~> 5) From ebc6f6beab77b04b68be53f4b7e937848855139b Mon Sep 17 00:00:00 2001 From: julesinberlin Date: Sat, 22 Feb 2020 15:39:48 +0100 Subject: [PATCH 2/4] Visualize existing style violations --- .rubocop_todo.yml | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..20a9315 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,72 @@ +# This configuration was generated by +# `rubocop --auto-gen-config`. +# 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: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only +Layout/EmptyLinesAroundClassBody: + Exclude: + - 'app/models/user.rb' + +# Offense count: 5 +Metrics/AbcSize: + Max: 20 + +# Offense count: 7 +# Configuration parameters: CountComments, ExcludedMethods. +# ExcludedMethods: refine +Metrics/BlockLength: + Max: 118 + +# Offense count: 7 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/MethodLength: + Max: 18 + +# Offense count: 2 +# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros. +# NamePrefix: is_, has_, have_ +# ForbiddenPrefixes: is_, has_, have_ +# AllowedMethods: is_a? +# MethodDefinitionMacros: define_method, define_singleton_method +Naming/PredicateName: + Exclude: + - 'spec/**/*' + - 'app/helpers/application_helper.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, EnforcedStyle. +# SupportedStyles: nested, compact +Style/ClassAndModuleChildren: + Exclude: + - 'app/controllers/users/registrations_controller.rb' + +# Offense count: 1 +# Configuration parameters: MinBodyLength. +Style/GuardClause: + Exclude: + - 'app/models/ability.rb' + +# Offense count: 1 +Style/IfUnlessModifier: + Exclude: + - 'spec/rails_helper.rb' + +# Offense count: 2 +Style/MixinUsage: + Exclude: + - 'bin/setup' + - 'bin/update' + +# Offense count: 29 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Layout/LineLength: + Max: 121 From e435cadc0436c92405c19334ff01c9501203d8b9 Mon Sep 17 00:00:00 2001 From: julesinberlin Date: Sat, 22 Feb 2020 21:22:48 +0100 Subject: [PATCH 3/4] Fix 'Layout/EmptyLinesAroundClassBody' offense --- .rubocop_todo.yml | 8 -------- app/models/user.rb | 1 - 2 files changed, 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 20a9315..fa7bd67 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,14 +5,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only -Layout/EmptyLinesAroundClassBody: - Exclude: - - 'app/models/user.rb' - # Offense count: 5 Metrics/AbcSize: Max: 20 diff --git a/app/models/user.rb b/app/models/user.rb index 558a8ee..8b660b2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -27,5 +27,4 @@ def managed_houses end array end - end From 97fe3755f498e41cc96543da1b9a2d17dda33772 Mon Sep 17 00:00:00 2001 From: julesinberlin Date: Sat, 22 Feb 2020 22:02:50 +0100 Subject: [PATCH 4/4] Address 'Layout/LineLength' offenses --- .rubocop_todo.yml | 12 ++++++++++- app/controllers/application_controller.rb | 13 +++++++++--- app/controllers/groups_controller.rb | 25 ++++++++++++++++++----- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fa7bd67..7be6a6d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -61,4 +61,14 @@ Style/MixinUsage: # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Layout/LineLength: - Max: 121 + Exclude: + - 'app/controllers/houses_controller.rb' + - 'app/controllers/tasks_controller.rb' + - 'app/uploaders/avatar_uploader.rb' + - 'app/uploaders/house_image_uploader.rb' + - 'config/environments/production.rb' + - 'db/migrate/20190521171605_first.rb' + - 'spec/controllers/houses_controller_spec.rb' + - 'spec/models/house_spec.rb' + - 'spec/models/user_spec.rb' + - 'spec/rails_helper.rb' diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c7686e0..e9d90b0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -8,14 +8,21 @@ class ApplicationController < ActionController::Base rescue_from CanCan::AccessDenied do |_exception| respond_to do |format| format.json { head :forbidden } - format.html { redirect_to houses_url, alert: "You're not authorized to perform this action." } + format.html do + redirect_to houses_url, + alert: "You're not authorized to perform this action." + end end end protected def configure_permitted_parameters - devise_parameter_sanitizer.permit(:sign_up, keys: %i[nickname firstname lastname bio birthday avatar]) - devise_parameter_sanitizer.permit(:account_update, keys: %i[nickname firstname lastname bio birthday avatar]) + devise_parameter_sanitizer.permit(:sign_up, + keys: %i[nickname firstname lastname bio + birthday avatar]) + devise_parameter_sanitizer.permit(:account_update, + keys: %i[nickname firstname lastname bio + birthday avatar]) end end diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 9d0efe3..3007c59 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -27,11 +27,17 @@ def create respond_to do |format| if @group.save - format.html { redirect_to house_group_url(@house, @group), notice: 'Group was successfully created.' } + format.html do + redirect_to house_group_url(@house, @group), + notice: 'Group was successfully created.' + end format.json { render :show, status: :created, location: @group } else format.html { render :new } - format.json { render json: @group.errors, status: :unprocessable_entity } + format.json do + render json: @group.errors, + status: :unprocessable_entity + end end end end @@ -39,11 +45,17 @@ def create def update respond_to do |format| if @group.update(group_params) - format.html { redirect_to house_group_url(@house, @group), notice: 'Group was successfully updated.' } + format.html do + redirect_to house_group_url(@house, @group), + notice: 'Group was successfully updated.' + end format.json { render :show, status: :ok, location: @group } else format.html { render :edit } - format.json { render json: @group.errors, status: :unprocessable_entity } + format.json do + render json: @group.errors, + status: :unprocessable_entity + end end end end @@ -51,7 +63,10 @@ def update def destroy @group.destroy respond_to do |format| - format.html { redirect_to house_groups_url, notice: 'Group was successfully destroyed.' } + format.html do + redirect_to house_groups_url, + notice: 'Group was successfully destroyed.' + end format.json { head :no_content } end end