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/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..7be6a6d --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,74 @@ +# 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: 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: + 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/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) 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 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