cloudinsight/opentsdb-ruby

View on GitHub

Showing 37 of 37 total issues

Assignment Branch Condition size for parse_rate is too high. [24.1/15]
Open

      def parse_rate(spec)
        return QueryRateOptions.default if spec.size == 4
        raise QueryErrors::InvalidRateOptionError, "invalid specification: #{spec}" if spec.size < 6
        parts = split_for(spec[5..-1], ',')
        if parts.empty? || parts.size > 3
Severity: Minor
Found in lib/opentsdb/query_parser.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

Method has too many lines. [17/10]
Open

      def split_for(string, token = ':')
        result = []
        index = start = pos = 0
        is_in_bracket = false
        string.each_char do |char|
Severity: Minor
Found in lib/opentsdb/query_parser.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for query is too high. [21.24/15]
Open

    def query
      [].tap do |results|
        query_commads.each do |query_commad|
          start = Time.now
          Opentsdb.logger.debug "[OpenTSDB] query: #{query_commad.to_json}"
Severity: Minor
Found in lib/opentsdb/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

Assignment Branch Condition size for parse_metric is too high. [19.34/15]
Open

      def parse_metric(metric)
        start_index = metric.index('{')
        return { metric: metric } unless start_index
        {}.tap do |h|
          h[:metric] = metric[0...start_index]
Severity: Minor
Found in lib/opentsdb/query_parser.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

Method has too many lines. [14/10]
Open

      def parse(q_string)
        parts = split_for(q_string, ':')
        return nil if parts.size < 2 || parts.size > 3
        metric_query = {}
        metric_query[:aggregator] = parts[0]
Severity: Minor
Found in lib/opentsdb/query_parser.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for parse is too high. [18.57/15]
Open

      def parse(q_string)
        parts = split_for(q_string, ':')
        return nil if parts.size < 2 || parts.size > 3
        metric_query = {}
        metric_query[:aggregator] = parts[0]
Severity: Minor
Found in lib/opentsdb/query_parser.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

Method has too many lines. [13/10]
Open

    def auto_detect_adapter
      if defined?(::Patron)
        :partron
      elsif defined?(::Excon) && defined?(::Excon::VERSION)
        :excon
Severity: Minor
Found in lib/opentsdb/faraday.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for split_for is too high. [17.12/15]
Open

      def split_for(string, token = ':')
        result = []
        index = start = pos = 0
        is_in_bracket = false
        string.each_char do |char|
Severity: Minor
Found in lib/opentsdb/query_parser.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

Method has too many lines. [12/10]
Open

      def parse_metric(metric)
        start_index = metric.index('{')
        return { metric: metric } unless start_index
        {}.tap do |h|
          h[:metric] = metric[0...start_index]
Severity: Minor
Found in lib/opentsdb/query_parser.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Cyclomatic complexity for auto_detect_adapter is too high. [7/6]
Open

    def auto_detect_adapter
      if defined?(::Patron)
        :partron
      elsif defined?(::Excon) && defined?(::Excon::VERSION)
        :excon
Severity: Minor
Found in lib/opentsdb/faraday.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Method has too many lines. [11/10]
Open

      def parse_tags(tags)
        return if tags.nil?
        over_tags = Hash.new { |h, k| h[k] = [] }
        excluding_tags = Hash.new { |h, k| h[k] = [] }
        split_for(tags, ',').each do |tag|
Severity: Minor
Found in lib/opentsdb/query_parser.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Cyclomatic complexity for parse_rate is too high. [7/6]
Open

      def parse_rate(spec)
        return QueryRateOptions.default if spec.size == 4
        raise QueryErrors::InvalidRateOptionError, "invalid specification: #{spec}" if spec.size < 6
        parts = split_for(spec[5..-1], ',')
        if parts.empty? || parts.size > 3
Severity: Minor
Found in lib/opentsdb/query_parser.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Method has too many lines. [11/10]
Open

    def query
      [].tap do |results|
        query_commads.each do |query_commad|
          start = Time.now
          Opentsdb.logger.debug "[OpenTSDB] query: #{query_commad.to_json}"
Severity: Minor
Found in lib/opentsdb/client.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Perceived complexity for auto_detect_adapter is too high. [8/7]
Open

    def auto_detect_adapter
      if defined?(::Patron)
        :partron
      elsif defined?(::Excon) && defined?(::Excon::VERSION)
        :excon
Severity: Minor
Found in lib/opentsdb/faraday.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

Assignment Branch Condition size for parse_queries is too high. [15.52/15]
Open

    def parse_queries
      [].tap do |qs|
        query_options[:q].split(';').each do |q|
          query = QueryParser.parse(q)
          query.interval   = query_options[:interval]
Severity: Minor
Found in lib/opentsdb/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

Method parse_rate has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

      def parse_rate(spec)
        return QueryRateOptions.default if spec.size == 4
        raise QueryErrors::InvalidRateOptionError, "invalid specification: #{spec}" if spec.size < 6
        parts = split_for(spec[5..-1], ',')
        if parts.empty? || parts.size > 3
Severity: Minor
Found in lib/opentsdb/query_parser.rb - About 45 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 parse has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

      def parse(q_string)
        parts = split_for(q_string, ':')
        return nil if parts.size < 2 || parts.size > 3
        metric_query = {}
        metric_query[:aggregator] = parts[0]
Severity: Minor
Found in lib/opentsdb/query_parser.rb - About 45 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_query_tags has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def to_query_tags
      {}.tap do |qtags|
        tags.each do |tagk, tagv|
          qtags[tagk] = tagv.to_a.compact.join('|') if tagv.is_a?(Array) || tagv.is_a?(Set)
          qtags[tagk] = '*' if tagv.nil? || tagv.empty?
Severity: Minor
Found in lib/opentsdb/query_param.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 auto_detect_adapter has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def auto_detect_adapter
      if defined?(::Patron)
        :partron
      elsif defined?(::Excon) && defined?(::Excon::VERSION)
        :excon
Severity: Minor
Found in lib/opentsdb/faraday.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

Block has too many lines. [27/25]
Open

Gem::Specification.new do |spec|
  spec.name          = 'opentsdb-ruby'
  spec.version       = Opentsdb::VERSION
  spec.authors       = %w(lizhe luyingrui)
  spec.email         = ['lnz013@qq.com', 'luyingrui@oneapm.com']
Severity: Minor
Found in opentsdb-ruby.gemspec by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Severity
Category
Status
Source
Language