Added rubocop-rails (#3059)

* Added rubocop-rails

* Update rubocop version in the CodeClimate config
This commit is contained in:
Anna Buianova 2019-06-06 16:47:57 +03:00 committed by Ben Halpern
parent 1ea1a30ca7
commit 0ecb937875
16 changed files with 39 additions and 33 deletions

View file

@ -2,7 +2,7 @@ version: "2"
plugins:
rubocop:
enabled: true
channel: rubocop-0-67
channel: rubocop-0-71
brakeman:
enabled: true
eslint:

View file

@ -2,6 +2,7 @@ inherit_from: .rubocop_todo.yml
require:
- rubocop-performance
- rubocop-rails
- rubocop-rspec
# our custom config

View file

@ -132,6 +132,7 @@ group :development, :test do
gem "rspec-rails", "~> 3.8" # rspec-rails is a testing framework for Rails 3+
gem "rubocop", "~> 0.71", require: false # Automatic Ruby code style checking tool
gem "rubocop-performance", "~> 1.0", require: false # A collection of RuboCop cops to check for performance optimizations in Ruby code
gem "rubocop-rails", "~> 2.0", require: false # Automatic Rails code style checking tool
gem "rubocop-rspec", "~> 1.33", require: false # Code style checking for RSpec files
gem "spring", "~> 2.0" # Preloads your application so things like console, rake and tests run faster
gem "spring-commands-rspec", "~> 1.0" # rspec command for spring

View file

@ -649,6 +649,9 @@ GEM
unicode-display_width (>= 1.4.0, < 1.7)
rubocop-performance (1.3.0)
rubocop (>= 0.68.0)
rubocop-rails (2.0.0)
rack (>= 2.0)
rubocop (>= 0.70.0)
rubocop-rspec (1.33.0)
rubocop (>= 0.60.0)
ruby-prof (0.17.0)
@ -924,6 +927,7 @@ DEPENDENCIES
rspec-retry (~> 0.6)
rubocop (~> 0.71)
rubocop-performance (~> 1.0)
rubocop-rails (~> 2.0)
rubocop-rspec (~> 1.33)
ruby-prof (~> 0.17)
rubyzip (~> 1.2)

View file

@ -5,7 +5,7 @@ module Api
def create
@user = valid_user
unless @user
render json: { message: "invalid_user" }, status: 422
render json: { message: "invalid_user" }, status: :unprocessable_entity
return
end
Rails.cache.delete "count_for_reactable-#{params[:reactable_type]}-#{params[:reactable_id]}"

View file

@ -27,7 +27,7 @@ class ApplicationController < ActionController::Base
respond_to do |format|
format.html { redirect_to "/enter" }
format.json { render json: { error: "Please sign in" }, status: 401 }
format.json { render json: { error: "Please sign in" }, status: :unauthorized }
end
end

View file

@ -47,7 +47,7 @@ class ChatChannelMembershipsController < ApplicationController
@chat_channel_membership.remove_from_index!
@chat_channel_membership.chat_channel.index!
@chat_channels_memberships = []
render json: { result: "left channel" }, status: 201
render json: { result: "left channel" }, status: :created
end
def permitted_params

View file

@ -26,7 +26,7 @@ class ChatChannelsController < ApplicationController
if @chat_channel.valid?
render json: { status: "success",
chat_channel: @chat_channel.to_json(only: %i[channel_name slug]) },
status: 200
status: :ok
else
render json: { errors: @chat_channel.errors.full_messages }
end
@ -39,7 +39,7 @@ class ChatChannelsController < ApplicationController
if @chat_channel.valid?
render json: { status: "success",
chat_channel: @chat_channel.to_json(only: %i[channel_name slug]) },
status: 200
status: :ok
else
render json: { errors: @chat_channel.errors.full_messages }
end
@ -52,7 +52,7 @@ class ChatChannelsController < ApplicationController
membership.update(last_opened_at: 1.second.from_now, has_unopened_messages: false)
@chat_channel.index!
membership.index!
render json: { status: "success", channel: params[:id] }, status: 200
render json: { status: "success", channel: params[:id] }, status: :ok
end
def moderate
@ -68,29 +68,29 @@ class ChatChannelsController < ApplicationController
Pusher.trigger(@chat_channel.pusher_channels,
"user-banned",
{ userId: banned_user.id }.to_json)
render json: { status: "success", message: "banned!" }, status: 200
render json: { status: "success", message: "banned!" }, status: :ok
else
render json: { status: "error", message: "username not found" }, status: 400
render json: { status: "error", message: "username not found" }, status: :bad_request
end
when "/unban"
banned_user = User.find_by(username: command[1])
if banned_user
banned_user.remove_role :banned
render json: { status: "success", message: "unbanned!" }, status: 200
render json: { status: "success", message: "unbanned!" }, status: :ok
else
render json: { status: "error", message: "username not found" }, status: 400
render json: { status: "error", message: "username not found" }, status: :bad_request
end
when "/clearchannel"
@chat_channel.clear_channel
render json: { status: "success", message: "cleared!" }, status: 200
render json: { status: "success", message: "cleared!" }, status: :ok
else
render json: { status: "error", message: "invalid command" }, status: 400
render json: { status: "error", message: "invalid command" }, status: :bad_request
end
end
def create_chat
chat_recipient = User.find(params[:user_id])
valid_listing = ClassifiedListing.where({ user_id: params[:user_id], contact_via_connect: true }).limit(1)
valid_listing = ClassifiedListing.where(user_id: params[:user_id], contact_via_connect: true).limit(1)
authorize ChatChannel
if chat_recipient.inbox_type == "open" || valid_listing.length == 1
chat = ChatChannel.create_with_users([current_user, chat_recipient], "direct")
@ -101,9 +101,9 @@ class ChatChannelsController < ApplicationController
user: current_user,
)
chat.messages.append(message)
render json: { status: "success", message: "chat channel created!" }, status: 200
render json: { status: "success", message: "chat channel created!" }, status: :ok
else
render json: { status: "error", message: "not allowed!" }, status: 400
render json: { status: "error", message: "not allowed!" }, status: :bad_request
end
end
@ -113,7 +113,7 @@ class ChatChannelsController < ApplicationController
chat_channel.status = "blocked"
chat_channel.save
chat_channel.chat_channel_memberships.map(&:remove_from_index!)
render json: { status: "success", message: "chat channel blocked" }, status: 200
render json: { status: "success", message: "chat channel blocked" }, status: :ok
end
private

View file

@ -143,7 +143,7 @@ class CommentsController < ApplicationController
processed_html = "<p>😔 There was a error in your markdown</p><hr><p>#{e}</p>"
end
respond_to do |format|
format.json { render json: { processed_html: processed_html }, status: 200 }
format.json { render json: { processed_html: processed_html }, status: :ok }
end
end

View file

@ -39,7 +39,7 @@ class ImageUploadsController < ApplicationController
end
respond_to do |format|
format.json { render json: { link: link }, status: 200 }
format.json { render json: { link: link }, status: :ok }
end
end
end

View file

@ -20,10 +20,10 @@ class MessagesController < ApplicationController
end
if success
render json: { status: "success", message: "Message created" }, status: 201
render json: { status: "success", message: "Message created" }, status: :created
else
error_message = "Message created but could not trigger Pusher"
render json: { status: "error", message: error_message }, status: 201
render json: { status: "error", message: error_message }, status: :created
end
else
render json: {
@ -33,7 +33,7 @@ class MessagesController < ApplicationController
message: @message.errors.full_messages,
type: "error"
}
}, status: 401
}, status: :unauthorized
end
end
@ -67,7 +67,7 @@ class MessagesController < ApplicationController
message: "You can not do that because you are banned",
type: "error"
}
}, status: 401
}, status: :unauthorized
end
end
end

View file

@ -8,7 +8,7 @@ class PushNotificationSubscriptionsController < ApplicationController
user_id: current_user.id,
notification_type: "browser",
)
render json: { status: "success", endpoint: @subscription.endpoint }, status: 201
render json: { status: "success", endpoint: @subscription.endpoint }, status: :created
end
private

View file

@ -16,7 +16,7 @@ class SocialPreviewsController < ApplicationController
end
format.png do
html = render_to_string(template, formats: :html, layout: false)
redirect_to HtmlCssToImage.fetch_url(html: html, css: PNG_CSS, google_fonts: "Roboto|Roboto+Condensed"), status: 302
redirect_to HtmlCssToImage.fetch_url(html: html, css: PNG_CSS, google_fonts: "Roboto|Roboto+Condensed"), status: :found
end
end
end
@ -30,7 +30,7 @@ class SocialPreviewsController < ApplicationController
end
format.png do
html = render_to_string(formats: :html, layout: false)
redirect_to HtmlCssToImage.fetch_url(html: html, css: PNG_CSS, google_fonts: "Roboto"), status: 302
redirect_to HtmlCssToImage.fetch_url(html: html, css: PNG_CSS, google_fonts: "Roboto"), status: :found
end
end
end
@ -44,7 +44,7 @@ class SocialPreviewsController < ApplicationController
end
format.png do
html = render_to_string("user", formats: :html, layout: false)
redirect_to HtmlCssToImage.fetch_url(html: html, css: PNG_CSS, google_fonts: "Roboto"), status: 302
redirect_to HtmlCssToImage.fetch_url(html: html, css: PNG_CSS, google_fonts: "Roboto"), status: :found
end
end
end
@ -58,7 +58,7 @@ class SocialPreviewsController < ApplicationController
end
format.png do
html = render_to_string(formats: :html, layout: false)
redirect_to HtmlCssToImage.fetch_url(html: html, css: PNG_CSS, google_fonts: "Roboto"), status: 302
redirect_to HtmlCssToImage.fetch_url(html: html, css: PNG_CSS, google_fonts: "Roboto"), status: :found
end
end
end

View file

@ -32,8 +32,8 @@ class StripeCancellationsController < ApplicationController
monthly_dues = event.data.object.items.data[0].plan.amount
user = User.where(stripe_id_code: stripe_id).first
MembershipService.new(customer, user, monthly_dues).unsubscribe_customer
render body: nil, status: 200
render body: nil, status: :ok
rescue Stripe::APIConnectionError, Stripe::StripeError
render body: nil, status: 400
render body: nil, status: :bad_request
end
end

View file

@ -5,12 +5,12 @@ class TwilioTokensController < ApplicationController
video_channel = params[:id].split("private-video-channel-")[1] if params[:id].start_with?("private-video-channel-")
unless video_channel
skip_authorization
render json: { status: "failure", token: @twilio_token }, status: 404
render json: { status: "failure", token: @twilio_token }, status: :not_found
return
end
@chat_channel = ChatChannel.find(video_channel.to_i)
authorize @chat_channel # show pundit method for chat_channel_policy works here, should always check though
@twilio_token = TwilioToken.new(current_user, params[:id]).get
render json: { status: "success", token: @twilio_token }, status: 200
render json: { status: "success", token: @twilio_token }, status: :ok
end
end

View file

@ -5,7 +5,7 @@ class VideoStatesController < ApplicationController
def create
unless valid_user
render json: { message: "invalid_user" }, status: 422
render json: { message: "invalid_user" }, status: :unprocessable_entity
return
end
begin