Skip to content

Commit

Permalink
Merge pull request #915 from EFForg/jparr/913-rubocop-fixes
Browse files Browse the repository at this point in the history
Update rubocop and fix issues
  • Loading branch information
esoterik committed May 9, 2024
2 parents 320e9ba + ea38d35 commit b705ed4
Show file tree
Hide file tree
Showing 57 changed files with 76 additions and 288 deletions.
23 changes: 13 additions & 10 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
inherit_from: .rubocop_todo.yml
require:
- rubocop-rails
- rubocop-performance

inherit_gem:
rubocop-github:
- config/default_edge.yml
- config/rails_edge.yml
- config/default.yml
- config/rails.yml

AllCops:
TargetRailsVersion: 5.0
TargetRubyVersion: 2.7
NewCops: disable
TargetRailsVersion: 6.1
TargetRubyVersion: 3.0
NewCops: enable
SuggestExtensions: false
Exclude:
- 'db/**/*'
- 'config/**/*'
Expand Down Expand Up @@ -66,7 +69,10 @@ Performance/Squeeze:
Performance/StringInclude:
Enabled: true

### Override rubcop-github ###
Bundler/OrderedGems:
Enabled: false

### Override rubocop-github ###

Style/FrozenStringLiteralComment:
# We aren't upgrading to Ruby 3.0, so this is just noise
Expand All @@ -84,9 +90,6 @@ GitHub/RailsControllerRenderPathsExist:
# Doesn't seem to work; can't find templates that exist
Enabled: false

GitHub/RailsApplicationRecord:
# Rails/ApplicationRecord does the same thing
Enabled: false

Lint/Void:
Exclude:
Expand Down
186 changes: 0 additions & 186 deletions .rubocop_todo.yml

This file was deleted.

2 changes: 1 addition & 1 deletion app/controllers/admin/action_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Admin::ActionPagesController < Admin::ApplicationController
allow_collaborators_to :index, :edit

def index
@categories = Category.all.order(:title)
@categories = Category.order(:title)
@authors = User.authors.order(:last_name)
@actionPages = filter_action_pages

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/institutions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Admin::InstitutionsController < Admin::ApplicationController
before_action :set_categories, only: %i[new edit upload index]

def index
@institutions = Institution.includes(:action_pages).all.order(created_at: :desc)
@institutions = Institution.includes(:action_pages).order(created_at: :desc)
@institutions = @institutions.search(params[:q]) if params[:q].present?
@institutions = @institutions.where(category: params[:category]) if params[:category].present? && params[:category] != "All"
@institutions = @institutions.paginate(page: params[:page], per_page: 20)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/topic_sets_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Admin::TopicSetsController < Admin::ApplicationController
def index
topic_sets = TopicSet.all.order(:tier)
topic_sets = TopicSet.order(:tier)
render json: topic_sets
end

Expand Down
2 changes: 0 additions & 2 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ def handle_nonunique_email
existing.update(sign_up_params) unless existing.confirmed?

if resource.persisted?
# rubocop:todo Rails/SkipsModelValidations
resource.update_attribute(:unconfirmed_email, account_update_params[:email])
# rubocop:enable Rails/SkipsModelValidations
flash[:notice] = I18n.t "devise.registrations.update_needs_confirmation"
respond_with resource, location: after_update_path_for(resource)
else
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/tools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,9 @@ def set_user
@user = current_user
end

# rubocop:todo Naming/MemoizedInstanceVariableName
def set_action_page
@action_page ||= ActionPage.find_by(id: params[:action_id])
end
# rubocop:enable Naming/MemoizedInstanceVariableName

def create_newsletter_subscription
if params[:subscribe] && EmailValidator.valid?(params[:subscription][:email])
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ def update
end

def clear_activity
# rubocop:todo Rails/SkipsModelValidations
current_user.events.update_all(user_id: nil)
# rubocop:enable Rails/SkipsModelValidations
redirect_to user_path
end

Expand Down
6 changes: 3 additions & 3 deletions app/helpers/action_page_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def parse_email_text(options = {})
name = html_escape(options[:name])

email_text
.gsub(/\$TITLE/, title)
.gsub(/\$URL/, url)
.gsub(/\$NAME/, name)
.gsub("$TITLE", title)
.gsub("$URL", url)
.gsub("$NAME", name)
end

def visible_partners
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def messages
safe_join(messages)
end

def percentage(x, y, precision: 0) # rubocop:todo Naming/MethodParameterName
def percentage(x, y, precision: 0)
return "-" unless y > 0

number_to_percentage((x / y.to_f) * 100, precision: precision)
Expand Down
2 changes: 0 additions & 2 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ class UserMailer < ActionMailer::Base
layout "email"
after_action :check_bounces

# rubocop:todo Naming/MethodParameterName
def thanks_message(email, actionPage, options = {})
@email = email
@user = options[:user]
@actionPage = actionPage
@name = options[:name].presence || "Friend of Digital Freedom"
mail(to: email, subject: "Thanks for taking action")
end
# rubocop:enable Naming/MethodParameterName

def signup_attempt_with_existing_email(user, _options = {})
@user = user
Expand Down
2 changes: 1 addition & 1 deletion app/models/action_institution.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ActionInstitution < ActiveRecord::Base
class ActionInstitution < ApplicationRecord
belongs_to :institution
belongs_to :action_page

Expand Down
10 changes: 3 additions & 7 deletions app/models/action_page.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ActionPage < ActiveRecord::Base
class ActionPage < ApplicationRecord
extend AmazonCredentials
extend FriendlyId

Expand Down Expand Up @@ -36,13 +36,11 @@ class ActionPage < ActiveRecord::Base
belongs_to :congress_message_campaign
belongs_to :call_campaign
belongs_to :category, optional: true
# rubocop:todo Rails/InverseOf
belongs_to :active_action_page_for_redirect, class_name: "ActionPage",
foreign_key: "archived_redirect_action_page_id"
# rubocop:enable Rails/InverseOf
# rubocop:todo Rails/InverseOf

belongs_to :author, class_name: "User", foreign_key: :user_id, optional: true
# rubocop:enable Rails/InverseOf


accepts_nested_attributes_for :tweet, :petition, :email_campaign,
:call_campaign, :congress_message_campaign, :affiliation_types, :partnerships,
Expand Down Expand Up @@ -151,13 +149,11 @@ def image
[og_image, background_image, featured_image].find(&:present?)
end

# rubocop:todo Naming/MemoizedInstanceVariableName
def actions_taken_percent
return 0 if view_count == 0

@percent ||= (action_count / view_count.to_f) * 100
end
# rubocop:enable Naming/MemoizedInstanceVariableName

def status
if archived?
Expand Down
2 changes: 1 addition & 1 deletion app/models/affiliation.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Affiliation < ActiveRecord::Base
class Affiliation < ApplicationRecord
belongs_to :action_page
belongs_to :signature
belongs_to :affiliation_type
Expand Down
2 changes: 1 addition & 1 deletion app/models/affiliation_type.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AffiliationType < ActiveRecord::Base
class AffiliationType < ApplicationRecord
belongs_to :action_page
has_many :affiliations
end
2 changes: 1 addition & 1 deletion app/models/ahoy/event.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Ahoy
class Event < ActiveRecord::Base
class Event < ApplicationRecord
self.table_name = "ahoy_events"

belongs_to :visit
Expand Down
3 changes: 3 additions & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
2 changes: 1 addition & 1 deletion app/models/bounce.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
class Bounce < ActiveRecord::Base
class Bounce < ApplicationRecord
end

0 comments on commit b705ed4

Please sign in to comment.