diff --git a/.rubocop.yml b/.rubocop.yml index 501c217172c..1ed0294bec8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -443,4 +443,4 @@ Style/WordArray: # `!!` is the de facto way in Ruby to cast an Object to boolean. Style/DoubleNegation: - Enabled: false \ No newline at end of file + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 90064a42cb0..07fef6aeb12 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -407,3 +407,7 @@ Style/FrozenStringLiteralComment: Metrics/BlockNesting: Exclude: - 'lib/datadog/appsec/configuration/settings.rb' + +Style/YodaCondition: + Exclude: + - 'spec/support/platform_helpers.rb' diff --git a/Gemfile b/Gemfile index cc56608b026..6f5671ebdf9 100644 --- a/Gemfile +++ b/Gemfile @@ -83,10 +83,12 @@ else end if RUBY_VERSION >= '2.6.0' - gem 'rubocop', '~> 1.34.0', require: false + # 1.50 is the last version to support Ruby 2.6 + gem 'rubocop', '~> 1.50.0', require: false gem 'rubocop-packaging', '~> 0.5.2', require: false gem 'rubocop-performance', '~> 1.9', require: false - gem 'rubocop-rspec', '~> 2.2', require: false + # 2.20 is the last version to support Ruby 2.6 + gem 'rubocop-rspec', ['~> 2.20', '< 2.21'], require: false end # Optional extensions diff --git a/lib/datadog/core/configuration/options.rb b/lib/datadog/core/configuration/options.rb index 0e106d10166..8e1c8772cdc 100644 --- a/lib/datadog/core/configuration/options.rb +++ b/lib/datadog/core/configuration/options.rb @@ -101,7 +101,7 @@ def options_hash end def reset_options! - options.values.each(&:reset) + options.each_value(&:reset) end private diff --git a/lib/datadog/core/configuration/settings.rb b/lib/datadog/core/configuration/settings.rb index 748ede56418..c1f124b9ec5 100644 --- a/lib/datadog/core/configuration/settings.rb +++ b/lib/datadog/core/configuration/settings.rb @@ -99,6 +99,7 @@ def initialize(*_) # Datadog features are sending to the Agent or backend. # @default `DD_TRACE_DEBUG` environment variable, otherwise `false` # @return [Boolean] + # rubocop:disable Lint/RedundantRequireStatement option :debug do |o| o.env Datadog::Core::Configuration::Ext::Diagnostics::ENV_DEBUG_ENABLED o.default false @@ -109,6 +110,7 @@ def initialize(*_) require 'pp' if enabled end end + # rubocop:enable Lint/RedundantRequireStatement # Internal {Datadog::Statsd} metrics collection. # diff --git a/lib/datadog/profiling.rb b/lib/datadog/profiling.rb index a16e857cea0..5266e42bb25 100644 --- a/lib/datadog/profiling.rb +++ b/lib/datadog/profiling.rb @@ -73,7 +73,7 @@ def self.enabled? end private_class_method def self.replace_noop_allocation_count - def self.allocation_count # rubocop:disable Lint/DuplicateMethods, Lint/NestedMethodDefinition (On purpose!) + def self.allocation_count # rubocop:disable Lint/NestedMethodDefinition (On purpose!) Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_allocation_count end end diff --git a/lib/datadog/tracing/contrib/utils/quantization/http.rb b/lib/datadog/tracing/contrib/utils/quantization/http.rb index 3e7d1196ee0..3e232421977 100644 --- a/lib/datadog/tracing/contrib/utils/quantization/http.rb +++ b/lib/datadog/tracing/contrib/utils/quantization/http.rb @@ -160,11 +160,11 @@ def obfuscate_query(query, options = {}) (?:"|%22) # closing '"' at end of value ) |(?: # other common secret values - bearer(?:\s|%20)+[a-z0-9._\-]+ + bearer(?:\s|%20)+[a-z0-9._-]+ |token(?::|%3A)[a-z0-9]{13} |gh[opsu]_[0-9a-zA-Z]{36} |ey[I-L](?:[\w=-]|%3D)+\.ey[I-L](?:[\w=-]|%3D)+(?:\.(?:[\w.+/=-]|%3D|%2F|%2B)+)? - |-{5}BEGIN(?:[a-z\s]|%20)+PRIVATE(?:\s|%20)KEY-{5}[^\-]+-{5}END(?:[a-z\s]|%20)+PRIVATE(?:\s|%20)KEY(?:-{5})?(?:\n|%0A)? + |-{5}BEGIN(?:[a-z\s]|%20)+PRIVATE(?:\s|%20)KEY-{5}[^-]+-{5}END(?:[a-z\s]|%20)+PRIVATE(?:\s|%20)KEY(?:-{5})?(?:\n|%0A)? |(?:ssh-(?:rsa|dss)|ecdsa-[a-z0-9]+-[a-z0-9]+)(?:\s|%20)*(?:[a-z0-9/.+]|%2F|%5C|%2B){100,}(?:=|%3D)*(?:(?:\s+)[a-z0-9._-]+)? ) }ix.freeze diff --git a/spec/datadog/appsec/remote_spec.rb b/spec/datadog/appsec/remote_spec.rb index f1305bd64a4..bfc329d16ce 100644 --- a/spec/datadog/appsec/remote_spec.rb +++ b/spec/datadog/appsec/remote_spec.rb @@ -404,9 +404,7 @@ context 'unsupported key' do let(:data) do { - 'unsupported' => { - - } + 'unsupported' => {} } end @@ -452,9 +450,7 @@ context 'without rules_data information' do let(:data) do { - 'other_key' => { - - } + 'other_key' => {} } end diff --git a/spec/datadog/profiling/integration_spec.rb b/spec/datadog/profiling/integration_spec.rb index 7494bbf2ce2..f9bdd67716f 100644 --- a/spec/datadog/profiling/integration_spec.rb +++ b/spec/datadog/profiling/integration_spec.rb @@ -255,9 +255,8 @@ def stack_frame_to_function_id(backtrace_location) is_expected.to have(4).items # All but last are unique - (0..-2).each do |i| + 3.times do |i| stack_sample = stack_samples[i] - expect(sample[i].to_h).to eq( location_id: stack_sample.frames.collect { |f| stack_frame_to_location_id(f) }, value: [stack_sample.cpu_time_interval_ns, stack_sample.wall_time_interval_ns], diff --git a/spec/datadog/tracing/contrib/aws/instrumentation_spec.rb b/spec/datadog/tracing/contrib/aws/instrumentation_spec.rb index 5a0b8e9c1f9..e105ec66dc4 100644 --- a/spec/datadog/tracing/contrib/aws/instrumentation_spec.rb +++ b/spec/datadog/tracing/contrib/aws/instrumentation_spec.rb @@ -454,9 +454,7 @@ end let(:responses) do - { create_topic: { - - } } + { create_topic: {} } end it_behaves_like 'schema version span' diff --git a/spec/datadog/tracing/contrib/rails/rails_active_job_spec.rb b/spec/datadog/tracing/contrib/rails/rails_active_job_spec.rb index f08977c51b4..82af5bfbc93 100644 --- a/spec/datadog/tracing/contrib/rails/rails_active_job_spec.rb +++ b/spec/datadog/tracing/contrib/rails/rails_active_job_spec.rb @@ -77,7 +77,7 @@ def perform(test_retry: false, test_discard: false) expect(span.name).to eq('active_job.enqueue') expect(span.resource).to eq('ExampleJob') expect(span.get_tag('active_job.adapter')).to eq('ActiveJob::QueueAdapters::InlineAdapter') - expect(span.get_tag('active_job.job.id')).to match(/[0-9a-f\-]{32}/) + expect(span.get_tag('active_job.job.id')).to match(/[0-9a-f-]{32}/) expect(span.get_tag('active_job.job.queue')).to eq('mice') expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)) .to eq('active_job') @@ -97,7 +97,7 @@ def perform(test_retry: false, test_discard: false) expect(span.name).to eq('active_job.enqueue') expect(span.resource).to eq('ExampleJob') expect(span.get_tag('active_job.adapter')).to eq('ActiveJob::QueueAdapters::InlineAdapter') - expect(span.get_tag('active_job.job.id')).to match(/[0-9a-f\-]{32}/) + expect(span.get_tag('active_job.job.id')).to match(/[0-9a-f-]{32}/) expect(span.get_tag('active_job.job.queue')).to eq('mice') expect(span.get_tag('active_job.job.scheduled_at').to_time).to be_within(1).of(scheduled_at) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)) @@ -117,7 +117,7 @@ def perform(test_retry: false, test_discard: false) expect(span.name).to eq('active_job.perform') expect(span.resource).to eq('ExampleJob') expect(span.get_tag('active_job.adapter')).to eq('ActiveJob::QueueAdapters::InlineAdapter') - expect(span.get_tag('active_job.job.id')).to match(/[0-9a-f\-]{32}/) + expect(span.get_tag('active_job.job.id')).to match(/[0-9a-f-]{32}/) expect(span.get_tag('active_job.job.queue')).to eq('elephants') expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)) .to eq('active_job') @@ -140,7 +140,7 @@ def perform(test_retry: false, test_discard: false) expect(enqueue_retry_span.name).to eq('active_job.enqueue_retry') expect(enqueue_retry_span.resource).to eq('ExampleJob') expect(enqueue_retry_span.get_tag('active_job.adapter')).to eq('ActiveJob::QueueAdapters::InlineAdapter') - expect(enqueue_retry_span.get_tag('active_job.job.id')).to match(/[0-9a-f\-]{32}/) + expect(enqueue_retry_span.get_tag('active_job.job.id')).to match(/[0-9a-f-]{32}/) expect(enqueue_retry_span.get_tag('active_job.job.queue')).to eq('elephants') expect(enqueue_retry_span.get_tag('active_job.job.error')).to eq('JobRetryError') expect(enqueue_retry_span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)) @@ -159,7 +159,7 @@ def perform(test_retry: false, test_discard: false) expect(retry_stopped_span.name).to eq('active_job.retry_stopped') expect(retry_stopped_span.resource).to eq('ExampleJob') expect(retry_stopped_span.get_tag('active_job.adapter')).to eq('ActiveJob::QueueAdapters::InlineAdapter') - expect(retry_stopped_span.get_tag('active_job.job.id')).to match(/[0-9a-f\-]{32}/) + expect(retry_stopped_span.get_tag('active_job.job.id')).to match(/[0-9a-f-]{32}/) expect(retry_stopped_span.get_tag('active_job.job.queue')).to eq('elephants') expect(retry_stopped_span.get_tag('active_job.job.error')).to eq('JobRetryError') expect(retry_stopped_span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)) @@ -183,7 +183,7 @@ def perform(test_retry: false, test_discard: false) expect(span.name).to eq('active_job.discard') expect(span.resource).to eq('ExampleJob') expect(span.get_tag('active_job.adapter')).to eq('ActiveJob::QueueAdapters::InlineAdapter') - expect(span.get_tag('active_job.job.id')).to match(/[0-9a-f\-]{32}/) + expect(span.get_tag('active_job.job.id')).to match(/[0-9a-f-]{32}/) expect(span.get_tag('active_job.job.queue')).to eq('elephants') expect(span.get_tag('active_job.job.error')).to eq('JobDiscardError') expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)) diff --git a/spec/support/platform_helpers.rb b/spec/support/platform_helpers.rb index 0c664fbdb28..590a332cbd9 100644 --- a/spec/support/platform_helpers.rb +++ b/spec/support/platform_helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'os' module PlatformHelpers @@ -6,15 +8,15 @@ module PlatformHelpers # Ruby runtime engines def mri? - RUBY_ENGINE == 'ruby'.freeze + RUBY_ENGINE == 'ruby' end def jruby? - RUBY_ENGINE == 'jruby'.freeze + RUBY_ENGINE == 'jruby' end def truffleruby? - RUBY_ENGINE == 'truffleruby'.freeze + RUBY_ENGINE == 'truffleruby' end def engine_version