toptal/chewy

View on GitHub

Showing 62 of 62 total issues

Class Request has 37 methods (exceeds 20 allowed). Consider refactoring.
Open

    class Request
      include Enumerable
      include Scoping
      include Scrolling
      UNDEFINED = Class.new.freeze
Severity: Minor
Found in lib/chewy/search/request.rb - About 4 hrs to fix

    Class BulkBuilder has 26 methods (exceeds 20 allowed). Consider refactoring.
    Open

          class BulkBuilder
            # @param index [Chewy::Index] desired index
            # @param to_index [Array<Object>] objects to index
            # @param delete [Array<Object>] objects or ids to delete
            # @param fields [Array<Symbol, String>] and array of fields for documents update
    Severity: Minor
    Found in lib/chewy/index/import/bulk_builder.rb - About 3 hrs to fix

      File request.rb has 273 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      module Chewy
        module Search
          # The main request DSL class. Supports multiple index requests.
          # Supports ES5 search API and query DSL.
          #
      Severity: Minor
      Found in lib/chewy/search/request.rb - About 2 hrs to fix

        Method sync has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

              def sync(only: nil, except: nil, parallel: nil, output: $stdout)
                subscribed_task_stats(output) do
                  indexes_from(only: only, except: except).each_with_object([]) do |index, synced_indexes|
                    output.puts "Synchronizing #{index}"
                    output.puts "  #{index} doesn't support outdated synchronization" unless index.supports_outdated_sync?
        Severity: Minor
        Found in lib/chewy/rake_helper.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 dynamic_template has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

              def dynamic_template(*args)
                options = args.extract_options!.deep_symbolize_keys
                if args.first
                  template_name = :"template_#{dynamic_templates.count.next}"
                  template = {template_name => {mapping: options}}
        Severity: Minor
        Found in lib/chewy/fields/root.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 update_proc has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

                def update_proc(index_name, *args, &block)
                  options = args.extract_options!
                  method = args.first
        
                  proc do
        Severity: Minor
        Found in lib/chewy/index/observe/active_record_methods.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 resolve has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

              def resolve(params, repository)
                if params.is_a?(Array)
                  params.flatten.reject(&:blank?).each.with_object({}) do |name_or_hash, result|
                    options = if name_or_hash.is_a?(Hash)
                      name_or_hash
        Severity: Minor
        Found in lib/chewy/index/settings.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 first has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

              def first(limit = UNDEFINED)
                request_limit = limit == UNDEFINED ? 1 : limit
        
                if performed? && (request_limit <= size || size == total)
                  limit == UNDEFINED ? wrappers.first : wrappers.first(limit)
        Severity: Minor
        Found in lib/chewy/search/request.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 non_proc_values has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

                def non_proc_values(field, nesting)
                  non_proc_fields = non_proc_fields_for(field, nesting)
                  object = "object#{nesting}"
        
                  if non_proc_fields.present?
        Severity: Minor
        Found in lib/chewy/index/witchcraft.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 scroll_batches has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

              def scroll_batches(batch_size: Request::DEFAULT_BATCH_SIZE, scroll: Request::DEFAULT_SCROLL)
                return enum_for(:scroll_batches, batch_size: batch_size, scroll: scroll) unless block_given?
        
                result = perform(size: batch_size, scroll: scroll)
                total = [raw_limit_value, result.fetch('hits', {}).fetch('total', {}).fetch('value', 0)].compact.min
        Severity: Minor
        Found in lib/chewy/search/scrolling.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 create_missing_indexes! has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

              def create_missing_indexes!(output: $stdout, env: ENV)
                subscribed_task_stats(output) do
                  Chewy.eager_load!
                  all_indexes = Chewy::Index.descendants
                  all_indexes -= [Chewy::Stash::Journal] unless Chewy.configuration[:journal]
        Severity: Minor
        Found in lib/chewy/rake_helper.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 index_entry has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

                def index_entry(object)
                  entry = {}
                  entry[:_id] = index_object_ids[object] if index_object_ids[object]
                  entry[:routing] = routing(object) if join_field?
        
        
        Severity: Minor
        Found in lib/chewy/index/import/bulk_builder.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 reset! has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def reset!(suffix = nil, apply_journal: true, journal: false, **import_options)
                  result = if suffix.present?
                    start_time = Time.now
                    indexes = self.indexes - [index_name]
                    create! suffix, alias: false
        Severity: Minor
        Found in lib/chewy/index/actions.rb - About 1 hr to fix

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

                  def source_for(proc, nesting)
                    ast = Parser::CurrentRuby.parse(proc.source)
                    lambdas = exctract_lambdas(ast)
          
                    raise "No lambdas found, try to reformat your code:\n`#{proc.source}`" unless lambdas
          Severity: Minor
          Found in lib/chewy/index/witchcraft.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 parent_changed? has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

                  def parent_changed?(data, old_parent)
                    return false unless old_parent
                    return false unless join_field?
                    return false unless @fields.include?(join_field.to_sym)
                    return false unless data.key?(join_field)
          Severity: Minor
          Found in lib/chewy/index/import/bulk_builder.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 entry_id has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

                  def entry_id(object)
                    if type_root.id
                      type_root.compose_id(object)
                    else
                      id = object.id if object.respond_to?(:id)
          Severity: Minor
          Found in lib/chewy/index/import/bulk_builder.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 import_parallel has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

                  def import_parallel(objects, routine)
                    raise "The `parallel` gem is required for parallel import, please add `gem 'parallel'` to your Gemfile" unless '::Parallel'.safe_constantize
          
                    ActiveSupport::Notifications.instrument 'import_objects.chewy', index: self do |payload|
                      batches = adapter.import_references(*objects, routine.options.slice(:batch_size)).to_a
          Severity: Minor
          Found in lib/chewy/index/import.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 request_bodies has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

                  def request_bodies(body)
                    if @bulk_size
                      serializer = ::Elasticsearch::API.serializer
                      pieces = body.each_with_object(['']) do |piece, result|
                        operation, meta = piece.to_a.first
          Severity: Minor
          Found in lib/chewy/index/import/bulk_request.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 mock_elasticsearch_response_sources has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def mock_elasticsearch_response_sources(index, hits, &block)
                  raw_response = {
                    'took' => 4,
                    'timed_out' => false,
                    '_shards' => {
          Severity: Minor
          Found in lib/chewy/minitest/helpers.rb - About 1 hr to fix

            Method mock_elasticsearch_response_sources has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def mock_elasticsearch_response_sources(index, hits)
                    raw_response = {
                      'took' => 4,
                      'timed_out' => false,
                      '_shards' => {
            Severity: Minor
            Found in lib/chewy/rspec/helpers.rb - About 1 hr to fix
              Severity
              Category
              Status
              Source
              Language