standardrb: standard-rails

This commit is contained in:
Peter Bhat Harkins 2023-09-14 08:29:11 -05:00
parent c2935af068
commit b3d6903f05
18 changed files with 40 additions and 26 deletions

View File

@ -2,3 +2,14 @@ ignore:
# it's mad about the class variables and I don't want to risk the refactor now
- 'extras/**/*':
- Naming/VariableName
# migrations are not live code; ignore those before standardrb
- 'db/migrate/201*'
- 'db/migrate/2020*'
- 'db/migrate/202309*'
plugins:
- standard-rails
# Needs to be packaged as a plugin https://github.com/standardrb/standard#user-content-plugins
# - use_form_with:
# require_path: extras/prohibit_form_for_and_form_tag
# plugin_class_name: RuboCop::Cop::Style::DisallowFormForandFormTag

View File

@ -55,6 +55,7 @@ group :test, :development do
gem "rspec-rails", "~> 6.0.0.rc1"
gem "factory_bot_rails"
gem "standard"
gem "standard-rails"
gem "faker"
gem "byebug"
gem "rb-readline"

View File

@ -270,6 +270,10 @@ GEM
rubocop-performance (1.19.0)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.20.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
ruby-progressbar (1.13.0)
ruby-rc4 (0.1.5)
scenic (1.7.0)
@ -309,6 +313,9 @@ GEM
standard-performance (1.2.0)
lint_roller (~> 1.1)
rubocop-performance (~> 1.19.0)
standard-rails (0.2.0)
lint_roller (~> 1.0)
rubocop-rails (~> 2.20.2)
svg-graph (2.2.2)
thor (1.2.2)
timeout (0.4.0)
@ -374,6 +381,7 @@ DEPENDENCIES
sprockets-rails (= 2.3.3)
stackprof
standard
standard-rails
svg-graph
uglifier (>= 1.3.0)
vcr

View File

@ -50,7 +50,7 @@ class RepliesController < ApplicationController
# with the current user's vote added by StoriesController.load_user_votes
def apply_current_vote
@replies.each do |r|
next unless r.current_vote_vote.present?
next if r.current_vote_vote.blank?
r.comment.current_vote = {
vote: r.current_vote_vote,
reason: r.current_vote_reason.to_s

View File

@ -158,12 +158,12 @@ class SettingsController < ApplicationController
end
def pushover_callback
if !session[:pushover_rand].to_s.present?
if session[:pushover_rand].to_s.blank?
flash[:error] = "No random token present in session"
return redirect_to "/settings"
end
if !params[:rand].to_s.present?
if params[:rand].to_s.blank?
flash[:error] = "No random token present in URL"
return redirect_to "/settings"
end
@ -190,8 +190,8 @@ class SettingsController < ApplicationController
end
def github_callback
if !session[:github_state].present? ||
!params[:code].present? ||
if session[:github_state].blank? ||
params[:code].blank? ||
(params[:state].to_s != session[:github_state].to_s)
flash[:error] = "Invalid OAuth state"
return redirect_to "/settings"

View File

@ -35,7 +35,7 @@ class StoriesController < ApplicationController
update_story_attributes
if @story.user_id != @user.id && @user.is_moderator? && !@story.moderation_reason.present?
if @story.user_id != @user.id && @user.is_moderator? && @story.moderation_reason.blank?
@story.errors.add(:moderation_reason, message: "is required")
return render action: "edit"
end
@ -97,7 +97,7 @@ class StoriesController < ApplicationController
# ignore what the user brought unless we need it as a fallback
@story.title = sattrs[:title]
if !@story.title.present? && params[:title].present?
if @story.title.blank? && params[:title].present?
@story.title = params[:title]
end
end
@ -367,7 +367,7 @@ class StoriesController < ApplicationController
end
def check_url_dupe
raise ActionController::ParameterMissing.new("No URL") unless story_params[:url].present?
raise ActionController::ParameterMissing.new("No URL") if story_params[:url].blank?
@story = Story.new(user: @user)
@story.attributes = story_params
@story.already_posted_recently?

View File

@ -97,7 +97,7 @@ class UsersController < ApplicationController
return redirect_to "/"
end
if !params[:reason].present?
if params[:reason].blank?
flash[:error] = "You must give a reason for the ban."
return redirect_to user_path(user: buser.username)
end

View File

@ -75,8 +75,6 @@ class Comment < ApplicationRecord
SCORE_RANGE_TO_HIDE = (-2..4)
validates :short_id, length: {maximum: 10}
validates :user_id, presence: true
validates :story_id, presence: true
validates :markeddown_comment, length: {maximum: 16_777_215}
validates :comment, presence: {with: true, message: "cannot be empty."}
@ -206,7 +204,7 @@ class Comment < ApplicationRecord
recent = Comment.where("created_at >= ?", delay.ago)
.find_by(user: user, thread_id: parent_comment.thread_id)
return false unless recent.present?
return false if recent.blank?
wait = ActionController::Base.helpers
.distance_of_time_in_words(Time.now, (recent.created_at + delay))

View File

@ -4,7 +4,7 @@ class Hat < ApplicationRecord
after_create :log_moderation
validates :user, :granted_by_user, :hat, presence: true
validates :hat, presence: true
validates :hat, :link, length: {maximum: 255}
scope :active, -> { joins(:user).where(doffed_at: nil).merge(User.active) }

View File

@ -2,8 +2,6 @@ class ReadRibbon < ApplicationRecord
belongs_to :user
belongs_to :story
validates :user, :story, presence: true
# don't add callbacks to this model; for performance the read tracking in
# StoriesController uses .bump and RepliesController uses update_all, etc.

View File

@ -10,7 +10,7 @@ class ReplyingComment < ApplicationRecord
}
scope :unread_replies_for, ->(user_id) { for_user(user_id).where(is_unread: true) }
scope :comment_replies_for,
->(user_id) { for_user(user_id).where("parent_comment_id is not null") }
->(user_id) { for_user(user_id).where.not(parent_comment_id: nil) }
scope :story_replies_for, ->(user_id) { for_user(user_id).where("parent_comment_id is null") }
protected

View File

@ -243,7 +243,7 @@ class Story < ApplicationRecord
# doesn't include deleted/moderated/merged stories
def similar_stories
return Story.none unless url.present?
return Story.none if url.blank?
@_similar_stories ||= Story.find_similar_by_url(url).order("id DESC")
# do not include this story itself or any story merged into it
@ -253,7 +253,7 @@ class Story < ApplicationRecord
end
# do not include the story this one is merged into
if merged_story_id?
@_similar_stories = @_similar_stories.where("id != ?", merged_story_id)
@_similar_stories = @_similar_stories.where.not(id: merged_story_id)
end
@_similar_stories
end

View File

@ -54,9 +54,7 @@ class Vote < ApplicationRecord
Vote.where(
user_id: user_id, story_id: story_id
).where(
"comment_id IS NOT NULL"
).find_each do |v|
).where.not(comment_id: nil).find_each do |v|
votes[v.comment_id] = {vote: v.vote, reason: v.reason}
end

View File

@ -89,7 +89,7 @@ class EmailParser
rescue
end
elsif !email.content_type.to_s.present?
elsif email.content_type.to_s.blank?
# no content-type header, assume it's text/plain
@body = email.body.to_s
end

View File

@ -62,7 +62,7 @@ class Twitter
res = at.get("/1.1/account/verify_credentials.json")
js = JSON.parse(res.body)
if !js["screen_name"].present?
if js["screen_name"].blank?
return nil
end

View File

@ -38,7 +38,7 @@ elsif !parser.parent
warn "no valid comment or story being replied to"
exit EX_NOUSER
elsif !parser.body.present?
elsif parser.body.blank?
warn "no valid text/plain body found"
exit EX_UNAVAILABLE
end

View File

@ -77,7 +77,7 @@ if __FILE__ == $PROGRAM_NAME
# mark it done so we don't hit them again if we or they crash
Keystore.put(LAST_STORY_KEY, s.id)
next unless s.url.present?
next if s.url.blank?
sp = Sponge.new
sp.timeout = 10

View File

@ -12,7 +12,7 @@ TWITTER_LIST = "users".freeze
# find the id of our list name
res = Twitter.oauth_request("/1.1/lists/list.json", :get)
our_list = res.find { |l| l["name"] == TWITTER_LIST }
if !our_list.present?
if our_list.blank?
raise "can't find list #{TWITTER_LIST.inspect} in #{res.inspect}"
end
list_id = our_list["id_str"]