From 056fe5ec3f0ad62fa6edf2ac7b382e29bcdbdf95 Mon Sep 17 00:00:00 2001 From: Artem Chernikov Date: Mon, 21 Jul 2014 14:37:26 +0200 Subject: [PATCH] Fix others additional lints --- .rubocop.yml | 21 ++++++++----------- .../admin/dietchoices_controller.rb | 2 +- .../admin/eventtypes_controller.rb | 2 +- .../admin/registrations_controller.rb | 4 ++-- .../admin/supporter_levels_controller.rb | 2 +- .../admin/volunteers_controller.rb | 2 +- .../conference_registration_controller.rb | 2 +- .../event_attachments_controller.rb | 2 +- app/controllers/proposal_controller.rb | 6 +++--- .../users/omniauth_callbacks_controller.rb | 2 +- app/helpers/application_helper.rb | 2 +- app/models/ability.rb | 2 +- app/models/conference.rb | 2 +- app/models/datatable.rb | 6 +++--- config/environment.rb | 2 +- ...23203_add_events_per_week_to_conference.rb | 2 +- spec/features/user_spec.rb | 4 +++- spec/features/volunteers_spec.rb | 2 +- 18 files changed, 33 insertions(+), 34 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 9c4550a3..5aa96d75 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -55,28 +55,25 @@ Lint/Loop: Lint/ParenthesesAsGroupedExpression: Enabled: true -# Offense count: 13 -# Cop supports --auto-correct. +# Do not rescue Exceptions class itself Lint/RescueException: Enabled: true -# Offense count: 1 +# do not shadow local variables in blocks, choose other name Lint/ShadowingOuterLocalVariable: - Enabled: false + Enabled: true -# Offense count: 5 -# Cop supports --auto-correct. +# use _ or variable_name to explicitly mark variable as unused Lint/UnusedBlockArgument: - Enabled: false + Enabled: true -# Offense count: 2 -# Cop supports --auto-correct. +# use _ or _argument_name to explicitly mark argument as unused Lint/UnusedMethodArgument: - Enabled: false + Enabled: true -# Offense count: 6 +# avoid useless assignment Lint/UselessAssignment: - Enabled: false + Enabled: true # Offense count: 1 Lint/Void: diff --git a/app/controllers/admin/dietchoices_controller.rb b/app/controllers/admin/dietchoices_controller.rb index 688cd632..f1258dce 100644 --- a/app/controllers/admin/dietchoices_controller.rb +++ b/app/controllers/admin/dietchoices_controller.rb @@ -9,7 +9,7 @@ class Admin::DietchoicesController < ApplicationController begin @conference.update_attributes!(params[:conference]) redirect_to(admin_conference_dietary_list_path(:conference_id => @conference.short_title), :notice => 'Dietary choices were successfully updated.') - rescue Exception => e + rescue => e redirect_to(admin_conference_dietary_list_path(:conference_id => @conference.short_title), :alert => "Dietary choices update failed: #{e.message}") end end diff --git a/app/controllers/admin/eventtypes_controller.rb b/app/controllers/admin/eventtypes_controller.rb index d29f78cd..286e8f75 100644 --- a/app/controllers/admin/eventtypes_controller.rb +++ b/app/controllers/admin/eventtypes_controller.rb @@ -10,7 +10,7 @@ class Admin::EventtypesController < ApplicationController redirect_to(admin_conference_eventtypes_path( conference_id: @conference.short_title), notice: 'Event types were successfully updated.') - rescue Exception => e + rescue => e redirect_to(admin_conference_eventtypes_path( conference_id: @conference.short_title), alert: "Event types update failed: #{e.message}") diff --git a/app/controllers/admin/registrations_controller.rb b/app/controllers/admin/registrations_controller.rb index e00fa7ba..6ebe3db0 100644 --- a/app/controllers/admin/registrations_controller.rb +++ b/app/controllers/admin/registrations_controller.rb @@ -44,7 +44,7 @@ module Admin @registration.update_attributes!(params[:registration]) flash[:success] = "Successfully updated registration for #{@user.name} #{@user.email}" redirect_to(admin_conference_registrations_path(@conference.short_title)) - rescue Exception => e + rescue => e Rails.logger.debug e.backtrace.join("\n") redirect_to(admin_conference_registrations_path(@conference.short_title), alert: 'Failed to update registration:' + e.message) @@ -104,7 +104,7 @@ module Admin begin registration.destroy redirect_to admin_conference_registrations_path flash[:notice] = "Deleted registration for #{user.name} #{user.email}" - rescue Exception => e + rescue => e Rails.logger.debug e.backtrace.join("\n") redirect_to(admin_conference_registrations_path(@conference.short_title), alert: 'Failed to delete registration:' + e.message) diff --git a/app/controllers/admin/supporter_levels_controller.rb b/app/controllers/admin/supporter_levels_controller.rb index e835dcf5..3e11db97 100644 --- a/app/controllers/admin/supporter_levels_controller.rb +++ b/app/controllers/admin/supporter_levels_controller.rb @@ -9,7 +9,7 @@ class Admin::SupporterLevelsController < ApplicationController begin @conference.update_attributes!(params[:conference]) redirect_to(admin_conference_supporter_levels_path(:conference_id => @conference.short_title), :notice => 'Supporter levels were successfully updated.') - rescue Exception => e + rescue => e redirect_to(admin_conference_supporter_levels_path(:conference_id => @conference.short_title), :alert => "Supporter levels update failed: #{e.message}") end end diff --git a/app/controllers/admin/volunteers_controller.rb b/app/controllers/admin/volunteers_controller.rb index 0da1f31f..31593893 100644 --- a/app/controllers/admin/volunteers_controller.rb +++ b/app/controllers/admin/volunteers_controller.rb @@ -18,7 +18,7 @@ class Admin::VolunteersController < ApplicationController begin @conference.update_attributes!(params[:conference]) redirect_to(admin_conference_volunteers_info_path(:conference_id => params[:conference_id]), :notice => "Volunteering options were successfully updated.") - rescue Exception => e + rescue => e redirect_to(admin_conference_volunteers_info_path(:conference_id => params[:conference_id]), :alert => "Volunteering options update failed: #{e.message}") end end diff --git a/app/controllers/conference_registration_controller.rb b/app/controllers/conference_registration_controller.rb index 4fbf2a0a..3d9f0513 100644 --- a/app/controllers/conference_registration_controller.rb +++ b/app/controllers/conference_registration_controller.rb @@ -68,7 +68,7 @@ class ConferenceRegistrationController < ApplicationController else registration.update_attributes!(registration_params) end - rescue Exception => e + rescue => e Rails.logger.debug e.backtrace.join('\n') redirect_to(register_conference_path(id: conference.short_title), alert: 'Registration failed:' + e.message) diff --git a/app/controllers/event_attachments_controller.rb b/app/controllers/event_attachments_controller.rb index 7a7c1514..61a76b0b 100644 --- a/app/controllers/event_attachments_controller.rb +++ b/app/controllers/event_attachments_controller.rb @@ -53,7 +53,7 @@ class EventAttachmentsController < ApplicationController if !organizer_or_admin? begin event = current_user.events.find(params[:proposal_id]) - rescue Exception => e + rescue => e # They certainly aren't allowed to attach a file to someone else's proposal raise ActionController::RoutingError.new('Invalid proposal') end diff --git a/app/controllers/proposal_controller.rb b/app/controllers/proposal_controller.rb index 1016bad7..9334c4df 100644 --- a/app/controllers/proposal_controller.rb +++ b/app/controllers/proposal_controller.rb @@ -23,7 +23,7 @@ class ProposalController < ApplicationController else @event = Event.find(params[:id]) end - rescue Exception => e + rescue => e Rails.logger.debug("Proposal failure in verify_access: #{e.message}") redirect_to(conference_proposal_index_path(conference_id: @conference.short_title), alert: 'Invalid or uneditable proposal.') @@ -91,7 +91,7 @@ class ProposalController < ApplicationController event.update_attributes!(params[:event]) redirect_to(conference_proposal_index_path(conference_id: @conference.short_title), notice: "'#{event.title}' was successfully updated.") - rescue Exception => e + rescue => e redirect_to edit_conference_proposal_path(@conference.short_title, @event), alert: e.message end end @@ -131,7 +131,7 @@ class ProposalController < ApplicationController begin @event.save! - rescue Exception => e + rescue => e @url = conference_proposal_index_path(@conference.short_title) @event_types = @conference.event_types @user = current_user diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index 4fa0341c..2833137a 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -26,7 +26,7 @@ module Users sign_in user redirect_to root_path, notice: user.email + " signed in successfully with #{provider}" - rescue Exception => e + rescue => e redirect_back_or_to new_user_registration_path, alert: 'Failed' + e.message end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 62a97153..620bf62a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -75,7 +75,7 @@ module ApplicationHelper end def normalize_array_length(hashmap, length) - hashmap.each do |key, value| + hashmap.each do |_, value| if value.length < length value.fill(value[-1], value.length...length) end diff --git a/app/models/ability.rb b/app/models/ability.rb index 58929d7a..1ca0df1d 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -1,7 +1,7 @@ class Ability include CanCan::Ability - def initialize(user) + def initialize(user) # rubocop:disable Lint/UnusedMethodArgument # Define abilities for the passed in user here. For example: # # user ||= User.new # guest user (not logged in) diff --git a/app/models/conference.rb b/app/models/conference.rb index fae89ad8..f269a1bb 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -639,7 +639,7 @@ class Conference < ActiveRecord::Base # ====Returns # * +Fixnum+ -> Progress in Percent def calculate_setup_progress(result) - (result.select { |k, v| v }.length / result.length.to_f * 100).round(0).to_s + (result.select { |_k, v| v }.length / result.length.to_f * 100).round(0).to_s end ## diff --git a/app/models/datatable.rb b/app/models/datatable.rb index 339d4897..4ba59673 100644 --- a/app/models/datatable.rb +++ b/app/models/datatable.rb @@ -9,7 +9,7 @@ class Datatable @view = view end - def as_json(options = {}) + def as_json { sEcho: params[:sEcho].to_i, iTotalRecords: @klass.count, @@ -55,10 +55,10 @@ class Datatable search_for = params[:sSearch].split(' ') terms = {} which_one = -1 - criteria = search_for.inject([]) do |criteria,atom| + criteria = search_for.inject([]) do |mem, atom| which_one += 1 terms["search#{which_one}".to_sym] = "%#{atom}%" - criteria << "(#{search_cols.map{|col| "#{col} like :search#{which_one}"}.join(' or ')})" + mem << "(#{search_cols.map{|col| "#{col} like :search#{which_one}"}.join(' or ')})" end.join(' and ') [criteria, terms] end diff --git a/config/environment.rb b/config/environment.rb index 760642c1..bcd18b20 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -5,7 +5,7 @@ require File.expand_path('../application', __FILE__) path = Rails.root.join("config", "config.yml") begin CONFIG = YAML.load_file(path)[Rails.env] -rescue Exception +rescue puts "Error while parsing config file #{path}" CONFIG = {} end diff --git a/db/migrate/20140701123203_add_events_per_week_to_conference.rb b/db/migrate/20140701123203_add_events_per_week_to_conference.rb index 04163176..bedf4f58 100644 --- a/db/migrate/20140701123203_add_events_per_week_to_conference.rb +++ b/db/migrate/20140701123203_add_events_per_week_to_conference.rb @@ -72,7 +72,7 @@ class AddEventsPerWeekToConference < ActiveRecord::Migration hash.each do |week, values| if previous - values.each do |state, value| + values.each do |state, _value| hash[week][state] += previous[state] end end diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index ddec87b8..5e5a57df 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -5,7 +5,8 @@ feature User do let!(:participant_role) { create(:participant_role) } let!(:admin_role) { create(:admin_role) } let(:admin) { create(:admin) } - shared_examples 'admin ability' do |user| + + shared_examples 'admin ability' do scenario 'deletes a user', feature: true, js: true do sign_in(admin) visit admin_users_path @@ -34,6 +35,7 @@ feature User do sign_out end end + describe 'admin' do it_behaves_like 'admin ability', :admin end diff --git a/spec/features/volunteers_spec.rb b/spec/features/volunteers_spec.rb index bc1e6d76..70f4e16b 100644 --- a/spec/features/volunteers_spec.rb +++ b/spec/features/volunteers_spec.rb @@ -8,7 +8,7 @@ feature Conference do let(:admin) { create(:admin) } let(:conference) { create(:conference) } - shared_examples 'volunteer' do |user| + shared_examples 'volunteer' do scenario 'adds and updates vdays', feature: true, js: true do sign_in(admin) visit admin_conference_volunteers_info_path(