piotrmurach/tty-file

View on GitHub

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

      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 552..556

      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 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 521..525

      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

      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