Enable Style/RedundantSelf Rubocop cop

This cop checks for redundant uses of self. It supports autocorrection, so all the offenses where automatically solved.

Closes #1373
This commit is contained in:
Chaitanya 2017-03-28 13:27:52 +05:30
parent 444ceb8960
commit 4427f43bdf
11 changed files with 48 additions and 60 deletions

View file

@ -76,6 +76,10 @@ Style/HashSyntax:
Style/NilComparison:
Enabled: true
# Checks for redundant uses of self.
Style/RedundantSelf:
Enabled: true
# Use single quotes unless there's string interpolation
Style/StringLiterals:
Enabled: true

View file

@ -527,22 +527,6 @@ Style/RedundantReturn:
Exclude:
- 'app/helpers/application_helper.rb'
# Offense count: 61
# Cop supports --auto-correct.
Style/RedundantSelf:
Exclude:
- 'app/models/ahoy/program.rb'
- 'app/models/call_for_paper.rb'
- 'app/models/cfp.rb'
- 'app/models/comment.rb'
- 'app/models/conference.rb'
- 'app/models/event.rb'
- 'app/models/program.rb'
- 'app/models/question.rb'
- 'app/models/ticket.rb'
- 'app/models/user.rb'
- 'app/models/venue.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.

View file

@ -16,11 +16,11 @@ class Cfp < ActiveRecord::Base
# * +True+ -> If cfp dates is updated and all other parameters are set
# * +False+ -> Either cfp date is not updated or one or more parameter is not set
def notify_on_cfp_date_update?
!self.end_date.blank? && !self.start_date.blank?\
&& (self.start_date_changed? || self.end_date_changed?)\
&& self.program.conference.email_settings.send_on_cfp_dates_updated\
&& !self.program.conference.email_settings.cfp_dates_updated_subject.blank?\
&& !self.program.conference.email_settings.cfp_dates_updated_body.blank?
!end_date.blank? && !start_date.blank?\
&& (start_date_changed? || end_date_changed?)\
&& program.conference.email_settings.send_on_cfp_dates_updated\
&& !program.conference.email_settings.cfp_dates_updated_subject.blank?\
&& !program.conference.email_settings.cfp_dates_updated_body.blank?
end
##
@ -51,7 +51,7 @@ class Cfp < ActiveRecord::Base
end
def remaining_days(date = Date.today)
result = (self.end_date - date).to_i
result = (end_date - date).to_i
result > 0 ? result : 0
end

View file

@ -27,7 +27,7 @@ class Comment < ActiveRecord::Base
#helper method to check if a comment has children
def has_children?
self.children.any?
children.any?
end
# Helper class method to lookup all comments assigned

View file

@ -555,9 +555,9 @@ class Conference < ActiveRecord::Base
# * +True+ -> If conference is updated and all other parameters are set
# * +False+ -> Either conference is not updated or one or more parameter is not set
def notify_on_dates_changed?
return false unless self.email_settings.send_on_conference_dates_updated
return false unless email_settings.send_on_conference_dates_updated
# do not notify unless one of the dates changed
return false unless self.start_date_changed? || self.end_date_changed?
return false unless start_date_changed? || end_date_changed?
# do not notify unless the mail content is set up
(!email_settings.conference_dates_updated_subject.blank? && !email_settings.conference_dates_updated_body.blank?)
end
@ -569,9 +569,9 @@ class Conference < ActiveRecord::Base
# * +True+ -> If registration dates is updated and all other parameters are set
# * +False+ -> Either registration date is not updated or one or more parameter is not set
def notify_on_registration_dates_changed?
return false unless self.email_settings.send_on_conference_registration_dates_updated
return false unless email_settings.send_on_conference_registration_dates_updated
# do not notify unless we allow a registration
return false unless self.registration_period
return false unless registration_period
# do not notify unless one of the dates changed
return false unless registration_period.start_date_changed? || registration_period.end_date_changed?
# do not notify unless the mail content is set up
@ -628,8 +628,8 @@ class Conference < ActiveRecord::Base
end
after_create do
self.create_contact
self.create_program
create_contact
create_program
create_roles
end

View file

@ -185,12 +185,12 @@ class Event < ActiveRecord::Base
end
begin
if mail
self.send(transition,
send_mail: send_mail_param)
send(transition,
send_mail: send_mail_param)
else
self.send(transition)
send(transition)
end
self.save
save
rescue Transitions::InvalidTransition => e
alert = "Update state failed. #{e.message}"
end
@ -210,12 +210,12 @@ class Event < ActiveRecord::Base
# Returns +Hash+
def progress_status
{
registered: self.program.conference.user_registered?(self.submitter),
commercials: self.commercials.any?,
biography: !self.submitter.biography.blank?,
subtitle: !self.subtitle.blank?,
track: (!self.track.blank? unless self.program.tracks.empty?),
difficulty_level: !self.difficulty_level.blank?,
registered: program.conference.user_registered?(submitter),
commercials: commercials.any?,
biography: !submitter.biography.blank?,
subtitle: !subtitle.blank?,
track: (!track.blank? unless program.tracks.empty?),
difficulty_level: !difficulty_level.blank?,
title: true,
abstract: true
}.with_indifferent_access
@ -227,7 +227,7 @@ class Event < ActiveRecord::Base
# ====Returns
# * +String+ -> Progress in Percent
def calculate_progress
result = self.progress_status
result = progress_status
(100 * result.values.count(true) / result.values.compact.count).to_s
end
@ -280,8 +280,8 @@ class Event < ActiveRecord::Base
def set_week
self.week = created_at.strftime('%W')
self.without_versioning do
self.save!
without_versioning do
save!
end
end

View file

@ -115,7 +115,7 @@ class Program < ActiveRecord::Base
# * +false+ -> If rating is not enabled
# * +true+ -> If rating is enabled
def rating_enabled?
self.rating && self.rating > 0
rating && rating > 0
end
##
@ -139,7 +139,7 @@ class Program < ActiveRecord::Base
end
def languages_list
self.languages.split(',').map {|l| ISO_639.find(l).english_name} if self.languages.present?
languages.split(',').map {|l| ISO_639.find(l).english_name} if languages.present?
end
##
@ -161,10 +161,10 @@ class Program < ActiveRecord::Base
def create_event_types
EventType.create(title: 'Talk', length: 30, color: '#FF0000', description: 'Presentation in lecture format',
minimum_abstract_length: 0,
maximum_abstract_length: 500, program_id: self.id)
maximum_abstract_length: 500, program_id: id)
EventType.create(title: 'Workshop', length: 60, color: '#0000FF', description: 'Interactive hands-on practice',
minimum_abstract_length: 0,
maximum_abstract_length: 500, program_id: self.id)
maximum_abstract_length: 500, program_id: id)
true
end
@ -174,13 +174,13 @@ class Program < ActiveRecord::Base
def create_difficulty_levels
DifficultyLevel.create(title: 'Easy',
description: 'Events are understandable for everyone without knowledge of the topic.',
color: '#70EF69', program_id: self.id)
color: '#70EF69', program_id: id)
DifficultyLevel.create(title: 'Medium',
description: 'Events require a basic understanding of the topic.',
color: '#EEEF69', program_id: self.id)
color: '#EEEF69', program_id: id)
DifficultyLevel.create(title: 'Hard',
description: 'Events require expert knowledge of the topic.',
color: '#EF6E69', program_id: self.id)
color: '#EF6E69', program_id: id)
true
end
@ -188,12 +188,12 @@ class Program < ActiveRecord::Base
# Check if languages string has the right format. Used as validation.
#
def check_languages_format
return unless self.languages.present?
return unless languages.present?
# All white spaces are removed to allow languages to be separated by ',' and ', '. The languages string without spaces is saved
self.languages = self.languages.delete(' ').downcase
self.languages = languages.delete(' ').downcase
errors.add(:languages, 'must be two letters separated by commas') && return unless
self.languages.match(/^$|(\A[a-z][a-z](,[a-z][a-z])*\z)/).present?
languages_array = self.languages.split(',')
languages.match(/^$|(\A[a-z][a-z](,[a-z][a-z])*\z)/).present?
languages_array = languages.split(',')
# We check that languages are not repeated
errors.add(:languages, "can't be repeated") && return unless languages_array.uniq!.nil?
# We check if every language is a valid ISO 639-1 language

View file

@ -12,6 +12,6 @@ class Question < ActiveRecord::Base
private
def existing_answers
errors.add(:base, 'Must have answers') if self.answers.blank?
errors.add(:base, 'Must have answers') if answers.blank?
end
end

View file

@ -66,7 +66,7 @@ class Ticket < ActiveRecord::Base
private
def tickets_of_conference_have_same_currency
unless Ticket.where(conference_id: conference_id).all?{|t| t.price_currency == self.price_currency }
unless Ticket.where(conference_id: conference_id).all?{|t| t.price_currency == price_currency }
errors.add(:price_currency, 'is different from the existing tickets of this conference.')
end
end

View file

@ -72,7 +72,7 @@ class User < ActiveRecord::Base
# * +true+ if the user attended the event
# * +false+ if the user did not attend the event
def attended_event? event
event_registration = event.events_registrations.find_by(registration: self.registrations)
event_registration = event.events_registrations.find_by(registration: registrations)
return false unless event_registration.present?
event_registration.attended
@ -91,7 +91,7 @@ class User < ActiveRecord::Base
end
def subscribed? conference
self.subscriptions.find_by(conference_id: conference.id).present?
subscriptions.find_by(conference_id: conference.id).present?
end
def supports? conference
@ -206,8 +206,8 @@ class User < ActiveRecord::Base
# Check if biography has an allowed number of words. Used as validation.
#
def biography_limit
if self.biography.present?
errors.add(:biography, 'is limited to 150 words.') if self.biography.split.length > 150
if biography.present?
errors.add(:biography, 'is limited to 150 words.') if biography.split.length > 150
end
end
end

View file

@ -35,7 +35,7 @@ class Venue < ActiveRecord::Base
def notify_on_venue_changed?
return false unless conference.try(:email_settings).try(:send_on_venue_updated)
# do not notify unless the address changed
return false unless self.name_changed? || self.street_changed? || self.city_changed? || self.country_changed?
return false unless name_changed? || street_changed? || city_changed? || country_changed?
# do not notify unless the mail content is set up
(!conference.email_settings.venue_updated_subject.blank? && !conference.email_settings.venue_updated_body.blank?)
end