piotrmurach/tty-prompt

View on GitHub
lib/tty/prompt/expander.rb

Summary

Maintainability
B
5 hrs
Test Coverage

Class Expander has 25 methods (exceeds 20 allowed). Consider refactoring.
Open

    class Expander
      HELP_CHOICE = {
        key: "h",
        name: "print help",
        value: :help
Severity: Minor
Found in lib/tty/prompt/expander.rb - About 2 hrs to fix

    Method validate_choices has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

          def validate_choices
            errors = []
            keys = []
            @choices.each do |choice|
              if choice.key.nil?
    Severity: Minor
    Found in lib/tty/prompt/expander.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 keypress has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

          def keypress(event)
            if DELETE_KEYS.include?(event.key.name)
              @input.chop! unless @input.empty?
            elsif event.value =~ /^[^\e\n\r]/
              @input += event.value
    Severity: Minor
    Found in lib/tty/prompt/expander.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 load_auto_hint has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def load_auto_hint
            if @hint.nil? && collapsed?
              if @selected
                @hint = @selected.name
              else
    Severity: Minor
    Found in lib/tty/prompt/expander.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 refresh has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def refresh(lines)
            if (@hint && (!@selected || @done)) || (@auto_hint && collapsed?)
              @hint = nil
              @prompt.clear_lines(lines, :down) +
                @prompt.cursor.prev_line
    Severity: Minor
    Found in lib/tty/prompt/expander.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 keyenter has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def keyenter(_)
            if @input.nil? || @input.empty?
              @input = @choices[@default - 1].key
              @default_key = true
            end
    Severity: Minor
    Found in lib/tty/prompt/expander.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

    There are no issues that match your filters.

    Category
    Status