VianetManagement/the-captain-ruby

View on GitHub

Showing 21 of 21 total issues

Assignment Branch Condition size for send_to_snowplow is too high. [36.07/18] (http://c2.com/cgi/wiki?AbcMetric)
Open

    def send_to_snowplow(params)
      snowplow_params = params.dup
      url = ENV.fetch("CAPTAIN_SNOWPLOW_URL", "sp.trustcaptain.com")
      schema = ENV.fetch("CAPTAIN_SNOWPLOW_SCHEMA", "")
      env = ENV.fetch("RAILS_ENV", "development")
Severity: Minor
Found in lib/the_captain/captain_client.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Perceived complexity for send_to_snowplow is too high. [9/7]
Open

    def send_to_snowplow(params)
      snowplow_params = params.dup
      url = ENV.fetch("CAPTAIN_SNOWPLOW_URL", "sp.trustcaptain.com")
      schema = ENV.fetch("CAPTAIN_SNOWPLOW_SCHEMA", "")
      env = ENV.fetch("RAILS_ENV", "development")
Severity: Minor
Found in lib/the_captain/captain_client.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Method symbolize_names has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def symbolize_names(object)
        case object
        when Hash
          {}.tap do |new_hash|
            object.each do |key, value|
Severity: Minor
Found in lib/the_captain/utility/helper.rb - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method to_s has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def to_s
        out_message = message
        out_message += "\n(Status: #{http_status})"            unless http_status.nil?
        out_message += "\nRaw request body: #{http_body}"      unless http_body.nil?
        out_message += "\nResponse Headers: #{http_headers}\n" unless http_headers.nil?
Severity: Minor
Found in lib/the_captain/error/standard_exception.rb - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method capture_response! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def capture_response!(retry_count = TheCaptain.retry_attempts)
      @response = yield
    rescue StandardError
      retry_count ||= 0
      (retry_count -= 1).positive? ? retry : raise
Severity: Minor
Found in lib/the_captain/captain_client.rb - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Line is too long. [134/120] (https://github.com/rubocop-hq/ruby-style-guide#80-character-limits)
Open

      emitter = SnowplowTracker::Emitter.new(endpoint: url, options: { method: 'post', protocol: 'https', port: 443, buffer_size: 1 })
Severity: Minor
Found in lib/the_captain/captain_client.rb by rubocop

This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/Tab cop.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. (https://github.com/rubocop-hq/ruby-style-guide#consistent-string-literals)
Open

      emitter = SnowplowTracker::Emitter.new(endpoint: url, options: { method: 'post', protocol: 'https', port: 443, buffer_size: 1 })
Severity: Minor
Found in lib/the_captain/captain_client.rb by rubocop

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Line is too long. [148/120] (https://github.com/rubocop-hq/ruby-style-guide#80-character-limits)
Open

      tracker = SnowplowTracker::Tracker.new(emitters: emitter, namespace: "roommates-captain-web", app_id: "roommates-#{env}", encode_base64: true)
Severity: Minor
Found in lib/the_captain/captain_client.rb by rubocop

This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/Tab cop.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. (https://github.com/rubocop-hq/ruby-style-guide#consistent-string-literals)
Open

      emitter = SnowplowTracker::Emitter.new(endpoint: url, options: { method: 'post', protocol: 'https', port: 443, buffer_size: 1 })
Severity: Minor
Found in lib/the_captain/captain_client.rb by rubocop

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Add an empty line after magic comments. (https://github.com/rubocop-hq/ruby-style-guide#separate-magic-comments-from-code)
Open

require "snowplow-tracker"
Severity: Minor
Found in lib/the_captain/captain_client.rb by rubocop

Checks for a newline after the final magic comment.

Example:

# good
# frozen_string_literal: true

# Some documentation for Person
class Person
  # Some code
end

# bad
# frozen_string_literal: true
# Some documentation for Person
class Person
  # Some code
end

Space inside { missing. (https://github.com/rubocop-hq/ruby-style-guide#spaces-operators)
Open

        Curl.post(url, {site: "roommates", user_id: user_id}.to_json) {|http|
Severity: Minor
Found in lib/the_captain/captain_client.rb by rubocop

Checks that braces used for hash literals have or don't have surrounding space depending on configuration.

Example: EnforcedStyle: space (default)

# The `space` style enforces that hash literals have
# surrounding space.

# bad
h = {a: 1, b: 2}

# good
h = { a: 1, b: 2 }

Example: EnforcedStyle: no_space

# The `no_space` style enforces that hash literals have
# no surrounding space.

# bad
h = { a: 1, b: 2 }

# good
h = {a: 1, b: 2}

Example: EnforcedStyle: compact

# The `compact` style normally requires a space inside
# hash braces, with the exception that successive left
# braces or right braces are collapsed together in nested hashes.

# bad
h = { a: { b: 2 } }

# good
h = { a: { b: 2 }}

Example: EnforcedStyleForEmptyBraces: no_space (default)

# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# empty hash braces do not contain spaces.

# bad
foo = { }
bar = {    }

# good
foo = {}
bar = {}

Example: EnforcedStyleForEmptyBraces: space

# The `space` EnforcedStyleForEmptyBraces style enforces that
# empty hash braces contain space.

# bad
foo = {}

# good
foo = { }
foo = {  }
foo = {     }

Line is too long. [149/120] (https://github.com/rubocop-hq/ruby-style-guide#80-character-limits)
Open

      tracker.set_ip_address(snowplow_params[:context][:ip_address]) if snowplow_params.key?(:context) && snowplow_params[:context].key?(:ip_address)
Severity: Minor
Found in lib/the_captain/captain_client.rb by rubocop

This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/Tab cop.

Avoid using {...} for multi-line blocks. (https://github.com/rubocop-hq/ruby-style-guide#single-line-blocks)
Open

        Curl.post(url, {site: "roommates", user_id: user_id}.to_json) {|http|
Severity: Minor
Found in lib/the_captain/captain_client.rb by rubocop

Check for uses of braces or do/end around single line or multi-line blocks.

Example: EnforcedStyle: linecountbased (default)

# bad - single line block
items.each do |item| item / 5 end

# good - single line block
items.each { |item| item / 5 }

# bad - multi-line block
things.map { |thing|
  something = thing.some_method
  process(something)
}

# good - multi-line block
things.map do |thing|
  something = thing.some_method
  process(something)
end

Example: EnforcedStyle: semantic

# Prefer `do...end` over `{...}` for procedural blocks.

# return value is used/assigned
# bad
foo = map do |x|
  x
end
puts (map do |x|
  x
end)

# return value is not used out of scope
# good
map do |x|
  x
end

# Prefer `{...}` over `do...end` for functional blocks.

# return value is not used out of scope
# bad
each { |x|
  x
}

# return value is used/assigned
# good
foo = map { |x|
  x
}
map { |x|
  x
}.inspect

Example: EnforcedStyle: bracesforchaining

# bad
words.each do |word|
  word.flip.flop
end.join("-")

# good
words.each { |word|
  word.flip.flop
}.join("-")

Line is too long. [121/120] (https://github.com/rubocop-hq/ruby-style-guide#80-character-limits)
Open

      tracker.set_user_id(snowplow_params[:user][:id]) if snowplow_params.key?(:user) && snowplow_params[:user].key?(:id)
Severity: Minor
Found in lib/the_captain/captain_client.rb by rubocop

This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/Tab cop.

Useless assignment to variable - res. (https://github.com/rubocop-hq/ruby-style-guide#underscore-unused-vars)
Open

      res = tracker.track_self_describing_event(event_json: self_desc_json)
Severity: Minor
Found in lib/the_captain/captain_client.rb by rubocop

This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Prefer the use of the nil? predicate. (https://github.com/rubocop-hq/ruby-style-guide#predicate-methods)
Open

      return if user_id == nil
Severity: Minor
Found in lib/the_captain/captain_client.rb by rubocop

This cop checks for comparison of something with nil using ==.

Example:

# bad
if x == nil
end

# good
if x.nil?
end

Line is too long. [159/120] (https://github.com/rubocop-hq/ruby-style-guide#80-character-limits)
Open

      tracker.set_fingerprint(snowplow_params[:user][:browser_fingerprint]) if snowplow_params.key?(:user) && snowplow_params[:user].key?(:browser_fingerprint)
Severity: Minor
Found in lib/the_captain/captain_client.rb by rubocop

This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/Tab cop.

Redundant else-clause.
Open

      else
Severity: Minor
Found in lib/the_captain/captain_client.rb by rubocop

Checks for empty else-clauses, possibly including comments and/or an explicit nil depending on the EnforcedStyle.

Example: EnforcedStyle: empty

# warn only on empty else

# bad
if condition
  statement
else
end

# good
if condition
  statement
else
  nil
end

# good
if condition
  statement
else
  statement
end

# good
if condition
  statement
end

Example: EnforcedStyle: nil

# warn on else with nil in it

# bad
if condition
  statement
else
  nil
end

# good
if condition
  statement
else
end

# good
if condition
  statement
else
  statement
end

# good
if condition
  statement
end

Example: EnforcedStyle: both (default)

# warn on empty else and else with nil in it

# bad
if condition
  statement
else
  nil
end

# bad
if condition
  statement
else
end

# good
if condition
  statement
else
  statement
end

# good
if condition
  statement
end

Space between { and | missing.
Open

        Curl.post(url, {site: "roommates", user_id: user_id}.to_json) {|http|
Severity: Minor
Found in lib/the_captain/captain_client.rb by rubocop

Checks that block braces have or don't have surrounding space inside them on configuration. For blocks taking parameters, it checks that the left brace has or doesn't have trailing space depending on configuration.

Example: EnforcedStyle: space (default)

# The `space` style enforces that block braces have
# surrounding space.

# bad
some_array.each {puts e}

# good
some_array.each { puts e }

Example: EnforcedStyle: no_space

# The `no_space` style enforces that block braces don't
# have surrounding space.

# bad
some_array.each { puts e }

# good
some_array.each {puts e}

Example: EnforcedStyleForEmptyBraces: no_space (default)

# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# block braces don't have a space in between when empty.

# bad
some_array.each {   }
some_array.each {  }
some_array.each { }

# good
some_array.each {}

Example: EnforcedStyleForEmptyBraces: space

# The `space` EnforcedStyleForEmptyBraces style enforces that
# block braces have at least a space in between when empty.

# bad
some_array.each {}

# good
some_array.each { }
some_array.each {  }
some_array.each {   }

Example: SpaceBeforeBlockParameters: true (default)

# The SpaceBeforeBlockParameters style set to `true` enforces that
# there is a space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.

# bad
[1, 2, 3].each {|n| n * 2 }

# good
[1, 2, 3].each { |n| n * 2 }

Example: SpaceBeforeBlockParameters: false

# The SpaceBeforeBlockParameters style set to `false` enforces that
# there is no space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.

# bad
[1, 2, 3].each { |n| n * 2 }

# good
[1, 2, 3].each {|n| n * 2 }

Line is too long. [148/120] (https://github.com/rubocop-hq/ruby-style-guide#80-character-limits)
Open

      tracker.set_useragent(snowplow_params[:context][:user_agent]) if snowplow_params.key?(:context) && snowplow_params[:context].key?(:user_agent)
Severity: Minor
Found in lib/the_captain/captain_client.rb by rubocop

This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/Tab cop.

Severity
Category
Status
Source
Language