mirror of
https://github.com/tildeverse/lobsters
synced 2024-06-19 15:17:03 +00:00
standardrb: standard-rails
This commit is contained in:
parent
c2935af068
commit
b3d6903f05
|
@ -2,3 +2,14 @@ ignore:
|
||||||
# it's mad about the class variables and I don't want to risk the refactor now
|
# it's mad about the class variables and I don't want to risk the refactor now
|
||||||
- 'extras/**/*':
|
- 'extras/**/*':
|
||||||
- Naming/VariableName
|
- 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
|
||||||
|
|
1
Gemfile
1
Gemfile
|
@ -55,6 +55,7 @@ group :test, :development do
|
||||||
gem "rspec-rails", "~> 6.0.0.rc1"
|
gem "rspec-rails", "~> 6.0.0.rc1"
|
||||||
gem "factory_bot_rails"
|
gem "factory_bot_rails"
|
||||||
gem "standard"
|
gem "standard"
|
||||||
|
gem "standard-rails"
|
||||||
gem "faker"
|
gem "faker"
|
||||||
gem "byebug"
|
gem "byebug"
|
||||||
gem "rb-readline"
|
gem "rb-readline"
|
||||||
|
|
|
@ -270,6 +270,10 @@ GEM
|
||||||
rubocop-performance (1.19.0)
|
rubocop-performance (1.19.0)
|
||||||
rubocop (>= 1.7.0, < 2.0)
|
rubocop (>= 1.7.0, < 2.0)
|
||||||
rubocop-ast (>= 0.4.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-progressbar (1.13.0)
|
||||||
ruby-rc4 (0.1.5)
|
ruby-rc4 (0.1.5)
|
||||||
scenic (1.7.0)
|
scenic (1.7.0)
|
||||||
|
@ -309,6 +313,9 @@ GEM
|
||||||
standard-performance (1.2.0)
|
standard-performance (1.2.0)
|
||||||
lint_roller (~> 1.1)
|
lint_roller (~> 1.1)
|
||||||
rubocop-performance (~> 1.19.0)
|
rubocop-performance (~> 1.19.0)
|
||||||
|
standard-rails (0.2.0)
|
||||||
|
lint_roller (~> 1.0)
|
||||||
|
rubocop-rails (~> 2.20.2)
|
||||||
svg-graph (2.2.2)
|
svg-graph (2.2.2)
|
||||||
thor (1.2.2)
|
thor (1.2.2)
|
||||||
timeout (0.4.0)
|
timeout (0.4.0)
|
||||||
|
@ -374,6 +381,7 @@ DEPENDENCIES
|
||||||
sprockets-rails (= 2.3.3)
|
sprockets-rails (= 2.3.3)
|
||||||
stackprof
|
stackprof
|
||||||
standard
|
standard
|
||||||
|
standard-rails
|
||||||
svg-graph
|
svg-graph
|
||||||
uglifier (>= 1.3.0)
|
uglifier (>= 1.3.0)
|
||||||
vcr
|
vcr
|
||||||
|
|
|
@ -50,7 +50,7 @@ class RepliesController < ApplicationController
|
||||||
# with the current user's vote added by StoriesController.load_user_votes
|
# with the current user's vote added by StoriesController.load_user_votes
|
||||||
def apply_current_vote
|
def apply_current_vote
|
||||||
@replies.each do |r|
|
@replies.each do |r|
|
||||||
next unless r.current_vote_vote.present?
|
next if r.current_vote_vote.blank?
|
||||||
r.comment.current_vote = {
|
r.comment.current_vote = {
|
||||||
vote: r.current_vote_vote,
|
vote: r.current_vote_vote,
|
||||||
reason: r.current_vote_reason.to_s
|
reason: r.current_vote_reason.to_s
|
||||||
|
|
|
@ -158,12 +158,12 @@ class SettingsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def pushover_callback
|
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"
|
flash[:error] = "No random token present in session"
|
||||||
return redirect_to "/settings"
|
return redirect_to "/settings"
|
||||||
end
|
end
|
||||||
|
|
||||||
if !params[:rand].to_s.present?
|
if params[:rand].to_s.blank?
|
||||||
flash[:error] = "No random token present in URL"
|
flash[:error] = "No random token present in URL"
|
||||||
return redirect_to "/settings"
|
return redirect_to "/settings"
|
||||||
end
|
end
|
||||||
|
@ -190,8 +190,8 @@ class SettingsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def github_callback
|
def github_callback
|
||||||
if !session[:github_state].present? ||
|
if session[:github_state].blank? ||
|
||||||
!params[:code].present? ||
|
params[:code].blank? ||
|
||||||
(params[:state].to_s != session[:github_state].to_s)
|
(params[:state].to_s != session[:github_state].to_s)
|
||||||
flash[:error] = "Invalid OAuth state"
|
flash[:error] = "Invalid OAuth state"
|
||||||
return redirect_to "/settings"
|
return redirect_to "/settings"
|
||||||
|
|
|
@ -35,7 +35,7 @@ class StoriesController < ApplicationController
|
||||||
|
|
||||||
update_story_attributes
|
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")
|
@story.errors.add(:moderation_reason, message: "is required")
|
||||||
return render action: "edit"
|
return render action: "edit"
|
||||||
end
|
end
|
||||||
|
@ -97,7 +97,7 @@ class StoriesController < ApplicationController
|
||||||
|
|
||||||
# ignore what the user brought unless we need it as a fallback
|
# ignore what the user brought unless we need it as a fallback
|
||||||
@story.title = sattrs[:title]
|
@story.title = sattrs[:title]
|
||||||
if !@story.title.present? && params[:title].present?
|
if @story.title.blank? && params[:title].present?
|
||||||
@story.title = params[:title]
|
@story.title = params[:title]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -367,7 +367,7 @@ class StoriesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_url_dupe
|
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 = Story.new(user: @user)
|
||||||
@story.attributes = story_params
|
@story.attributes = story_params
|
||||||
@story.already_posted_recently?
|
@story.already_posted_recently?
|
||||||
|
|
|
@ -97,7 +97,7 @@ class UsersController < ApplicationController
|
||||||
return redirect_to "/"
|
return redirect_to "/"
|
||||||
end
|
end
|
||||||
|
|
||||||
if !params[:reason].present?
|
if params[:reason].blank?
|
||||||
flash[:error] = "You must give a reason for the ban."
|
flash[:error] = "You must give a reason for the ban."
|
||||||
return redirect_to user_path(user: buser.username)
|
return redirect_to user_path(user: buser.username)
|
||||||
end
|
end
|
||||||
|
|
|
@ -75,8 +75,6 @@ class Comment < ApplicationRecord
|
||||||
SCORE_RANGE_TO_HIDE = (-2..4)
|
SCORE_RANGE_TO_HIDE = (-2..4)
|
||||||
|
|
||||||
validates :short_id, length: {maximum: 10}
|
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 :markeddown_comment, length: {maximum: 16_777_215}
|
||||||
validates :comment, presence: {with: true, message: "cannot be empty."}
|
validates :comment, presence: {with: true, message: "cannot be empty."}
|
||||||
|
|
||||||
|
@ -206,7 +204,7 @@ class Comment < ApplicationRecord
|
||||||
recent = Comment.where("created_at >= ?", delay.ago)
|
recent = Comment.where("created_at >= ?", delay.ago)
|
||||||
.find_by(user: user, thread_id: parent_comment.thread_id)
|
.find_by(user: user, thread_id: parent_comment.thread_id)
|
||||||
|
|
||||||
return false unless recent.present?
|
return false if recent.blank?
|
||||||
|
|
||||||
wait = ActionController::Base.helpers
|
wait = ActionController::Base.helpers
|
||||||
.distance_of_time_in_words(Time.now, (recent.created_at + delay))
|
.distance_of_time_in_words(Time.now, (recent.created_at + delay))
|
||||||
|
|
|
@ -4,7 +4,7 @@ class Hat < ApplicationRecord
|
||||||
|
|
||||||
after_create :log_moderation
|
after_create :log_moderation
|
||||||
|
|
||||||
validates :user, :granted_by_user, :hat, presence: true
|
validates :hat, presence: true
|
||||||
validates :hat, :link, length: {maximum: 255}
|
validates :hat, :link, length: {maximum: 255}
|
||||||
|
|
||||||
scope :active, -> { joins(:user).where(doffed_at: nil).merge(User.active) }
|
scope :active, -> { joins(:user).where(doffed_at: nil).merge(User.active) }
|
||||||
|
|
|
@ -2,8 +2,6 @@ class ReadRibbon < ApplicationRecord
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :story
|
belongs_to :story
|
||||||
|
|
||||||
validates :user, :story, presence: true
|
|
||||||
|
|
||||||
# don't add callbacks to this model; for performance the read tracking in
|
# don't add callbacks to this model; for performance the read tracking in
|
||||||
# StoriesController uses .bump and RepliesController uses update_all, etc.
|
# StoriesController uses .bump and RepliesController uses update_all, etc.
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ class ReplyingComment < ApplicationRecord
|
||||||
}
|
}
|
||||||
scope :unread_replies_for, ->(user_id) { for_user(user_id).where(is_unread: true) }
|
scope :unread_replies_for, ->(user_id) { for_user(user_id).where(is_unread: true) }
|
||||||
scope :comment_replies_for,
|
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") }
|
scope :story_replies_for, ->(user_id) { for_user(user_id).where("parent_comment_id is null") }
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
|
@ -243,7 +243,7 @@ class Story < ApplicationRecord
|
||||||
|
|
||||||
# doesn't include deleted/moderated/merged stories
|
# doesn't include deleted/moderated/merged stories
|
||||||
def similar_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")
|
@_similar_stories ||= Story.find_similar_by_url(url).order("id DESC")
|
||||||
# do not include this story itself or any story merged into it
|
# do not include this story itself or any story merged into it
|
||||||
|
@ -253,7 +253,7 @@ class Story < ApplicationRecord
|
||||||
end
|
end
|
||||||
# do not include the story this one is merged into
|
# do not include the story this one is merged into
|
||||||
if merged_story_id?
|
if merged_story_id?
|
||||||
@_similar_stories = @_similar_stories.where("id != ?", merged_story_id)
|
@_similar_stories = @_similar_stories.where.not(id: merged_story_id)
|
||||||
end
|
end
|
||||||
@_similar_stories
|
@_similar_stories
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,9 +54,7 @@ class Vote < ApplicationRecord
|
||||||
|
|
||||||
Vote.where(
|
Vote.where(
|
||||||
user_id: user_id, story_id: story_id
|
user_id: user_id, story_id: story_id
|
||||||
).where(
|
).where.not(comment_id: nil).find_each do |v|
|
||||||
"comment_id IS NOT NULL"
|
|
||||||
).find_each do |v|
|
|
||||||
votes[v.comment_id] = {vote: v.vote, reason: v.reason}
|
votes[v.comment_id] = {vote: v.vote, reason: v.reason}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ class EmailParser
|
||||||
rescue
|
rescue
|
||||||
end
|
end
|
||||||
|
|
||||||
elsif !email.content_type.to_s.present?
|
elsif email.content_type.to_s.blank?
|
||||||
# no content-type header, assume it's text/plain
|
# no content-type header, assume it's text/plain
|
||||||
@body = email.body.to_s
|
@body = email.body.to_s
|
||||||
end
|
end
|
||||||
|
|
|
@ -62,7 +62,7 @@ class Twitter
|
||||||
res = at.get("/1.1/account/verify_credentials.json")
|
res = at.get("/1.1/account/verify_credentials.json")
|
||||||
js = JSON.parse(res.body)
|
js = JSON.parse(res.body)
|
||||||
|
|
||||||
if !js["screen_name"].present?
|
if js["screen_name"].blank?
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ elsif !parser.parent
|
||||||
warn "no valid comment or story being replied to"
|
warn "no valid comment or story being replied to"
|
||||||
exit EX_NOUSER
|
exit EX_NOUSER
|
||||||
|
|
||||||
elsif !parser.body.present?
|
elsif parser.body.blank?
|
||||||
warn "no valid text/plain body found"
|
warn "no valid text/plain body found"
|
||||||
exit EX_UNAVAILABLE
|
exit EX_UNAVAILABLE
|
||||||
end
|
end
|
||||||
|
|
|
@ -77,7 +77,7 @@ if __FILE__ == $PROGRAM_NAME
|
||||||
# mark it done so we don't hit them again if we or they crash
|
# mark it done so we don't hit them again if we or they crash
|
||||||
Keystore.put(LAST_STORY_KEY, s.id)
|
Keystore.put(LAST_STORY_KEY, s.id)
|
||||||
|
|
||||||
next unless s.url.present?
|
next if s.url.blank?
|
||||||
|
|
||||||
sp = Sponge.new
|
sp = Sponge.new
|
||||||
sp.timeout = 10
|
sp.timeout = 10
|
||||||
|
|
|
@ -12,7 +12,7 @@ TWITTER_LIST = "users".freeze
|
||||||
# find the id of our list name
|
# find the id of our list name
|
||||||
res = Twitter.oauth_request("/1.1/lists/list.json", :get)
|
res = Twitter.oauth_request("/1.1/lists/list.json", :get)
|
||||||
our_list = res.find { |l| l["name"] == TWITTER_LIST }
|
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}"
|
raise "can't find list #{TWITTER_LIST.inspect} in #{res.inspect}"
|
||||||
end
|
end
|
||||||
list_id = our_list["id_str"]
|
list_id = our_list["id_str"]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user