ruby-grape/grape

View on GitHub

Showing 95 of 95 total issues

Class Endpoint has 39 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Endpoint
    include Grape::DSL::Settings
    include Grape::DSL::InsideRoute

    attr_accessor :block, :source, :options
Severity: Minor
Found in lib/grape/endpoint.rb - About 5 hrs to fix

    Class ParamsScope has 30 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class ParamsScope
          attr_accessor :element, :parent, :index
          attr_reader :type
    
          include Grape::DSL::Parameters
    Severity: Minor
    Found in lib/grape/validations/params_scope.rb - About 3 hrs to fix

      Method declared_hash has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

              def declared_hash(passed_params, options, declared_params, params_nested_path)
                declared_params.each_with_object(passed_params.class.new) do |declared_param, memo|
                  if declared_param.is_a?(Hash)
                    declared_param.each_pair do |declared_parent_param, declared_children_params|
                      params_nested_path_dup = params_nested_path.dup
      Severity: Minor
      Found in lib/grape/dsl/inside_route.rb - About 3 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

      File endpoint.rb has 308 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      module Grape
        # An Endpoint is the proxy scope in which all routing
        # blocks are executed. In other words, any methods
        # on the instance level of this class may be called
        # from inside a `get`, `post`, etc.
      Severity: Minor
      Found in lib/grape/endpoint.rb - About 3 hrs to fix

        File params_scope.rb has 300 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        module Grape
          module Validations
            class ParamsScope
              attr_accessor :element, :parent, :index
              attr_reader :type
        Severity: Minor
        Found in lib/grape/validations/params_scope.rb - About 3 hrs to fix

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

              class Instance
                include Grape::DSL::API
          
                class << self
                  attr_reader :instance
          Severity: Minor
          Found in lib/grape/api/instance.rb - About 3 hrs to fix

            Method infer_coercion has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
            Open

                  def infer_coercion(validations)
                    if validations.key?(:type) && validations.key?(:types)
                      raise ArgumentError, ':type may not be supplied with :types'
                    end
            
            
            Severity: Minor
            Found in lib/grape/validations/params_scope.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

            Class Header has 24 methods (exceeds 20 allowed). Consider refactoring.
            Open

                  class Header < Base
                    VENDOR_VERSION_HEADER_REGEX =
                      /\Avnd\.([a-z0-9.\-_!#\$&\^]+?)(?:-([a-z0-9*.]+))?(?:\+([a-z0-9*\-.]+))?\z/.freeze
            
                    HAS_VENDOR_REGEX = /\Avnd\.[a-z0-9.\-_!#\$&\^]+/.freeze
            Severity: Minor
            Found in lib/grape/middleware/versioner/header.rb - About 2 hrs to fix

              File inside_route.rb has 264 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              require 'active_support/concern'
              require 'grape/dsl/headers'
              
              module Grape
                module DSL
              Severity: Minor
              Found in lib/grape/dsl/inside_route.rb - About 2 hrs to fix

                Class Router has 22 methods (exceeds 20 allowed). Consider refactoring.
                Open

                  class Router
                    attr_reader :map, :compiled
                
                    def self.normalize_path(path)
                      path = +"/#{path}"
                Severity: Minor
                Found in lib/grape/router.rb - About 2 hrs to fix

                  Class API has 22 methods (exceeds 20 allowed). Consider refactoring.
                  Open

                    class API
                      # Class methods that we want to call on the API rather than on the API object
                      NON_OVERRIDABLE = (Class.new.methods + %i[call call! configuration compile! inherited]).freeze
                  
                      class << self
                  Severity: Minor
                  Found in lib/grape/api.rb - About 2 hrs to fix

                    Method add_head_not_allowed_methods_and_options_methods has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                    Open

                          def add_head_not_allowed_methods_and_options_methods
                            versioned_route_configs = collect_route_config_per_pattern
                            # The paths we collected are prepared (cf. Path#prepare), so they
                            # contain already versioning information when using path versioning.
                            # Disable versioning so adding a route won't prepend versioning
                    Severity: Minor
                    Found in lib/grape/api/instance.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 check_incompatible_option_values has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                    Open

                          def check_incompatible_option_values(default, values, except_values, excepts)
                            return unless default && !default.is_a?(Proc)
                    
                            if values && !values.is_a?(Proc)
                              raise Grape::Exceptions::IncompatibleOptionValues.new(:default, default, :values, values) \
                    Severity: Minor
                    Found in lib/grape/validations/params_scope.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 meets_dependency? has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                    Open

                          def meets_dependency?(params, request_params)
                            if @parent.present? && !@parent.meets_dependency?(@parent.params(request_params), request_params)
                              return false
                            end
                    
                    
                    Severity: Minor
                    Found in lib/grape/validations/params_scope.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 validate! has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                    Open

                          def validate!(params)
                            attributes = SingleAttributeIterator.new(self, @scope, params)
                            # we collect errors inside array because
                            # there may be more than one error per field
                            array_errors = []
                    Severity: Minor
                    Found in lib/grape/validations/validators/base.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 validate_value_coercion has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                    Open

                          def validate_value_coercion(coerce_type, *values_list)
                            return unless coerce_type
                            coerce_type = coerce_type.first if coerce_type.is_a?(Array)
                            values_list.each do |values|
                              next if !values || values.is_a?(Proc)
                    Severity: Minor
                    Found in lib/grape/validations/params_scope.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 run_validators has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def run_validators(validator_factories, request)
                          validation_errors = []
                    
                          validators = validator_factories.map { |options| Grape::Validations::ValidatorFactory.create_validator(**options) }
                    
                    
                    Severity: Minor
                    Found in lib/grape/endpoint.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 read_rack_input has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                    Open

                          def read_rack_input(body)
                            fmt = request.media_type ? mime_types[request.media_type] : options[:default_format]
                    
                            unless content_type_for(fmt)
                              throw :error, status: 415, message: "The provided content-type '#{request.media_type}' is not supported."
                    Severity: Minor
                    Found in lib/grape/middleware/formatter.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 validates has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                    Open

                          def validates(attrs, validations)
                            doc_attrs = { required: validations.key?(:presence) }
                    
                            coerce_type = infer_coercion(validations)
                    
                    
                    Severity: Minor
                    Found in lib/grape/validations/params_scope.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 present has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                    Open

                          def present(*args)
                            options = args.count > 1 ? args.extract_options! : {}
                            key, object = if args.count == 2 && args.first.is_a?(Symbol)
                                            args
                                          else
                    Severity: Minor
                    Found in lib/grape/dsl/inside_route.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

                    Severity
                    Category
                    Status
                    Source
                    Language