ruby-grape/grape

View on GitHub

Showing 100 of 100 total issues

Class Endpoint has 38 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 35 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 4 hrs to fix

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

      require_relative 'attributes_doc'
      
      module Grape
        module Validations
          class ParamsScope
      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, :base
        Severity: Minor
        Found in lib/grape/api/instance.rb - About 3 hrs to fix

          File endpoint.rb has 291 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

            Method add_head_not_allowed_methods_and_options_methods has a Cognitive Complexity of 21 (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 infer_coercion has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
            Open

                  def infer_coercion(validations)
                    raise ArgumentError, ':type may not be supplied with :types' if validations.key?(:type) && validations.key?(:types)
            
                    validations[:coerce] = (options_key?(:type, :value, validations) ? validations[:type][:value] : validations[:type]) if validations.key?(:type)
                    validations[:coerce_message] = (options_key?(:type, :message, validations) ? validations[:type][:message] : nil) if validations.key?(:type)
            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.\-_!#{Regexp.last_match(0)}\^]+?)(?:-([a-z0-9*.]+))?(?:\+([a-z0-9*\-.]+))?\z/.freeze
            
                    HAS_VENDOR_REGEX = /\Avnd\.[a-z0-9.\-_!#{Regexp.last_match(0)}\^]+/.freeze
            Severity: Minor
            Found in lib/grape/middleware/versioner/header.rb - About 2 hrs to fix

              Method validate! has a Cognitive Complexity of 18 (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 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

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

              require 'logger'
              require 'rack'
              require 'rack/builder'
              require 'rack/accept'
              require 'rack/auth/basic'
              Severity: Minor
              Found in lib/grape.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

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

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

                    Class API has 21 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 Boolean
                    Severity: Minor
                    Found in lib/grape/api.rb - About 2 hrs to fix

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

                      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]
                      
                              throw :error, status: 415, message: "The provided content-type '#{request.media_type}' is not supported." unless content_type_for(fmt)
                              parser = Grape::Parser.parser_for fmt, **options
                      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

                      Consider simplifying this complex logical expression.
                      Open

                              return unless
                                (request.post? || request.put? || request.patch? || request.delete?) &&
                                (!request.form_data? || !request.media_type) &&
                                !request.parseable_data? &&
                                (request.content_length.to_i.positive? || request.env[Grape::Http::Headers::HTTP_TRANSFER_ENCODING] == CHUNKED)
                      Severity: Critical
                      Found in lib/grape/middleware/formatter.rb - About 1 hr to fix

                        Method present has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                        Open

                              def present(message, env)
                                present_options = {}
                                presented_message = message
                                if presented_message.is_a?(Hash)
                                  presented_message = presented_message.dup
                        Severity: Minor
                        Found in lib/grape/error_formatter/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 optional has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                        Open

                              def optional(*attrs, &block)
                                orig_attrs = attrs.clone
                        
                                opts = attrs.extract_options!.clone
                                type = opts[:type]
                        Severity: Minor
                        Found in lib/grape/dsl/parameters.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