piotrmurach/tty-file

View on GitHub

Showing 13 of 15 total issues

File file.rb has 377 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "pastel"
require "erb"
require "tempfile"
require "pathname"

Severity: Minor
Found in lib/tty/file.rb - About 5 hrs to fix

    Method diff has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

        def diff(path_a, path_b, threshold: 10_000_00, format: :unified,
                 header: true, context_lines: 3, verbose: true,
                 color: :green, noop: false)
          output = []
    
    
    Severity: Minor
    Found in lib/tty/file.rb - About 4 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 detect_collision has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

          def detect_collision
            if exist?
              if identical?
                notify(:identical, :cyan)
              elsif @force
    Severity: Minor
    Found in lib/tty/file/create_file.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 create_directory has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def create_directory(destination, *args, context: nil, verbose: true,
                             color: :green, noop: false, force: false, skip: false)
          parent = args.size.nonzero? ? args.pop : nil
          if destination.is_a?(String) || destination.is_a?(Pathname)
            destination = { destination.to_s => [] }
    Severity: Minor
    Found in lib/tty/file.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 tail_file has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def tail_file(relative_path, lines: 10, chunk_size: 512, &block)
          file = ::File.open(relative_path)
          line_sep = $/
          output = []
          newline_count = 0
    Severity: Minor
    Found in lib/tty/file.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 diff has 30 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def diff(path_a, path_b, threshold: 10_000_00, format: :unified,
                 header: true, context_lines: 3, verbose: true,
                 color: :green, noop: false)
          output = []
    
    
    Severity: Minor
    Found in lib/tty/file.rb - About 1 hr to fix

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

          def copy_file(source_path, *args, context: nil, force: false, skip: false,
                        verbose: true, color: :green, noop: false, preserve: nil, &block)
            source_path = source_path.to_s
            dest_path = (args.first || source_path).to_s.sub(/\.erb$/, "")
      
      
      Severity: Minor
      Found in lib/tty/file.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 copy_directory has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def copy_directory(source_path, *args, context: nil, force: false, skip: false,
                             verbose: true, color: :green, noop: false, preserve: nil,
                             recursive: true, exclude: nil, &block)
            source_path = source_path.to_s
            check_path(source_path)
      Severity: Minor
      Found in lib/tty/file.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 inject_into_file has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def inject_into_file(relative_path, *args, verbose: true, color: :green,
                               after: nil, before: nil, force: true, noop: false, &block)
            check_path(relative_path)
            replacement = block_given? ? block[] : args.join
      
      
      Severity: Minor
      Found in lib/tty/file.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 download_file has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def download_file(uri, *args, **options, &block)
            uri = uri.to_s
            dest_path = (args.first || ::File.basename(uri)).to_s
      
            unless uri =~ %r{^https?\://}
      Severity: Minor
      Found in lib/tty/file.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 replace_in_file has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def replace_in_file(relative_path, *args, verbose: true, color: :green,
                              noop: false, force: true, &block)
            check_path(relative_path)
            contents = ::File.read(relative_path)
            replacement = (block ? block[] : args[1..-1].join).gsub('\0', "")
      Severity: Minor
      Found in lib/tty/file.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

      Avoid too many return statements within this method.
      Open

                return "No differences found\n" if hunks.empty?
      Severity: Major
      Found in lib/tty/file.rb - About 30 mins to fix

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

              def call
                if ::FileTest.file?(source.to_s)
                  ::File.open(source, "rb") { |f| checksum_io(f, @digest) }
                else
                  non_file = source
        Severity: Minor
        Found in lib/tty/file/digest_file.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