Skip to content

Commit

Permalink
chore: Implement shared RuboCop configuration (#1587)
Browse files Browse the repository at this point in the history
Mostly all gems and folders contains the same `.rubocop.yml` config file.
It requires mostly to touch and verify 36 files for changes.
Extract common cops and settings of rubocop to `contrib/rubocop.yml` and update all other to use it.
Most common Cops put in the file and remove duplications.

In an effort to streamline maintenance, a common configuration file, `contrib/rubocop.yml`, has been introduced.
The majority of gems and folders previously relied on individual `.rubocop.yml` files, leading to redundancy.
This change involves consolidating common Cops and settings in `contrib/rubocop.yml`,
thereby reducing the need for modifications across 36 files.
This modification enhances consistency and eliminates duplications in the RuboCop configurations.

Signed-off-by: Michael Nikitochkin <michael.nikitochkin@gmx.net>
Co-authored-by: Matthew Wear <matthew.wear@gmail.com>
  • Loading branch information
miry and mwear authored Mar 8, 2024
1 parent 94832be commit bffcb77
Show file tree
Hide file tree
Showing 34 changed files with 85 additions and 339 deletions.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace :each do
foreach_gem('bundle exec rake yard')
end

desc "Run rubocop in each gem"
task :rubocop do
foreach_gem('bundle exec rake rubocop')
end
Expand Down
23 changes: 1 addition & 22 deletions api/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
AllCops:
TargetRubyVersion: "3.0"
inherit_from: ../contrib/rubocop.yml

Lint/UnusedMethodArgument:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/LineLength:
Enabled: false
Metrics/MethodLength:
Max: 20
Metrics/ParameterLists:
Enabled: false
Naming/FileName:
Exclude:
- "lib/opentelemetry-api.rb"
Lint/MissingSuper:
Enabled: false
Lint/ConstantDefinitionInBlock:
Exclude:
- "test/**/*"
Style/StringConcatenation:
Exclude:
- "test/**/*"
Style/ModuleFunction:
Enabled: false
Style/ExplicitBlockArgument:
Enabled: false
2 changes: 1 addition & 1 deletion api/lib/opentelemetry/trace/trace_flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class << self
# @param [Integer] flags 8-bit byte of bit flags
# @return [TraceFlags]
def from_byte(flags)
flags = 0 unless flags & ~0xFF == 0 # rubocop:disable Style/NumericPredicate
flags = 0 unless flags & ~0xFF == 0

new(flags)
end
Expand Down
25 changes: 1 addition & 24 deletions common/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,11 @@
AllCops:
TargetRubyVersion: '3.0'
NewCops: disable
SuggestExtensions: false
inherit_from: ../contrib/rubocop.yml

Bundler/OrderedGems:
Exclude:
- gemfiles/**/*
Lint/UnusedMethodArgument:
Enabled: false
Lint/MissingSuper:
Enabled: false
Lint/ConstantDefinitionInBlock:
Exclude:
- "test/**/*"
Style/StringConcatenation:
Exclude:
- "test/**/*"
Metrics/AbcSize:
Enabled: false
Layout/LineLength:
Enabled: false
Metrics/MethodLength:
Max: 20
Metrics/ParameterLists:
Enabled: false
Style/FrozenStringLiteralComment:
Exclude:
- gemfiles/**/*
Style/ModuleFunction:
Enabled: false
Style/StringLiterals:
Exclude:
- gemfiles/**/*
Expand Down
32 changes: 32 additions & 0 deletions contrib/rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
AllCops:
NewCops: disable
SuggestExtensions: false
TargetRubyVersion: "3.0"
Exclude:
- "vendor/**/*"

Layout/LineLength:
Enabled: false

Lint/ConstantDefinitionInBlock:
Exclude:
- "test/**/*"
Lint/MissingSuper:
Enabled: false
Lint/UnusedMethodArgument:
Enabled: false

Metrics/AbcSize:
Enabled: false
Metrics/MethodLength:
Max: 21
Metrics/ParameterLists:
Enabled: false

Style/ModuleFunction:
Enabled: false
Style/NumericPredicate:
Enabled: false
Style/StringConcatenation:
Exclude:
- "test/**/*"
25 changes: 2 additions & 23 deletions exporter/jaeger/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,16 @@
inherit_from: ../../contrib/rubocop.yml

AllCops:
TargetRubyVersion: "3.0"
NewCops: disable
SuggestExtensions: false
Exclude:
- "thrift/**/*"
- "vendor/**/*"

Bundler/OrderedGems:
Exclude:
- gemfiles/**/*
Lint/UnusedMethodArgument:
Enabled: false
Lint/MissingSuper:
Enabled: false
Lint/ConstantDefinitionInBlock:
Exclude:
- "test/**/*"
Style/StringConcatenation:
Exclude:
- "test/**/*"
Metrics/AbcSize:
Enabled: false
Layout/LineLength:
Enabled: false
Metrics/MethodLength:
Max: 20
Metrics/ParameterLists:
Enabled: false
Style/FrozenStringLiteralComment:
Exclude:
- gemfiles/**/*
Style/ModuleFunction:
Enabled: false
Style/StringLiterals:
Exclude:
- gemfiles/**/*
Expand Down
16 changes: 4 additions & 12 deletions exporter/otlp-common/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
inherit_from: ../../contrib/rubocop.yml

AllCops:
TargetRubyVersion: "3.0"
Exclude:
- "lib/opentelemetry/proto/**/*"
- "vendor/**/*"

Lint/UnusedMethodArgument:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/LineLength:
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/ParameterLists:
Enabled: false

Naming/FileName:
Exclude:
- "lib/opentelemetry-exporter-otlp-common.rb"
Style/ModuleFunction:
Enabled: false
4 changes: 0 additions & 4 deletions exporter/otlp-common/test/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
inherit_from: ../.rubocop.yml

Metrics/AbcSize:
Enabled: false
Metrics/BlockLength:
Enabled: false
Metrics/LineLength:
Enabled: false
15 changes: 1 addition & 14 deletions exporter/otlp-grpc/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
AllCops:
TargetRubyVersion: "3.0"
inherit_from: ../../contrib/rubocop.yml

Lint/UnusedMethodArgument:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/LineLength:
Enabled: false
Metrics/MethodLength:
Max: 21
Metrics/ParameterLists:
Enabled: false
Naming/FileName:
Exclude:
- "lib/opentelemetry-exporter-otlp-grpc.rb"
Style/ModuleFunction:
Enabled: false
4 changes: 0 additions & 4 deletions exporter/otlp-grpc/test/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
inherit_from: ../.rubocop.yml

Metrics/AbcSize:
Enabled: false
Metrics/BlockLength:
Enabled: false
Metrics/LineLength:
Enabled: false
Style/MethodCallWithoutArgsParentheses:
Exclude:
- 'opentelemetry/exporter/otlp/grpc/exporter_test.rb'
Expand Down
15 changes: 2 additions & 13 deletions exporter/otlp-http/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
inherit_from: ../../contrib/rubocop.yml

AllCops:
TargetRubyVersion: "3.0"
Exclude:
- "lib/opentelemetry/proto/**/*"
- "vendor/**/*"

Lint/UnusedMethodArgument:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
Metrics/LineLength:
Enabled: false
Metrics/MethodLength:
Max: 21
Metrics/ParameterLists:
Enabled: false
Naming/FileName:
Exclude:
- "lib/opentelemetry-exporter-otlp-http.rb"
Style/ModuleFunction:
Enabled: false
4 changes: 0 additions & 4 deletions exporter/otlp-http/test/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
inherit_from: ../.rubocop.yml

Metrics/AbcSize:
Enabled: false
Metrics/BlockLength:
Enabled: false
Metrics/LineLength:
Enabled: false
Style/MethodCallWithoutArgsParentheses:
Exclude:
- 'opentelemetry/exporter/otlp/http/exporter_test.rb'
Expand Down
23 changes: 2 additions & 21 deletions exporter/otlp/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
inherit_from: ../../contrib/rubocop.yml

AllCops:
TargetRubyVersion: "3.0"
NewCops: disable
SuggestExtensions: false
Exclude:
- "lib/opentelemetry/proto/**/*"
- "vendor/**/*"

Bundler/OrderedGems:
Exclude:
- gemfiles/**/*
Lint/UnusedMethodArgument:
Enabled: false
Lint/MissingSuper:
Enabled: false
Lint/ConstantDefinitionInBlock:
Exclude:
- "test/**/*"
Style/StringConcatenation:
Exclude:
- "test/**/*"
Metrics/AbcSize:
Enabled: false
Layout/LineLength:
Enabled: false
Metrics/MethodLength:
Max: 20
Metrics/ParameterLists:
Enabled: false
Style/FrozenStringLiteralComment:
Exclude:
- gemfiles/**/*
Expand Down
2 changes: 1 addition & 1 deletion exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def measure_request_duration
end
end

def backoff?(retry_count:, reason:, retry_after: nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
def backoff?(retry_count:, reason:, retry_after: nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
@metrics_reporter.add_to_counter('otel.otlp_exporter.failure', labels: { 'reason' => reason })
return false if retry_count > RETRY_COUNT

Expand Down
15 changes: 3 additions & 12 deletions exporter/zipkin/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
inherit_from: .rubocop_todo.yml
inherit_from:
- ../../contrib/rubocop.yml
- .rubocop_todo.yml

AllCops:
TargetRubyVersion: "3.0"
Exclude:
- "thrift/**/*"
- "vendor/**/*"

Lint/UnusedMethodArgument:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/LineLength:
Enabled: false
Metrics/ModuleLength:
Max: 130
Metrics/MethodLength:
Expand All @@ -20,12 +15,8 @@ Metrics/PerceivedComplexity:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/ParameterLists:
Enabled: false
Naming/FileName:
Exclude:
- "lib/opentelemetry-exporter-zipkin.rb"
Style/ExplicitBlockArgument:
Enabled: false
Style/ModuleFunction:
Enabled: false
4 changes: 0 additions & 4 deletions exporter/zipkin/test/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
inherit_from: ../.rubocop.yml

Metrics/AbcSize:
Enabled: false
Metrics/BlockLength:
Enabled: false
Metrics/LineLength:
Enabled: false
16 changes: 2 additions & 14 deletions logs_api/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
# inherit_from: .rubocop_todo.yml
inherit_from: ../contrib/rubocop.yml

AllCops:
TargetRubyVersion: '3.0'

Lint/UnusedMethodArgument:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/LineLength:
Enabled: false
Metrics/MethodLength:
Max: 50
Metrics/PerceivedComplexity:
Max: 30
Metrics/CyclomaticComplexity:
Max: 20
Metrics/ParameterLists:
Enabled: false

Naming/FileName:
Exclude:
- "lib/opentelemetry-logs-api.rb"
Style/ModuleFunction:
Enabled: false
7 changes: 4 additions & 3 deletions logs_api/test/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
inherit_from: ../.rubocop.yml

Metrics/BlockLength:
Enabled: false
Metrics/LineLength:
Layout/LineLength:
Enabled: false

Metrics/AbcSize:
Enabled: false
Metrics/BlockLength:
Enabled: false
Loading

0 comments on commit bffcb77

Please sign in to comment.