ruby-grape/grape

View on GitHub

Showing 79 of 85 total issues

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

        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

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

        require 'logger'
        require 'rack'
        require 'rack/builder'
        require 'rack/auth/basic'
        require 'set'
        Severity: Minor
        Found in lib/grape.rb - About 2 hrs to fix

          Method mount has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
          Open

                  def mount(mounts, *opts)
                    mounts = { mounts => '/' } unless mounts.respond_to?(:each_pair)
                    mounts.each_pair do |app, path|
                      if app.respond_to?(:mount_instance)
                        opts_with = opts.any? ? opts.first[:with] : {}
          Severity: Minor
          Found in lib/grape/dsl/routing.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 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 inside_route.rb has 267 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 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

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

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

                      def status(status = nil)
                        case status
                        when Symbol
                          raise ArgumentError, "Status code :#{status} is invalid." unless Rack::Utils::SYMBOL_TO_STATUS_CODE.key?(status)
                
                
                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 validate_param! has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                        def validate_param!(attr_name, params)
                          return unless params.is_a?(Hash)
                
                          val = params[attr_name]
                
                
                Severity: Minor
                Found in lib/grape/validations/validators/values_validator.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 mount has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                        def mount(mounts, *opts)
                          mounts = { mounts => '/' } unless mounts.respond_to?(:each_pair)
                          mounts.each_pair do |app, path|
                            if app.respond_to?(:mount_instance)
                              opts_with = opts.any? ? opts.first[:with] : {}
                Severity: Minor
                Found in lib/grape/dsl/routing.rb - About 1 hr to fix

                  Method run_rescue_handler has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                  Open

                        def run_rescue_handler(handler, error, endpoint)
                          if handler.instance_of?(Symbol)
                            raise NoMethodError, "undefined method '#{handler}'" unless respond_to?(handler)
                  
                            handler = public_method(handler)
                  Severity: Minor
                  Found in lib/grape/middleware/error.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