piotrmurach/tty-file

View on GitHub

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

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

        def append_to_file(relative_path, *args, verbose: true, color: :green,
                           force: true, noop: false, &block)
          log_status(:append, relative_path, verbose: verbose, color: color)
          inject_into_file(relative_path, *args, after: /\z/, verbose: false,
                           force: force, noop: noop, color: color, &block)
    Severity: Minor
    Found in lib/tty/file.rb and 1 other location - About 35 mins to fix
    lib/tty/file.rb on lines 543..547

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

    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 prepend_to_file(relative_path, *args, verbose: true, color: :green,
                            force: true, noop: false, &block)
          log_status(:prepend, relative_path, verbose: verbose, color: color)
          inject_into_file(relative_path, *args, before: /\A/, verbose: false,
                           color: color, force: force, noop: noop, &block)
    Severity: Minor
    Found in lib/tty/file.rb and 1 other location - About 35 mins to fix
    lib/tty/file.rb on lines 574..578

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

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