Skip to content

Commit ba846e2

Browse files
authored
switch core to standard from rubocop (#4677)
1 parent 7e51f7a commit ba846e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+341
-330
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ AllCops:
3232
- lib/datadog/di/**/*
3333
- lib/datadog/di.rb
3434
- spec/datadog/di/**/*
35+
- lib/datadog/core/**/*
36+
- lib/datadog/core.rb
37+
- spec/datadog/core/**/*
3538
NewCops: disable # Don't allow new cops to be enabled implicitly.
3639
SuggestExtensions: false # Stop pushing suggestions constantly.
3740

.standard_todo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ignore:
3232
- ext/libdatadog_api/**/**
3333
- lib/*
3434
- lib/datadog/*
35-
- lib/datadog/core/**/**
35+
- lib/datadog/core/vendor/**/**
3636
- lib/datadog/kit/**/**
3737
- lib/datadog/opentelemetry/**/**
3838
- lib/datadog/tracing/**/**

lib/datadog/core/buffer/random.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def concat(items)
4040
add_all!(underflow) unless underflow.nil?
4141

4242
# Iteratively replace items, to ensure pseudo-random replacement.
43-
overflow.each { |item| replace!(item) } unless overflow.nil?
43+
overflow&.each { |item| replace!(item) }
4444
end
4545

4646
# Stored items are returned and the local buffer is reset.
@@ -78,7 +78,7 @@ def overflow_segments(items)
7878
underflow = nil
7979
overflow = nil
8080

81-
overflow_size = @max_size > 0 ? (@items.length + items.length) - @max_size : 0
81+
overflow_size = (@max_size > 0) ? (@items.length + items.length) - @max_size : 0
8282

8383
if overflow_size > 0
8484
# Items will overflow

lib/datadog/core/configuration.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,14 @@ def safely_synchronize
235235
end
236236

237237
COMPONENTS_WRITE_LOCK.synchronize do
238-
begin
239-
yield write_components
240-
rescue ThreadError => e
241-
logger_without_components.error(
242-
'Detected deadlock during datadog initialization. ' \
243-
'Please report this at https://github.com/datadog/dd-trace-rb/blob/master/CONTRIBUTING.md#found-a-bug' \
244-
"\n\tSource:\n\t#{Array(e.backtrace).join("\n\t")}"
245-
)
246-
nil
247-
end
238+
yield write_components
239+
rescue ThreadError => e
240+
logger_without_components.error(
241+
'Detected deadlock during datadog initialization. ' \
242+
'Please report this at https://github.com/datadog/dd-trace-rb/blob/master/CONTRIBUTING.md#found-a-bug' \
243+
"\n\tSource:\n\t#{Array(e.backtrace).join("\n\t")}"
244+
)
245+
nil
248246
end
249247
end
250248

lib/datadog/core/configuration/agent_settings_resolver.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def url
3737
case adapter
3838
when Datadog::Core::Configuration::Ext::Agent::HTTP::ADAPTER
3939
hostname = self.hostname
40-
hostname = "[#{hostname}]" if hostname =~ IPV6_REGEXP
41-
"#{ssl ? 'https' : 'http'}://#{hostname}:#{port}/"
40+
hostname = "[#{hostname}]" if IPV6_REGEXP.match?(hostname)
41+
"#{ssl ? "https" : "http"}://#{hostname}:#{port}/"
4242
when Datadog::Core::Configuration::Ext::Agent::UnixSocket::ADAPTER
4343
"unix://#{uds_path}"
4444
else
@@ -158,7 +158,7 @@ def configured_timeout_seconds
158158
value: settings.agent.timeout_seconds,
159159
),
160160
try_parsing_as_integer(
161-
friendly_name: "#{Datadog::Core::Configuration::Ext::Agent::ENV_DEFAULT_TIMEOUT_SECONDS} "\
161+
friendly_name: "#{Datadog::Core::Configuration::Ext::Agent::ENV_DEFAULT_TIMEOUT_SECONDS} " \
162162
'environment variable',
163163
value: ENV[Datadog::Core::Configuration::Ext::Agent::ENV_DEFAULT_TIMEOUT_SECONDS],
164164
)
@@ -338,13 +338,13 @@ def warn_if_configuration_mismatch(detected_configurations_in_priority_order)
338338
log_warning(
339339
'Configuration mismatch: values differ between ' \
340340
"#{detected_configurations_in_priority_order
341-
.map { |config| "#{config.friendly_name} (#{config.value.inspect})" }.join(' and ')}" \
341+
.map { |config| "#{config.friendly_name} (#{config.value.inspect})" }.join(" and ")}" \
342342
". Using #{detected_configurations_in_priority_order.first.value.inspect} and ignoring other configuration."
343343
)
344344
end
345345

346346
def log_warning(message)
347-
logger.warn(message) if logger
347+
logger&.warn(message)
348348
end
349349

350350
def http_scheme?(uri)

lib/datadog/core/configuration/components.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class << self
3030

3131
def build_health_metrics(settings, logger, telemetry)
3232
settings = settings.health_metrics
33-
options = { enabled: settings.enabled }
33+
options = {enabled: settings.enabled}
3434
options[:statsd] = settings.statsd unless settings.statsd.nil?
3535

3636
Core::Diagnostics::Health::Metrics.new(telemetry: telemetry, logger: logger, **options)
@@ -44,7 +44,7 @@ def build_logger(settings)
4444
end
4545

4646
def build_runtime_metrics(settings, logger, telemetry)
47-
options = { enabled: settings.runtime_metrics.enabled }
47+
options = {enabled: settings.runtime_metrics.enabled}
4848
options[:statsd] = settings.runtime_metrics.statsd unless settings.runtime_metrics.statsd.nil?
4949
options[:services] = [settings.service] unless settings.service.nil?
5050
options[:experimental_runtime_id_enabled] = settings.runtime_metrics.experimental_runtime_id_enabled
@@ -163,20 +163,20 @@ def startup!(settings, old_state: nil)
163163
# and avoid tearing down parts still in use.
164164
def shutdown!(replacement = nil)
165165
# Shutdown remote configuration
166-
remote.shutdown! if remote
166+
remote&.shutdown!
167167

168168
# Shutdown DI after remote, since remote config triggers DI operations.
169169
dynamic_instrumentation&.shutdown!
170170

171171
# Decommission AppSec
172-
appsec.shutdown! if appsec
172+
appsec&.shutdown!
173173

174174
# Shutdown the old tracer, unless it's still being used.
175175
# (e.g. a custom tracer instance passed in.)
176176
tracer.shutdown! unless replacement && tracer == replacement.tracer
177177

178178
# Shutdown old profiler
179-
profiler.shutdown! unless profiler.nil?
179+
profiler&.shutdown!
180180

181181
# Shutdown workers
182182
runtime_metrics.stop(true, close_metrics: false)
@@ -194,14 +194,14 @@ def shutdown!(replacement = nil)
194194
health_metrics.statsd
195195
].compact.uniq
196196

197-
new_statsd = if replacement
198-
[
199-
replacement.runtime_metrics.metrics.statsd,
200-
replacement.health_metrics.statsd
201-
].compact.uniq
202-
else
203-
[]
204-
end
197+
new_statsd = if replacement
198+
[
199+
replacement.runtime_metrics.metrics.statsd,
200+
replacement.health_metrics.statsd
201+
].compact.uniq
202+
else
203+
[]
204+
end
205205

206206
unused_statsd = (old_statsd - (old_statsd & new_statsd))
207207
unused_statsd.each(&:close)

lib/datadog/core/configuration/option.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ def get
142142

143143
def reset
144144
@value = if definition.resetter
145-
# Don't change @is_set to false; custom resetters are
146-
# responsible for changing @value back to a good state.
147-
# Setting @is_set = false would cause a default to be applied.
148-
context_exec(@value, &definition.resetter)
149-
else
150-
@is_set = false
151-
nil
152-
end
145+
# Don't change @is_set to false; custom resetters are
146+
# responsible for changing @value back to a good state.
147+
# Setting @is_set = false would cause a default to be applied.
148+
context_exec(@value, &definition.resetter)
149+
else
150+
@is_set = false
151+
nil
152+
end
153153

154154
# Reset back to the lowest precedence, to allow all `set`s to succeed right after a reset.
155155
@precedence_set = Precedence::DEFAULT
@@ -227,20 +227,20 @@ def validate_type(value)
227227

228228
unless valid_type
229229
raise_error = if @definition.type_options[:nilable]
230-
!value.is_a?(NilClass)
231-
else
232-
true
233-
end
230+
!value.is_a?(NilClass)
231+
else
232+
true
233+
end
234234
end
235235

236236
if raise_error
237237
error_msg = if @definition.type_options[:nilable]
238-
"The setting `#{@definition.name}` inside your app's `Datadog.configure` block expects a "\
239-
"#{@definition.type} or `nil`, but a `#{value.class}` was provided (#{value.inspect})."\
240-
else
241-
"The setting `#{@definition.name}` inside your app's `Datadog.configure` block expects a "\
242-
"#{@definition.type}, but a `#{value.class}` was provided (#{value.inspect})."\
243-
end
238+
"The setting `#{@definition.name}` inside your app's `Datadog.configure` block expects a " \
239+
"#{@definition.type} or `nil`, but a `#{value.class}` was provided (#{value.inspect})." \
240+
else
241+
"The setting `#{@definition.name}` inside your app's `Datadog.configure` block expects a " \
242+
"#{@definition.type}, but a `#{value.class}` was provided (#{value.inspect})." \
243+
end
244244

245245
error_msg = "#{error_msg} Please update your `configure` block. "
246246

lib/datadog/core/configuration/option_definition.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ def initialize(name, options = {})
7171
validate_options!
7272
end
7373

74-
def env(value)
74+
def env(value) # standard:disable Style/TrivialAccessors
7575
@env = value
7676
end
7777

78-
def deprecated_env(value)
78+
def deprecated_env(value) # standard:disable Style/TrivialAccessors
7979
@deprecated_env = value
8080
end
8181

@@ -111,7 +111,7 @@ def setter(&block)
111111

112112
def type(value, nilable: false)
113113
@type = value
114-
@type_options = { nilable: nilable }
114+
@type_options = {nilable: nilable}
115115

116116
value
117117
end
@@ -156,7 +156,7 @@ def validate_options!
156156
if !@default.nil? && @default_proc
157157
raise InvalidOptionError,
158158
'Using `default` and `default_proc` is not allowed. Please use one or the other.' \
159-
'If you want to store a block as the default value use `default_proc`'\
159+
'If you want to store a block as the default value use `default_proc`' \
160160
' otherwise use `default`'
161161
end
162162
end

lib/datadog/core/configuration/options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def self.included(base)
1818
module ClassMethods
1919
def options
2020
# Allows for class inheritance of option definitions
21-
@options ||= superclass <= Options ? superclass.options.dup : {}
21+
@options ||= (superclass <= Options) ? superclass.options.dup : {}
2222
end
2323

2424
protected

lib/datadog/core/configuration/settings.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module Core
1818
module Configuration
1919
# Global configuration settings for the Datadog library.
2020
# @public_api
21-
# rubocop:disable Metrics/BlockLength
21+
# standard:disable Metrics/BlockLength
2222
class Settings
2323
include Base
2424

@@ -123,7 +123,7 @@ def initialize(*_)
123123
# @return [Boolean]
124124
option :debug do |o|
125125
o.env [Datadog::Core::Configuration::Ext::Diagnostics::ENV_DEBUG_ENABLED,
126-
Datadog::Core::Configuration::Ext::Diagnostics::ENV_OTEL_LOG_LEVEL]
126+
Datadog::Core::Configuration::Ext::Diagnostics::ENV_OTEL_LOG_LEVEL]
127127
o.default false
128128
o.type :bool
129129
o.env_parser do |value|
@@ -137,7 +137,7 @@ def initialize(*_)
137137
o.after_set do |enabled|
138138
# Enable rich debug print statements.
139139
# We do not need to unnecessarily load 'pp' unless in debugging mode.
140-
require 'pp' if enabled
140+
require 'pp' if enabled # standard:disable Lint/RedundantRequireStatement
141141
end
142142
end
143143

@@ -454,7 +454,7 @@ def initialize(*_)
454454
o.after_set do |_, _, precedence|
455455
unless precedence == Datadog::Core::Configuration::Option::Precedence::DEFAULT
456456
Core.log_deprecation(key: :experimental_crash_tracking_enabled) do
457-
'The profiling.advanced.experimental_crash_tracking_enabled setting has been deprecated for removal '\
457+
'The profiling.advanced.experimental_crash_tracking_enabled setting has been deprecated for removal ' \
458458
'and no longer does anything. Please remove it from your Datadog.configure block.'
459459
end
460460
end
@@ -641,11 +641,11 @@ def initialize(*_)
641641
val ||= ''
642642
# maps OpenTelemetry semantic attributes to Datadog tags
643643
key = case key.downcase
644-
when 'deployment.environment' then 'env'
645-
when 'service.version' then 'version'
646-
when 'service.name' then 'service'
647-
else key
648-
end
644+
when 'deployment.environment' then 'env'
645+
when 'service.version' then 'version'
646+
when 'service.name' then 'service'
647+
else key
648+
end
649649
result[key] = val unless key.empty?
650650
end
651651
end
@@ -995,7 +995,7 @@ def initialize(*_)
995995
# Keep this extension here for now to keep things working.
996996
extend Datadog::Tracing::Configuration::Settings
997997
end
998-
# rubocop:enable Metrics/BlockLength
998+
# standard:enable Metrics/BlockLength
999999
end
10001000
end
10011001
end

lib/datadog/core/encoding.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def decode(obj)
5454
end
5555

5656
def join(encoded_data)
57-
"[#{encoded_data.join(',')}]"
57+
"[#{encoded_data.join(",")}]"
5858
end
5959
end
6060

lib/datadog/core/environment/cgroup.rb

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,18 @@ module Cgroup
2323

2424
def descriptors(process = 'self')
2525
[].tap do |descriptors|
26-
begin
27-
filepath = "/proc/#{process}/cgroup"
28-
29-
if File.exist?(filepath)
30-
File.foreach("/proc/#{process}/cgroup") do |line|
31-
line = line.strip
32-
descriptors << parse(line) unless line.empty?
33-
end
26+
filepath = "/proc/#{process}/cgroup"
27+
28+
if File.exist?(filepath)
29+
File.foreach("/proc/#{process}/cgroup") do |line|
30+
line = line.strip
31+
descriptors << parse(line) unless line.empty?
3432
end
35-
rescue StandardError => e
36-
Datadog.logger.error(
37-
"Error while parsing cgroup. Cause: #{e.class.name} #{e.message} Location: #{Array(e.backtrace).first}"
38-
)
3933
end
34+
rescue => e
35+
Datadog.logger.error(
36+
"Error while parsing cgroup. Cause: #{e.class.name} #{e.message} Location: #{Array(e.backtrace).first}"
37+
)
4038
end
4139
end
4240

0 commit comments

Comments
 (0)