Showing 85 of 85 total issues

Avoid deeply nested control flow statements.
Open

          elsif @unquoted_column_value and
                (new_line = @scanner.scan(@line_end))
            ignore_broken_line
            message = "Unquoted fields do not allow new line " +
                      "<#{new_line.inspect}>"
Severity: Major
Found in lib/csv/parser.rb - About 45 mins to fix

    Method strip_value has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def strip_value(value)
          return value unless @strip
          return value if value.nil?
    
          case @strip
    Severity: Minor
    Found in lib/csv/parser.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

    Avoid deeply nested control flow statements.
    Open

                  if @scanner.scan(@escaped_quote)
                    value << @quote_character
                  else
                    value << @backslash_character
                  end
    Severity: Major
    Found in lib/csv/parser.rb - About 45 mins to fix

      Method to_csv has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def to_csv(write_headers: true, limit: nil, **options)
            array = write_headers ? [headers.to_csv(**options)] : []
            limit ||= @table.size
            limit = @table.size + 1 + limit if limit < 0
            limit = 0 if limit < 0
      Severity: Minor
      Found in lib/csv/table.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 inspect has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def inspect
            str = ["#<", self.class.to_s]
            each do |header, field|
              str << " " << (header.is_a?(Symbol) ? header.to_s : header.inspect) <<
                     ":" << field.inspect
      Severity: Minor
      Found in lib/csv/row.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

      Avoid deeply nested control flow statements.
      Open

                    if n_quotes.zero?
                      quoted_fields << false
                      # no quote
                    elsif n_quotes == 2 and
                         column.start_with?(@quote_character) and
      Severity: Major
      Found in lib/csv/parser.rb - About 45 mins to fix

        Consider simplifying this complex logical expression.
        Open

              if @mode == :row or  # by indices
                 ( @mode == :col_or_row and indices_or_headers.all? do |index|
                                              index.is_a?(Integer)         or
                                              ( index.is_a?(Range)         and
                                                index.first.is_a?(Integer) and
        Severity: Major
        Found in lib/csv/table.rb - About 40 mins to fix

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

              def validate_strip_and_col_sep_options
                return unless @strip
          
                if @strip.is_a?(String)
                  if @column_separator.start_with?(@strip) || @column_separator.end_with?(@strip)
          Severity: Minor
          Found in lib/csv/parser.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 prepare_format has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def prepare_format
                @column_separator = @options[:column_separator].to_s.encode(@encoding)
                row_separator = @options[:row_separator]
                if row_separator == :auto
                  @row_separator = InputRecordSeparator.value.encode(@encoding)
          Severity: Minor
          Found in lib/csv/writer.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 if mode.include?(":")
          Severity: Major
          Found in lib/csv.rb - About 30 mins to fix

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

                def prepare_quoted
                  if @quote_character
                    @quotes = Regexp.new(@escaped_quote_character +
                                         "+".encode(@encoding))
                    no_quoted_values = @escaped_quote_character.dup
            Severity: Minor
            Found in lib/csv/parser.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 dig has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def dig(index_or_header, *index_or_headers)
                  value = self[index_or_header]
                  if value.nil?
                    nil
                  elsif index_or_headers.empty?
            Severity: Minor
            Found in lib/csv/table.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 build_scanner has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                  def build_scanner
                    inputs = @samples.collect do |sample|
                      UnoptimizedStringIO.new(sample)
                    end
                    if @input.is_a?(StringIO)
            Severity: Minor
            Found in lib/csv/parser.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 generate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def generate(str=nil, **options)
                  encoding = options[:encoding]
                  # add a default empty String, if none was given
                  if str
                    str = StringIO.new(str)
            Severity: Minor
            Found in lib/csv.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 field has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def field(header_or_index, minimum_index = 0)
                  # locate the pair
                  finder = (header_or_index.is_a?(Integer) || header_or_index.is_a?(Range)) ? :[] : :assoc
                  pair   = @row[minimum_index..-1].public_send(finder, header_or_index)
            
            
            Severity: Minor
            Found in lib/csv/row.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

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

                def parse_column_end
                  return true if @scanner.scan(@column_end)
                  return false unless @column_ends
            
                  @scanner.keep_start
            Severity: Minor
            Found in lib/csv/parser.rb and 1 other location - About 25 mins to fix
            lib/csv/parser.rb on lines 1214..1223

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

            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 determine_encoding has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def determine_encoding(encoding, internal_encoding)
                # honor the IO encoding if we can, otherwise default to ASCII-8BIT
                io_encoding = raw_encoding
                return io_encoding if io_encoding
            
            
            Severity: Minor
            Found in lib/csv.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 dig has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def dig(index_or_header, *indexes)
                  value = field(index_or_header)
                  if value.nil?
                    nil
                  elsif indexes.empty?
            Severity: Minor
            Found in lib/csv/row.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 may_enable_bom_deletection_automatically has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def may_enable_bom_deletection_automatically(mode, options, file_opts)
                  # "bom|utf-8" may be buggy on Windows:
                  # https://bugs.ruby-lang.org/issues/20526
                  return if ON_WINDOWS
                  return unless Encoding.default_external == Encoding::UTF_8
            Severity: Minor
            Found in lib/csv.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 headers has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def headers
                if @writer
                  @writer.headers
                else
                  parsed_headers = parser.headers
            Severity: Minor
            Found in lib/csv.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