Skip to content

Commit

Permalink
Routine rubocop fixes (#7356)
Browse files Browse the repository at this point in the history
* rubocop -a

* Fix stuff

* rubocop -a again

* autocorrect
  • Loading branch information
rhymes authored Apr 17, 2020
1 parent 2c99424 commit a289305
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 41 deletions.
12 changes: 12 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ Layout/MultilineMethodCallIndentation:
Enabled: true
EnforcedStyle: indented

Layout/SpaceAroundMethodCallOperator:
Description: 'Checks method call operators to not have spaces around them.'
Enabled: true

#################### Lint ##################################

Lint/AmbiguousBlockAssociation:
Expand Down Expand Up @@ -223,6 +227,12 @@ Style/Encoding:
Description: 'Use UTF-8 as the source file encoding.'
Enabled: false

Style/ExponentialNotation:
Description: 'When using exponential notation, favor a mantissa between 1 (inclusive) and 10 (exclusive).'
StyleGuide: '#exponential-notation'
Enabled: true
EnforcedStyle: scientific

Style/FrozenStringLiteralComment:
Description: >-
Add the frozen_string_literal comment to the top of files
Expand Down Expand Up @@ -383,7 +393,9 @@ RSpec/DescribeClass:
Enabled: true
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribeClass
Exclude:
- 'spec/requests/**/*'
- 'spec/system/**/*'
- 'spec/tasks/**/*'

RSpec/ExampleLength:
Description: Checks for long examples.
Expand Down
25 changes: 8 additions & 17 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Workaround for erb_lint warnings:
# https://github.com/openstreetmap/openstreetmap-website/issues/2472
require:
- rubocop-performance
Expand All @@ -7,27 +6,26 @@ require:

# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-04-10 18:48:51 +0200 using RuboCop version 0.81.0.
# on 2020-04-17 11:30:37 +0200 using RuboCop version 0.82.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 257
# Offense count: 260
# Configuration parameters: IgnoredMethods.
Metrics/AbcSize:
Max: 75

# Offense count: 7
# Offense count: 8
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 62
Max: 60

# Offense count: 11
# Offense count: 10
Performance/OpenStruct:
Exclude:
- 'app/black_box/google_analytics.rb'
- 'app/models/article.rb'
- 'app/models/organization.rb'
- 'app/services/aws/fake_client.rb'
Expand All @@ -36,21 +34,14 @@ Performance/OpenStruct:
- 'spec/models/github_repo_spec.rb'
- 'spec/requests/github_repos_spec.rb'

# Offense count: 3
RSpec/DescribeClass:
Exclude:
- 'spec/requests/api/v0/classified_listings_spec.rb'
- 'spec/system/user_logs_in_with_twitter_spec.rb'
- 'spec/tasks/broadcasts_spec.rb'

# Offense count: 2
# Configuration parameters: Max.
RSpec/ExampleLength:
Exclude:
- 'spec/models/comment_spec.rb'
- 'spec/requests/display_ad_events_spec.rb'

# Offense count: 762
# Offense count: 802
# Configuration parameters: AggregateFailuresByDefault.
RSpec/MultipleExpectations:
Max: 10
Expand All @@ -74,7 +65,7 @@ Rails/HelperInstanceVariable:
Exclude:
- 'app/helpers/application_helper.rb'

# Offense count: 12
# Offense count: 15
Rails/OutputSafety:
Exclude:
- 'app/helpers/application_helper.rb'
Expand Down Expand Up @@ -105,7 +96,7 @@ Style/SingleLineBlockParams:
Exclude:
- 'app/labor/markdown_fixer.rb'

# Offense count: 4684
# Offense count: 4879
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/video_chats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def show
private

def display_username
return "@#{params[:username]}" if params[:username] && Rails.env.development? #simpler solo testing in dev
return "@#{params[:username]}" if params[:username] && Rails.env.development? # simpler solo testing in dev

"@" + current_user.username
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/chat_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def group?
end

def private_org_channel?
channel_name.to_s.ends_with?(" private group chat") #e.g. @devteam private group chat
channel_name.to_s.ends_with?(" private group chat") # e.g. @devteam private group chat
end

def clear_channel
Expand Down
11 changes: 4 additions & 7 deletions app/models/organization_membership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@ def upsert_chat_channel_membership
role = type_of_user == "admin" ? "mod" : "member"
name = "@#{organization.slug} private group chat"
channel = ChatChannel.find_by(channel_name: name)
if channel
add_chat_channel_membership(user, channel, role)
else
# find_or_create_chat_channel is custom method in class, not generic rails method
channel = ChatChannel.find_or_create_chat_channel("invite_only", "#{organization.slug}-private-group-chat", name)
add_chat_channel_membership(user, channel, role)
end

channel ||= ChatChannel.find_or_create_chat_channel("invite_only", "#{organization.slug}-private-group-chat", name)

add_chat_channel_membership(user, channel, role)
end

def add_chat_channel_membership(user, channel, role)
Expand Down
6 changes: 3 additions & 3 deletions app/models/response_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class ResponseTemplate < ApplicationRecord
validate :user_nil_only_for_user_nil_types

def user_nil_only_for_user_nil_types
if user_id.present? && USER_NIL_TYPE_OF_TYPES.include?(type_of)
errors.add(:type_of, USER_NIL_TYPE_OF_MSG)
end
return unless user_id.present? && USER_NIL_TYPE_OF_TYPES.include?(type_of)

errors.add(:type_of, USER_NIL_TYPE_OF_MSG)
end
end
2 changes: 1 addition & 1 deletion spec/decorators/article_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def create_article(*args)
describe "#processed_canonical_url" do
it "strips canonical_url" do
article.canonical_url = " http://google.com "
expect(article.decorate.processed_canonical_url). to eq("http://google.com")
expect(article.decorate.processed_canonical_url).to eq("http://google.com")
end

it "returns the article url without a canonical_url" do
Expand Down
2 changes: 1 addition & 1 deletion spec/liquid_tags/codesandbox_tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def generate_tag(id)

it "rejects bad ids" do
bad_ids.each do |id|
expect { generate_tag(id) } .to raise_error(StandardError)
expect { generate_tag(id) }.to raise_error(StandardError)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/liquid_tags/gist_tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def generate_script(link, option = "")

it "rejects XSS attempts" do
bad_links.each do |link|
expect { generate_new_liquid(link) } .to raise_error(StandardError)
expect { generate_new_liquid(link) }.to raise_error(StandardError)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/liquid_tags/medium_tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ def generate_medium_tag(link)
end

it "raises an error when invalid" do
expect { generate_medium_tag("invalid link") }. to raise_error("Invalid link URL or link URL does not exist")
expect { generate_medium_tag("invalid link") }.to raise_error("Invalid link URL or link URL does not exist")
end
end
6 changes: 3 additions & 3 deletions spec/requests/api/v0/classified_listings_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

RSpec.describe "Api::V0::Listings" do
RSpec.describe "Api::V0::ClassifiedListings", type: :request do
shared_context "when user is authorized" do
let(:api_secret) { create(:api_secret) }
let(:user) { api_secret.user }
Expand Down Expand Up @@ -228,12 +228,12 @@ def post_classified_listing(key: api_secret.secret, **params)

it "fails with no api key" do
post api_classified_listings_path, headers: { "content-type" => "application/json" }
expect(response). to have_http_status(:unauthorized)
expect(response).to have_http_status(:unauthorized)
end

it "fails with the wrong api key" do
post api_classified_listings_path, headers: { "api-key" => "foobar", "content-type" => "application/json" }
expect(response). to have_http_status(:unauthorized)
expect(response).to have_http_status(:unauthorized)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/requests/internal/feedback_messages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:admin) { create(:user, :super_admin) }

describe "GET /internal/reports" do
let(:single_resource_admin) { create(:user, :single_resource_admin, resource: FeedbackMessage)}
let(:single_resource_admin) { create(:user, :single_resource_admin, resource: FeedbackMessage) }

context "when the user is a single resource admin" do
it "renders with status 200" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
it "tests JSON data" do
json = notification.json_data
expect(json["article"]["title"]).to start_with("Hello")
expect(json["adjustment_type"]). to eq "addition"
expect(json["adjustment_type"]).to eq "addition"
end

it "tests JSON data for removal" do
tag_adjustment.adjustment_type = "removal"
json = notification.json_data
expect(json["article"]["title"]).to start_with("Hello")
expect(json["adjustment_type"]). to eq "removal"
expect(json["adjustment_type"]).to eq "removal"
end

specify "notification to be inserted on DB" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
visit root_path
click_link sign_in_link

expect(page.current_path).to include("/onboarding")
expect(page).to have_current_path("/onboarding", ignore_query: true)
expect(page.html).to include("onboarding-container")
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/workers/reactions/update_reactable_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
it " doesn't fail if a reaction doesn't exist" do
expect do
worker.perform(Reaction.maximum(:id).to_i + 1)
end. not_to raise_error
end.not_to raise_error
end
end
end

0 comments on commit a289305

Please sign in to comment.