Skip to content

Instantly share code, notes, and snippets.

@dannykopping
Created June 10, 2022 07:26
Show Gist options
  • Save dannykopping/6732dcda3d4f12a118752936196f4663 to your computer and use it in GitHub Desktop.
Save dannykopping/6732dcda3d4f12a118752936196f4663 to your computer and use it in GitHub Desktop.
# before
$ rubocop -c .rubocop.yml
Inspecting 7 files
..CCWC.
Offenses:
docker/Gemfile:6:1: C: [Correctable] Bundler/OrderedGems: Gems should be sorted in an alphabetical order within their section of the Gemfile. Gem fluentd should appear before fluent-plugin-multi-format-parser.
gem 'fluentd', '1.9.0'
^^^^^^^^^^^^^^^^^^^^^^
fluent-plugin-grafana-loki.gemspec:1:1: C: Gemspec/RequiredRubyVersion: required_ruby_version should be specified.
lib/fluent/plugin/out_loki.rb:84:7: C: Metrics/AbcSize: Assignment Branch Condition size for configure is too high. [<12, 41, 16> 45.62/35]
def configure(conf) # rubocop:disable Metrics/CyclomaticComplexity ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/fluent/plugin/out_loki.rb:84:7: C: Metrics/PerceivedComplexity: Perceived complexity for configure is too high. [16/8]
def configure(conf) # rubocop:disable Metrics/CyclomaticComplexity ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/fluent/plugin/out_loki.rb:87:26: C: [Correctable] Style/StringConcatenation: Prefer string interpolation to string concatenation.
@uri = URI.parse(@url + '/loki/api/v1/push')
^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/fluent/plugin/out_loki.rb:111:67: C: [Correctable] Style/IfUnlessModifier: Modifier form of if makes the line too long.
raise "bearer_token_file #{@bearer_token_file} not found" if !@bearer_token_file.nil? && !File.exist?(@bearer_token_file)
^^
lib/fluent/plugin/out_loki.rb:111:121: C: Layout/LineLength: Line is too long. [129/120]
raise "bearer_token_file #{@bearer_token_file} not found" if !@bearer_token_file.nil? && !File.exist?(@bearer_token_file)
^^^^^^^^^
lib/fluent/plugin/out_loki.rb:114:9: C: [Correctable] Style/NegatedIf: Favor unless over if for negative conditions.
if !@bearer_token_file.nil? ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/fluent/plugin/out_loki.rb:115:11: C: [Correctable] Style/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
if !File.exist?(@bearer_token_file)
^^
lib/fluent/plugin/out_loki.rb:115:11: C: [Correctable] Style/NegatedIf: Favor unless over if for negative conditions.
if !File.exist?(@bearer_token_file) ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/fluent/plugin/out_loki.rb:121:11: C: [Correctable] Style/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
if @auth_token_bearer.empty?
^^
lib/fluent/plugin/out_loki.rb:123:11: C: [Correctable] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
end
^^^
lib/fluent/plugin/out_loki.rb:127:1: C: [Correctable] Layout/EmptyLines: Extra blank line detected.
lib/fluent/plugin/out_loki.rb:207:9: C: [Correctable] Style/RedundantAssignment: Redundant assignment before returning detected.
payload = payload_builder(streams)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/fluent/plugin/out_loki.rb:218:9: C: [Correctable] Style/NegatedIf: Favor unless over if for negative conditions.
req.add_field('Authorization', "Bearer #{@auth_token_bearer}") if !@auth_token_bearer.nil?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/fluent/plugin/out_loki.rb:244:85: W: [Correctable] Lint/RedundantSafeNavigation: Redundant safe navigation detected.
data_labels.each { |k, v| formatted_labels[k] = v.gsub('"', '\\"') if v && v&.is_a?(String) }
^^^^^^^^^^^^^^^
lib/fluent/plugin/out_loki.rb:273:7: C: Metrics/CyclomaticComplexity: Cyclomatic complexity for record_to_line is too high. [9/7]
def record_to_line(record) ...
^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/fluent/plugin/out_loki.rb:273:7: C: Metrics/PerceivedComplexity: Perceived complexity for record_to_line is too high. [10/8]
def record_to_line(record) ...
^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/fluent/plugin/out_loki.rb:285:15: C: [Correctable] Style/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
if v.is_a?(String)
^^
lib/fluent/plugin/out_loki.rb:289:31: C: [Correctable] Style/RegexpLiteral: Use // around regular expression.
v = v.to_s.gsub(%r{(["\\])}, '\\\\\1')
^^^^^^^^^^^
lib/fluent/plugin/out_loki.rb:303:7: C: Metrics/CyclomaticComplexity: Cyclomatic complexity for line_to_loki is too high. [12/7]
def line_to_loki(record) ...
^^^^^^^^^^^^^^^^^^^^^^^^
lib/fluent/plugin/out_loki.rb:303:7: C: Metrics/PerceivedComplexity: Perceived complexity for line_to_loki is too high. [13/8]
def line_to_loki(record) ...
^^^^^^^^^^^^^^^^^^^^^^^^
lib/fluent/plugin/out_loki.rb:308:40: C: [Correctable] Style/RedundantRegexpEscape: Redundant escape inside regexp literal
new_key = name.gsub(%r{[.\-\/]}, '_')
^^
lib/fluent/plugin/out_loki.rb:315:13: C: [Correctable] Style/NegatedIf: Favor unless over if for negative conditions.
if !kubernetes_labels.nil? ...
^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/fluent/plugin/out_loki.rb:315:13: C: [Correctable] Style/SafeNavigation: Use safe navigation (&.) instead of checking if an object exists before calling the method.
if !kubernetes_labels.nil? ...
^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/fluent/plugin/out_loki.rb:317:41: C: [Correctable] Style/RedundantRegexpEscape: Redundant escape inside regexp literal
new_key = l.gsub(%r{[.\-\/]}, '_')
^^
spec/gems/fluent/plugin/loki_output_spec.rb:121:38: C: [Correctable] Layout/SpaceInsideHashLiteralBraces: Space inside { missing.
chunk = [Time.at(1_546_270_458), {'message'=>content, 'number': 1.2345, 'stream'=>'stdout'}]
^
spec/gems/fluent/plugin/loki_output_spec.rb:121:48: C: [Correctable] Layout/SpaceAroundOperators: Surrounding space missing for operator =>.
chunk = [Time.at(1_546_270_458), {'message'=>content, 'number': 1.2345, 'stream'=>'stdout'}]
^^
spec/gems/fluent/plugin/loki_output_spec.rb:121:85: C: [Correctable] Layout/SpaceAroundOperators: Surrounding space missing for operator =>.
chunk = [Time.at(1_546_270_458), {'message'=>content, 'number': 1.2345, 'stream'=>'stdout'}]
^^
spec/gems/fluent/plugin/loki_output_spec.rb:121:95: C: [Correctable] Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
chunk = [Time.at(1_546_270_458), {'message'=>content, 'number': 1.2345, 'stream'=>'stdout'}]
^
spec/gems/fluent/plugin/loki_output_spec.rb:125:46: C: [Correctable] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
expect(payload[0]['values'][0][0]).to eq "1546270458000000000"
^^^^^^^^^^^^^^^^^^^^^
spec/gems/fluent/plugin/loki_output_spec.rb:126:46: C: [Correctable] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
expect(payload[0]['values'][0][1]).to eq "message=\"? rest of line\" number=1.2345 stream=stdout"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/gems/fluent/plugin/loki_output_spec.rb:137:38: C: [Correctable] Layout/SpaceInsideHashLiteralBraces: Space inside { missing.
chunk = [Time.at(1_546_270_458), {'message'=>content, 'number': 1.2345, 'stream'=>'stdout'}]
^
spec/gems/fluent/plugin/loki_output_spec.rb:137:48: C: [Correctable] Layout/SpaceAroundOperators: Surrounding space missing for operator =>.
chunk = [Time.at(1_546_270_458), {'message'=>content, 'number': 1.2345, 'stream'=>'stdout'}]
^^
spec/gems/fluent/plugin/loki_output_spec.rb:137:85: C: [Correctable] Layout/SpaceAroundOperators: Surrounding space missing for operator =>.
chunk = [Time.at(1_546_270_458), {'message'=>content, 'number': 1.2345, 'stream'=>'stdout'}]
^^
spec/gems/fluent/plugin/loki_output_spec.rb:137:95: C: [Correctable] Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
chunk = [Time.at(1_546_270_458), {'message'=>content, 'number': 1.2345, 'stream'=>'stdout'}]
^
spec/gems/fluent/plugin/loki_output_spec.rb:141:46: C: [Correctable] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
expect(payload[0]['values'][0][0]).to eq "1546270458000000000"
^^^^^^^^^^^^^^^^^^^^^
spec/gems/fluent/plugin/loki_output_spec.rb:142:121: C: Layout/LineLength: Line is too long. [122/120]
expect(payload[0]['values'][0][1]).to eq "{\"message\":\"\xC1 rest of line\",\"number\":1.2345,\"stream\":\"stdout\"}"
^^
spec/gems/fluent/plugin/loki_output_spec.rb:158:53: C: [Correctable] Style/StringConcatenation: Prefer string interpolation to string concatenation.
expect(body[:streams][0]['values'][0][1]).to eq 'message="' + content[0] + '" stream=stdout'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7 files inspected, 39 offenses detected, 30 offenses autocorrectable
# after
$ rubocop -c .rubocop.yml
Inspecting 7 files
.......
7 files inspected, no offenses detected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment