piotrmurach/tty-file

View on GitHub

Showing 13 of 15 total issues

File file.rb has 373 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 4 hrs to fix

    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,
                             quiet: true)
          parent = args.size.nonzero? ? args.pop : nil
          if destination.is_a?(String) || destination.is_a?(Pathname)
    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 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 color_diff_lines has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def color_diff_lines(hunks)
            return hunks unless @color && @format == :unified
    
            newline = "\n"
            hunks.lines.map do |line|
    Severity: Minor
    Found in lib/tty/file/compare_files.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 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 call has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def call(file_a, file_b, file_a_path, file_b_path)
            differ = Differ.new(format: @format, context_lines: @context_lines)
            block_size = file_a.lstat.blksize
            file_a_chunk = file_a.read(block_size)
            file_b_chunk = file_b.read(block_size)
    Severity: Minor
    Found in lib/tty/file/compare_files.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 diff has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def diff(path_a, path_b, threshold: 10_000_000, format: :unified, lines: 3,
                 header: true, verbose: true, color: :green, noop: false)
          open_tempfile_if_missing(path_a) do |file_a, temp_a|
            message = check_binary_or_large(file_a, threshold)
            return message if message
    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 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

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