Skip to content

Commit

Permalink
Fix cops
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Oct 7, 2024
1 parent bdb442a commit 8fa30a5
Show file tree
Hide file tree
Showing 74 changed files with 228 additions and 225 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
AllCops:
Exclude:
- lib/templates/**/*
# Omakase Ruby styling for Rails
inherit_gem: { rubocop-rails-omakase: rubocop.yml }
# Overwrite or add rules to create your own house style
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class StatsController < Admin::ApplicationController
# model - Model 名称
# by - day, week, month
def index
result = {model: params[:model]}
result = { model: params[:model] }
result[:count] = klass.unscoped.count
result[:week_count] = klass.unscoped.where("created_at >= ?", Date.today.beginning_of_week).count
result[:month_count] = klass.unscoped.where("created_at >= ?", Date.today.beginning_of_month).count
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/api/v3/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ class AccessDenied < StandardError; end
class PageNotFound < StandardError; end

rescue_from(ActionController::ParameterMissing) do |err|
render json: {error: "ParameterInvalid", message: err}, status: 400
render json: { error: "ParameterInvalid", message: err }, status: 400
end
rescue_from(ActiveRecord::RecordInvalid) do |err|
render json: {error: "RecordInvalid", message: err}, status: 400
render json: { error: "RecordInvalid", message: err }, status: 400
end
rescue_from(AccessDenied) do |err|
render json: {error: "AccessDenied", message: err}, status: 403
render json: { error: "AccessDenied", message: err }, status: 403
end
rescue_from(ActiveRecord::RecordNotFound) do
render json: {error: "ResourceNotFound"}, status: 404
render json: { error: "ResourceNotFound" }, status: 404
end

def requires!(name, opts = {})
Expand Down Expand Up @@ -77,7 +77,7 @@ def error!(data, status_code = 400)
end

def error_404!
error!({"error" => "Page not found"}, 404)
error!({ "error" => "Page not found" }, 404)
end

def current_user
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v3/devices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def create
@device.last_actived_at = Time.now
@device.save!

render json: {ok: 1}
render json: { ok: 1 }
end

# 删除 Device 信息,请注意在用户登出或删除应用的时候调用,以便能确保清理掉
Expand All @@ -38,7 +38,7 @@ def destroy
requires! :platform, type: String, values: %w[ios android]
requires! :token, type: String
current_user.devices.where(platform: params[:platform].downcase, token: params[:token]).delete_all
render json: {ok: 1}
render json: { ok: 1 }
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v3/likes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class LikesController < Api::V3::ApplicationController
def create
current_user.like(likeable)
likeable.reload
data = {obj_type: params[:obj_type], obj_id: likeable.id, count: likeable.likes_count}
data = { obj_type: params[:obj_type], obj_id: likeable.id, count: likeable.likes_count }
render json: data
end

Expand All @@ -33,7 +33,7 @@ def create
def destroy
current_user.unlike(likeable)
likeable.reload
data = {obj_type: params[:obj_type], obj_id: likeable.id, count: likeable.likes_count}
data = { obj_type: params[:obj_type], obj_id: likeable.id, count: likeable.likes_count }
render json: data
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v3/nodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class NodesController < Api::V3::ApplicationController
# @return [Array<NodeSerializer>]
def index
@nodes = Node.sorted.all
@meta = {total: Node.count}
@meta = { total: Node.count }
end

##
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/api/v3/notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ def read
ids = current_user.notifications.where(id: params[:ids]).pluck(:id)
Notification.read!(current_user, ids)

render json: {ok: 1}
render json: { ok: 1 }
end

# 删除当前用户的所有通知
#
# DELETE /api/v3/notifications/all
def all
current_user.notifications.delete_all
render json: {ok: 1}
render json: { ok: 1 }
end

# 获得未读通知数量
Expand All @@ -46,7 +46,7 @@ def all
# == returns
# - count [Integer] 消息数量
def unread_count
render json: {count: Notification.unread_count(current_user)}
render json: { count: Notification.unread_count(current_user) }
end

# 删除当前用户的某个通知
Expand All @@ -55,7 +55,7 @@ def unread_count
def destroy
@notification = current_user.notifications.find(params[:id])
@notification.destroy
render json: {ok: 1}
render json: { ok: 1 }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v3/replies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def destroy
raise AccessDenied unless can?(:destroy, @reply)

@reply.destroy
render json: {ok: 1}
render json: { ok: 1 }
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v3/root_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def not_found
def hello
optional! :limit, values: 0..100

@meta = {time: Time.now}
@meta = { time: Time.now }
@user = current_user

render "api/v3/users/show"
Expand Down
18 changes: 9 additions & 9 deletions app/controllers/api/v3/topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def index
# { followed: 'Is followed this Topic', liked: 'Is liked this Topic', favorited: 'Is favorited this Topic' }
# ```
def show
@meta = {followed: false, liked: false, favorited: false}
@meta = { followed: false, liked: false, favorited: false }

if current_user
current_user.touch_last_online_ts
Expand Down Expand Up @@ -129,7 +129,7 @@ def update
def destroy
raise AccessDenied unless can?(:destroy, @topic)
@topic.destroy_by(current_user)
render json: {ok: 1}
render json: { ok: 1 }
end

# 获取话题的回帖列表
Expand All @@ -150,7 +150,7 @@ def replies
@replies = Reply.unscoped.where(topic_id: @topic.id).order(:id).includes(:user)
@replies = @replies.offset(params[:offset].to_i).limit(params[:limit].to_i)
@user_liked_reply_ids = current_user&.like_reply_ids_by_replies(@replies) || []
@meta = {user_liked_reply_ids: @user_liked_reply_ids}
@meta = { user_liked_reply_ids: @user_liked_reply_ids }
end

# 创建对话题的回帖
Expand All @@ -177,31 +177,31 @@ def create_replies
# POST /api/v3/topics/:id/follow
def follow
current_user.follow_topic(@topic)
render json: {ok: 1}
render json: { ok: 1 }
end

# Unfollow Topic
#
# POST /api/v3/topics/:id/unfollow
def unfollow
current_user.unfollow_topic(@topic)
render json: {ok: 1}
render json: { ok: 1 }
end

# Favorite Topic
#
# POST /api/v3/topics/:id/favorite
def favorite
current_user.favorite_topic(@topic.id)
render json: {ok: 1}
render json: { ok: 1 }
end

# Unfovorite Topic
#
# POST /api/v3/topics/:id/unfavorite
def unfavorite
current_user.unfavorite_topic(@topic.id)
render json: {ok: 1}
render json: { ok: 1 }
end

# Ban Topic (Admin only)
Expand All @@ -211,7 +211,7 @@ def unfavorite
def ban
raise AccessDenied.new("The current user does not have the authority to block other people's topics.") unless can?(:ban, @topic)
@topic.ban!
render json: {ok: 1}
render json: { ok: 1 }
end

# Actions
Expand All @@ -236,7 +236,7 @@ def action
when "open"
@topic.open!
end
render json: {ok: 1}
render json: { ok: 1 }
end

private
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/api/v3/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def me
# GET /api/v3/users/:id
# @return [UserDetailSerializer]
def show
@meta = {followed: false, blocked: false}
@meta = { followed: false, blocked: false }

if current_user
@meta[:followed] = current_user.follow_user?(@user)
Expand Down Expand Up @@ -146,31 +146,31 @@ def blocked
# POST /api/v3/users/:id/follow
def follow
current_user.follow_user(@user)
render json: {ok: 1}
render json: { ok: 1 }
end

# Unfollow user
#
# POST /api/v3/users/:id/unfollow
def unfollow
current_user.unfollow_user(@user)
render json: {ok: 1}
render json: { ok: 1 }
end

# Block user
#
# POST /api/v3/users/:id/block
def block
current_user.block_user(@user.id)
render json: {ok: 1}
render json: { ok: 1 }
end

# Unblock user
#
# POST /api/v3/users/:id/unblock
def unblock
current_user.unblock_user(@user.id)
render json: {ok: 1}
render json: { ok: 1 }
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/nodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ def index

def block
current_user.block_node(params[:id])
render json: {code: 0}
render json: { code: 0 }
end

def unblock
current_user.unblock_node(params[:id])
render json: {code: 0}
render json: { code: 0 }
end
end
2 changes: 1 addition & 1 deletion app/controllers/notifications/notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def index

def read
Notification.read!(current_user, params[:ids])
render json: {ok: 1}
render json: { ok: 1 }
end

def clean
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/oauth/applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def update
else
respond_to do |format|
format.html { render :edit }
format.json { render json: {errors: @application.errors.full_messages}, status: :unprocessable_entity }
format.json { render json: { errors: @application.errors.full_messages }, status: :unprocessable_entity }
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/photos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ class PhotosController < ApplicationController

def create
if params[:file].blank?
render json: {ok: false}, status: 400
render json: { ok: false }, status: 400
return
end

# 浮动窗口上传
@photo = Photo.new(image: params[:file], user: current_user)
if @photo.save
render json: {ok: true, url: @photo.image.url(:large)}
render json: { ok: true, url: @photo.image.url(:large) }
else
render json: {ok: false, message: @photo.errors.full_messages.join}, status: 400
render json: { ok: false, message: @photo.errors.full_messages.join }, status: 400
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ def index

def users
@result = User.search(params[:q], user: current_user, limit: params[:limit] || 10)
render json: @result.collect { |u| {login: u.login, name: u.name, avatar_url: u.large_avatar_url} }
render json: @result.collect { |u| { login: u.login, name: u.name, avatar_url: u.large_avatar_url } }
end
end
2 changes: 1 addition & 1 deletion app/controllers/topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def show
def read
cookie_read_flag = "_topic_#{@topic.id}_read".to_sym
if cookies[cookie_read_flag].blank?
cookies[cookie_read_flag] = {value: "1", expires: 1.minutes}
cookies[cookie_read_flag] = { value: "1", expires: 1.minutes }
@topic.hits.incr(1)
end
current_user&.read_topic(@topic)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def create
yield resource if block_given?

if successfully_sent?(resource)
respond_with({}, {location: after_sending_reset_password_instructions_path_for(resource_name)})
respond_with({}, { location: after_sending_reset_password_instructions_path_for(resource_name) })
else
respond_with(resource)
end
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/users/user_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ def favorites

def block
current_user.block_user(@user.id)
render json: {code: 0}
render json: { code: 0 }
end

def unblock
current_user.unblock_user(@user.id)
render json: {code: 0}
render json: { code: 0 }
end

def blocked
Expand All @@ -44,12 +44,12 @@ def blocked

def follow
current_user.follow_user(@user)
render json: {code: 0, data: {followers_count: @user.reload.followers_count}}
render json: { code: 0, data: { followers_count: @user.reload.followers_count } }
end

def unfollow
current_user.unfollow_user(@user)
render json: {code: 0, data: {followers_count: @user.reload.followers_count}}
render json: { code: 0, data: { followers_count: @user.reload.followers_count } }
end

def followers
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 @@ -64,7 +64,7 @@ def insert_code_menu_items_tag
Setting.editor_languages.each do |lang|
lexer = Rouge::Lexer.find(lang)
if lexer
dropdown_items << link_to(lexer.title, "#", class: "dropdown-item", data: {lang: lang})
dropdown_items << link_to(lexer.title, "#", class: "dropdown-item", data: { lang: lang })
end
end
raw dropdown_items.join("")
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/notify_topic_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def perform(topic_id)
notified_user_ids = topic.mentioned_user_ids

# Send notification for followers
default_note = {notify_type: "topic", target_type: "Topic", target_id: topic.id, actor_id: topic.user_id, created_at: Time.now, updated_at: Time.now}
default_note = { notify_type: "topic", target_type: "Topic", target_id: topic.id, actor_id: topic.user_id, created_at: Time.now, updated_at: Time.now }

all_records = []
follower_ids.each do |uid|
Expand Down
Loading

0 comments on commit 8fa30a5

Please sign in to comment.