Skip to content

Commit

Permalink
Adopt rubocop and format the project (#2241)
Browse files Browse the repository at this point in the history
* Adopt rubocop and most of rubocop-rails-omakase's rules

* Format sentry-ruby

* Format sentry-rails

* Format sentry-sidekiq

* Format sentry-delayed_job

* Format sentry-opentelemetry

* Format sentry-resque

* Add a new job for running rubocop

* Apply some manual adjustments
  • Loading branch information
st0012 authored Feb 8, 2024
1 parent 3377a28 commit 2979e86
Show file tree
Hide file tree
Showing 91 changed files with 270 additions and 256 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Lint

on:
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true
- name: Run rubocop
run: bundle exec rubocop
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
inherit_gem:
rubocop-rails-omakase: rubocop.yml

Layout/SpaceInsideArrayLiteralBrackets:
Enabled: false

AllCops:
Exclude:
- 'sentry-raven/**/*'
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ end
# For RSpec
gem "rspec", "~> 3.0"
gem "rspec-retry"
gem 'simplecov'
gem "simplecov"
gem "simplecov-cobertura", "~> 1.4"
gem "rexml"

gem "rubocop-rails-omakase"
2 changes: 1 addition & 1 deletion sentry-delayed_job/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ RSpec::Core::RakeTask.new(:spec).tap do |task|
task.rspec_opts = "--order rand"
end

task :default => :spec
task default: :spec
3 changes: 2 additions & 1 deletion sentry-delayed_job/lib/sentry/delayed_job/plugin.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require "delayed_job"

module Sentry
Expand Down Expand Up @@ -55,7 +56,7 @@ def self.generate_contexts(job)
created_at: job.created_at,
last_error: job.last_error&.byteslice(0..1000),
handler: job.handler&.byteslice(0..1000),
job_class: compute_job_class(job.payload_object),
job_class: compute_job_class(job.payload_object)
}

if job.payload_object.respond_to?(:job_data)
Expand Down
1 change: 0 additions & 1 deletion sentry-delayed_job/spec/sentry/delayed_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ def perform
end

it 'returns the class name for anything else' do

expect(Sentry::DelayedJob::Plugin.compute_job_class("something")).to eq("String")
expect(Sentry::DelayedJob::Plugin.compute_job_class(Sentry::DelayedJob::Plugin)).to eq("Class")
end
Expand Down
2 changes: 1 addition & 1 deletion sentry-opentelemetry/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ RSpec::Core::RakeTask.new(:spec).tap do |task|
task.rspec_opts = "--order rand"
end

task :default => :spec
task default: :spec
18 changes: 9 additions & 9 deletions sentry-opentelemetry/lib/sentry/opentelemetry/propagator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
module Sentry
module OpenTelemetry
class Propagator

FIELDS = [SENTRY_TRACE_HEADER_NAME, BAGGAGE_HEADER_NAME].freeze

SENTRY_TRACE_KEY = ::OpenTelemetry::Context.create_key('sentry-trace')
Expand Down Expand Up @@ -51,14 +50,15 @@ def extract(

baggage_header = getter.get(carrier, BAGGAGE_HEADER_NAME)

baggage = if baggage_header && !baggage_header.empty?
Baggage.from_incoming_header(baggage_header)
else
# If there's an incoming sentry-trace but no incoming baggage header,
# for instance in traces coming from older SDKs,
# baggage will be empty and frozen and won't be populated as head SDK.
Baggage.new({})
end
baggage =
if baggage_header && !baggage_header.empty?
Baggage.from_incoming_header(baggage_header)
else
# If there's an incoming sentry-trace but no incoming baggage header,
# for instance in traces coming from older SDKs,
# baggage will be empty and frozen and won't be populated as head SDK.
Baggage.new({})
end

baggage.freeze!
context = context.set_value(SENTRY_BAGGAGE_KEY, baggage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SpanProcessor < ::OpenTelemetry::SDK::Trace::SpanProcessor
include Singleton

SEMANTIC_CONVENTIONS = ::OpenTelemetry::SemanticConventions::Trace
INTERNAL_SPAN_KINDS = %i(client internal)
INTERNAL_SPAN_KINDS = %i[client internal]

# The mapping from otel span ids to sentry spans
# @return [Hash]
Expand Down
2 changes: 1 addition & 1 deletion sentry-rails/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ task :isolated_specs do
end
end

task :default => [:spec, :isolated_specs]
task default: [:spec, :isolated_specs]
1 change: 0 additions & 1 deletion sentry-rails/app/jobs/sentry/send_event_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ module Sentry
class SendEventJob; end
end
end

1 change: 0 additions & 1 deletion sentry-rails/benchmarks/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ def create_app(&block)
session.extend(app.routes.url_helpers)
session.extend(app.routes.mounted_helpers)
end

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ def index
end

def report_demo
render(:status => 500)
render(status: 500)
end
end
2 changes: 0 additions & 2 deletions sentry-rails/examples/rails-5.2/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2021_01_12_160711) do

create_table "posts", force: :cascade do |t|
t.string "title"
t.text "content"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

end
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def job_error

def report_demo
# @sentry_event_id = Raven.last_event_id
render(:status => 500)
render(status: 500)
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

config.cache_classes = false

# Do not eager load code on boot. This avoids loading your whole application
Expand Down
4 changes: 2 additions & 2 deletions sentry-rails/examples/rails-6.0/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Rails.application.routes.draw do
resources :posts
get '500', :to => 'welcome#report_demo'
get '500', to: 'welcome#report_demo'
root to: "welcome#index"

get 'appearance', to: 'welcome#appearance'
Expand All @@ -16,5 +16,5 @@
require 'sidekiq/web'

mount Sidekiq::Web => '/sidekiq'
mount Resque::Server.new, :at => "/resque"
mount Resque::Server.new, at: "/resque"
end
1 change: 0 additions & 1 deletion sentry-rails/examples/rails-6.0/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2021_12_19_212232) do

create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def job_error

def report_demo
# @sentry_event_id = Raven.last_event_id
render(:status => 500)
render(status: 500)
end

private
Expand Down
4 changes: 2 additions & 2 deletions sentry-rails/examples/rails-7.0/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Rails.application.routes.draw do
resources :posts
get '500', :to => 'welcome#report_demo'
get '500', to: 'welcome#report_demo'
root to: "welcome#index"

get 'appearance', to: 'welcome#appearance'
Expand All @@ -16,5 +16,5 @@
require 'sidekiq/web'

mount Sidekiq::Web => '/sidekiq'
mount Resque::Server.new, :at => "/resque"
mount Resque::Server.new, at: "/resque"
end
1 change: 0 additions & 1 deletion sentry-rails/examples/rails-7.0/db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sentry-rails/lib/sentry/rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module Rails
"service_url.active_storage" => %i[service key url],
"service_update_metadata.active_storage" => %i[service key],
"preview.active_storage" => %i[key],
"analyze.active_storage" => %i[analyzer],
"analyze.active_storage" => %i[analyzer]
}.freeze

class Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module Sentry
module Rails
module Tracing
class AbstractSubscriber

class << self
def subscribe!
raise NotImplementedError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ def self.subscribe!

next unless connection

db_config = if connection.pool.respond_to?(:db_config)
connection.pool.db_config.configuration_hash
elsif connection.pool.respond_to?(:spec)
connection.pool.spec.config
end
db_config =
if connection.pool.respond_to?(:db_config)
connection.pool.db_config.configuration_hash
elsif connection.pool.respond_to?(:spec)
connection.pool.spec.config
end

next unless db_config

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Sentry
module Rails
module Tracing
class ActiveStorageSubscriber < AbstractSubscriber
EVENT_NAMES = %w(
EVENT_NAMES = %w[
service_upload.active_storage
service_download.active_storage
service_streaming_download.active_storage
Expand All @@ -17,7 +17,7 @@ class ActiveStorageSubscriber < AbstractSubscriber
service_update_metadata.active_storage
preview.active_storage
analyze.active_storage
).freeze
].freeze

def self.subscribe!
subscribe_to_event(EVENT_NAMES) do |event_name, duration, payload|
Expand Down
22 changes: 11 additions & 11 deletions sentry-rails/spec/dummy/test_rails_app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ class TestApp < Rails::Application

FILE_NAME =
case Gem::Version.new(Rails.version)
when -> (v) { v < v5_2 }
when ->(v) { v < v5_2 }
"5-0"
when -> (v) { v.between?(v5_2, v6_0) }
when ->(v) { v.between?(v5_2, v6_0) }
"5-2"
when -> (v) { v.between?(v6_0, v6_1) }
when ->(v) { v.between?(v6_0, v6_1) }
"6-0"
when -> (v) { v.between?(v6_1, v7_0) }
when ->(v) { v.between?(v6_1, v7_0) }
"6-1"
when -> (v) { v > v7_0 && v < v7_1 }
when ->(v) { v > v7_0 && v < v7_1 }
"7-0"
when -> (v) { v >= v7_1 }
when ->(v) { v >= v7_1 }
"7-1"
end

Expand All @@ -60,10 +60,10 @@ def self.name
configure_app(app)

app.routes.append do
get "/exception", :to => "hello#exception"
get "/view_exception", :to => "hello#view_exception"
get "/view", :to => "hello#view"
get "/not_found", :to => "hello#not_found"
get "/exception", to: "hello#exception"
get "/view_exception", to: "hello#view_exception"
get "/view", to: "hello#view"
get "/not_found", to: "hello#not_found"
get "/world", to: "hello#world"
get "/with_custom_instrumentation", to: "hello#with_custom_instrumentation"
resources :posts, only: [:index, :show] do
Expand All @@ -72,7 +72,7 @@ def self.name
end
end
get "500", to: "hello#reporting"
root :to => "hello#world"
root to: "hello#world"
end

app.initializer :configure_sentry do
Expand Down
2 changes: 1 addition & 1 deletion sentry-rails/spec/dummy/test_rails_app/apps/5-0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def view
end

def world
render :plain => "Hello World!"
render plain: "Hello World!"
end

def with_custom_instrumentation
Expand Down
4 changes: 2 additions & 2 deletions sentry-rails/spec/dummy/test_rails_app/apps/5-2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def attach

attach_params = {
io: File.open(File.join(Rails.root, 'public', 'sentry-logo.png')),
filename: 'sentry-logo.png',
filename: 'sentry-logo.png'
}

p.cover.attach(attach_params)
Expand All @@ -88,7 +88,7 @@ def view
end

def world
render :plain => "Hello World!"
render plain: "Hello World!"
end

def with_custom_instrumentation
Expand Down
4 changes: 2 additions & 2 deletions sentry-rails/spec/dummy/test_rails_app/apps/6-0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def attach

attach_params = {
io: File.open(File.join(Rails.root, 'public', 'sentry-logo.png')),
filename: 'sentry-logo.png',
filename: 'sentry-logo.png'
}

p.cover.attach(attach_params)
Expand All @@ -88,7 +88,7 @@ def view
end

def world
render :plain => "Hello World!"
render plain: "Hello World!"
end

def with_custom_instrumentation
Expand Down
2 changes: 1 addition & 1 deletion sentry-rails/spec/dummy/test_rails_app/apps/6-1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def view
end

def world
render :plain => "Hello World!"
render plain: "Hello World!"
end

def with_custom_instrumentation
Expand Down
2 changes: 1 addition & 1 deletion sentry-rails/spec/dummy/test_rails_app/apps/7-0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def view
end

def world
render :plain => "Hello World!"
render plain: "Hello World!"
end

def with_custom_instrumentation
Expand Down
2 changes: 1 addition & 1 deletion sentry-rails/spec/dummy/test_rails_app/apps/7-1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def view
end

def world
render :plain => "Hello World!"
render plain: "Hello World!"
end

def with_custom_instrumentation
Expand Down
Loading

0 comments on commit 2979e86

Please sign in to comment.