kiyonori-matsumoto/tcl-ruby

View on GitHub

Showing 15 of 15 total issues

Method replace_commands has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

      def replace_commands(list)
        l = list.dup
        s = StringScanner.new(l)
        buffer = nil
        depth = 0
Severity: Minor
Found in lib/tcl/ruby/command.rb - About 2 hrs 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 replace_variable has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

      def replace_variable(elem)
        elem.gsub!(/\$\{(.+?)\}|\$(\w+\([^\s)]+\))|\$(\w+)/) do |_|
          v = Regexp.last_match(1) || Regexp.last_match(2) ||
              Regexp.last_match(3)
          h = nil
Severity: Minor
Found in lib/tcl/ruby/command.rb - About 1 hr 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 12 (exceeds 5 allowed). Consider refactoring.
Open

      def self.parse(options, args)
        ops = options.map do |e|
          v = e.sub(/\?/, '')
          ["-#{v}", v, e[-1] == '?']
        end
Severity: Minor
Found in lib/tcl/ruby/option_parser.rb - About 1 hr 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 __string_map_body has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

      def __string_map_body(char_map, str, opts = {})
        h = parse(char_map, true).to_h
        scan = StringScanner.new str
        rstr = ''
        until scan.empty?
Severity: Minor
Found in lib/tcl/ruby/commands/string.rb - About 1 hr 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 command has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

      def command(cmds)
        ret = nil
        cmds.each do |arg|
          next if arg.empty?
          arg.replace(&method(:replace))
Severity: Minor
Found in lib/tcl/ruby/command.rb - About 1 hr 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 replace_commands has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def replace_commands(list)
        l = list.dup
        s = StringScanner.new(l)
        buffer = nil
        depth = 0
Severity: Minor
Found in lib/tcl/ruby/command.rb - About 1 hr to fix

Method parse has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

        def parse(str, to_list = false)
          init(str)
          until @s.empty?
            if @s.scan(/\\./) then @buffer << @s[0]
            elsif @s.scan(/\#/) then parse_comments
Severity: Minor
Found in lib/tcl/ruby/parser.rb - About 1 hr 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

Avoid deeply nested control flow statements.
Open

          elsif s.scan(/[^\[\]\\]+/m)
            buffer << s[0] if buffer
Severity: Major
Found in lib/tcl/ruby/command.rb - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

            if depth == 0
              l[pos, buffer.length] = parse(buffer[1..-2]).to_s
              s.string = l
              buffer = nil
            end
Severity: Major
Found in lib/tcl/ruby/command.rb - About 45 mins to fix

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

      def __string_equal_body(str1, str2, opts = {})
        if opts.key?('nocase')
          str1 = str1.upcase
          str2 = str2.upcase
        end
Severity: Minor
Found in lib/tcl/ruby/commands/string.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 ___array_get has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def ___array_get(name, pattern = nil)
        return '' unless @variables[name].is_a?(Hash)
        if pattern
          return '' unless @variables[name].key?(pattern)
          "#{pattern} #{@variables[name][pattern]}"
Severity: Minor
Found in lib/tcl/ruby/commands/array.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_tcl_string has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def to_tcl_string
    if parenthesis?
      if (brace? && self[-1] == '}') || (quote? && self[-1] == '"')
        b = self[1..-2]
        clear << b
Severity: Minor
Found in lib/tcl/ruby/string.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 ___set has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def ___set(var_name, value = nil)
        if (m = var_name.match(/(\w+)\((\S+?)\)/))
          ___array_set(m[1], "{#{m[2]}} {#{value}}") if value
          ___array_get(m[1], "{#{m[2]}}")
        else
Severity: Minor
Found in lib/tcl/ruby/commands/basic.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

Similar blocks of code found in 2 locations. Consider refactoring.
Open

      def ___array(*arg)
        send("___array_#{arg[0]}", *arg[1..-1])
      rescue ArgumentError => e
        raise(TclArgumentError, "array #{arg[0]}: #{e.message}")
      end
Severity: Minor
Found in lib/tcl/ruby/commands/array.rb and 1 other location - About 25 mins to fix
lib/tcl/ruby/commands/string.rb on lines 8..12

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 29.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

      def ___string(*arg)
        send("___string_#{arg[0]}", *arg[1..-1])
      rescue ArgumentError => e
        raise(TclArgumentError, "string #{arg[0]}: #{e.message}")
      end
Severity: Minor
Found in lib/tcl/ruby/commands/string.rb and 1 other location - About 25 mins to fix
lib/tcl/ruby/commands/array.rb on lines 6..10

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 29.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Severity
Category
Status
Source
Language