piotrmurach/tty-prompt

View on GitHub

Showing 49 of 49 total issues

Method initialize has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def initialize(prompt, **options)
        # Option deprecation
        if options[:validation]
          warn "[DEPRECATION] The `:validation` option is deprecated. Use `:validate` instead."
          options[:validate] = options[:validation]
Severity: Minor
Found in lib/tty/prompt/question.rb - About 1 hr to fix

    Method validate_defaults has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

          def validate_defaults
            @default.each do |d|
              msg = if d.nil? || d.to_s.empty?
                      "default index must be an integer in range (1 - #{choices.size})"
                    elsif d.to_s !~ INTEGER_MATCHER
    Severity: Minor
    Found in lib/tty/prompt/list.rb - About 55 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 call has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

            def call(input)
              if pattern.is_a?(String) || pattern.is_a?(Symbol)
                VALIDATORS.key?(pattern.to_sym)
                !VALIDATORS[pattern.to_sym].match(input.to_s).nil?
              elsif pattern.is_a?(Regexp)
    Severity: Minor
    Found in lib/tty/prompt/question/validation.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 render has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def render
            @input = ""
            until @done
              question = render_question
              @prompt.print(question)
    Severity: Minor
    Found in lib/tty/prompt/enum_list.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

    Consider simplifying this complex logical expression.
    Open

            elsif (@first_render && (help_start? || help_always?)) ||
                  (help_always? && !@filter.any? && !@done)
              minmax_suffix +
                (print_selected ? "#{selected_names} " : "") +
                instructions
    Severity: Major
    Found in lib/tty/prompt/multi_list.rb - About 40 mins to fix

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

      choices = [{
        key: "y",
        name: "overwrite this file",
        value: :yes
      }, {
      Severity: Minor
      Found in examples/expand.rb and 1 other location - About 40 mins to fix
      examples/expand_auto.rb on lines 5..25

      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 37.

      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

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

      choices = [{
        key: "y",
        name: "overwrite this file",
        value: :yes
      }, {
      Severity: Minor
      Found in examples/expand_auto.rb and 1 other location - About 40 mins to fix
      examples/expand.rb on lines 5..25

      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 37.

      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

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

            def render_question
              header = ["#{@prefix}#{message} "]
              if echo?
                masked = @mask.to_s * @input.to_s.length
                if @done_masked && !@failure
      Severity: Minor
      Found in lib/tty/prompt/mask_question.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 choices has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

            def choices(values = (not_set = true))
              if not_set
                if !filterable? || @filter.empty?
                  @choices
                else
      Severity: Minor
      Found in lib/tty/prompt/list.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 setup_defaults has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

            def setup_defaults
              infer_default
              @convert = conversion
              return if suffix? && positive?
      
      
      Severity: Minor
      Found in lib/tty/prompt/confirm_question.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 validate_defaults has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

            def validate_defaults
              msg = if @default.nil? || @default.to_s.empty?
                      "default index must be an integer in range (1 - #{choices.size})"
                    elsif @default.to_s !~ INTEGER_MATCHER
                      validate_default_name
      Severity: Minor
      Found in lib/tty/prompt/enum_list.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 initialize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

            def initialize(prompt, **options)
              super
              @echo    = options.fetch(:echo) { false }
              @keys    = options.fetch(:keys) { UndefinedSetting }
              @timeout = options.fetch(:timeout) { UndefinedSetting }
      Severity: Minor
      Found in lib/tty/prompt/keypress.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 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 while_remaining has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

            def while_remaining
              start
              remaining = duration
      
              if @duration
      Severity: Minor
      Found in lib/tty/prompt/timer.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 render_question has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

            def render_question
              header = []
              if !Utils.blank?(@prefix) || !Utils.blank?(message)
                header << "#{@prefix}#{message} "
              end
      Severity: Minor
      Found in lib/tty/prompt/question.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 setup_defaults has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def setup_defaults
              validate_defaults
              # At this stage, @choices matches all the visible choices.
              default_indexes = @default.map do |d|
                if d.to_s =~ INTEGER_MATCHER
      Severity: Minor
      Found in lib/tty/prompt/multi_list.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 render has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def render
              @errors = []
              until @done
                result = process_input(render_question)
                if result.failure?
      Severity: Minor
      Found in lib/tty/prompt/question.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 call has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

                def self.call(question, value)
                  if question.convert? && !Utils.blank?(value)
                    result = question.convert_result(value)
                    if result == Const::Undefined
                      tokens = { value: value, type: question.convert }
      Severity: Minor
      Found in lib/tty/prompt/question/checks.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 render_question has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def render_question
              header = ["#{@prefix}#{@question} "]
              if @done
                header << @prompt.decorate(choices[@active].to_s, @active_color)
                header << "\n"
      Severity: Minor
      Found in lib/tty/prompt/slider.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 render_question has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def render_question
              header = "#{@prefix}#{message} "
              if !@done
                header += @prompt.decorate("(#{@suffix})", @help_color) + " "
              else
      Severity: Minor
      Found in lib/tty/prompt/confirm_question.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

      Severity
      Category
      Status
      Source
      Language