ruby-grape/grape

View on GitHub

Showing 80 of 86 total issues

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

      def validates(attrs, validations)
        doc = AttributesDoc.new @api, self
        doc.extract_details validations

        coerce_type = infer_coercion(validations)
Severity: Minor
Found in lib/grape/validations/params_scope.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 validate! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def validate!(params)
          attrs = SingleAttributeIterator.new(self, @scope, params)
          attrs.each do |resource_params, attr_name|
            next unless @scope.meets_dependency?(resource_params, params)

Severity: Minor
Found in lib/grape/validations/validators/default_validator.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 requires has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def requires(*attrs, &block)
        orig_attrs = attrs.clone

        opts = attrs.extract_options!.clone
        opts[:presence] = { value: true, message: opts[:message] }
Severity: Minor
Found in lib/grape/dsl/parameters.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 extract_message_option has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def extract_message_option(attrs)
        return nil unless attrs.is_a?(Array)

        opts = attrs.last.is_a?(Hash) ? attrs.pop : {}
        opts.key?(:message) && !opts[:message].nil? ? opts.delete(:message) : nil
Severity: Minor
Found in lib/grape/validations/params_scope.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 redirect has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def redirect(url, permanent: false, body: nil, **_options)
        body_message = body
        if permanent
          status 301
          body_message ||= "This resource has been moved permanently to #{url}."
Severity: Minor
Found in lib/grape/dsl/inside_route.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 push_declared_params has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def push_declared_params(attrs, **opts)
        opts = opts.merge(declared_params_scope: self) unless opts.key?(:declared_params_scope)
        if lateral?
          @parent.push_declared_params(attrs, **opts)
        else
Severity: Minor
Found in lib/grape/validations/params_scope.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 validate_param! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def validate_param!(attr_name, params)
          params[attr_name] = if @default.is_a? Proc
                                if @default.parameters.empty?
                                  @default.call
                                else
Severity: Minor
Found in lib/grape/validations/validators/default_validator.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 call_with_allow_headers(env, last_neighbor_route) if !cascade && last_neighbor_route
Severity: Major
Found in lib/grape/router.rb - About 30 mins to fix

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

            def check_values(param_array, attr_name)
              values = @values.is_a?(Proc) && @values.arity.zero? ? @values.call : @values
              return true if values.nil?
    
              begin
    Severity: Minor
    Found in lib/grape/validations/validators/values_validator.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 mime_array has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def mime_array
            accept = env[Grape::Http::Headers::HTTP_ACCEPT]
            return [] unless accept
    
            accept_into_mime_and_quality = %r{
    Severity: Minor
    Found in lib/grape/middleware/formatter.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_headers has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def build_headers
          Grape::Util::LazyObject.new do
            env.each_pair.with_object({}) do |(k, v), headers|
              next unless k.to_s.start_with? HTTP_PREFIX
    
    
    Severity: Minor
    Found in lib/grape/request.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 should_validate? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def should_validate?(parameters)
            scoped_params = params(parameters)
    
            return false if @optional && (scoped_params.blank? || all_element_blank?(scoped_params))
            return false unless meets_dependency?(scoped_params, parameters)
    Severity: Minor
    Found in lib/grape/validations/params_scope.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 meets_dependency? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

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

          def stream(value = nil)
            return if value.nil? && @stream.nil?
    
            header Rack::CONTENT_LENGTH, nil
            header Grape::Http::Headers::TRANSFER_ENCODING, nil
    Severity: Minor
    Found in lib/grape/dsl/inside_route.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 call has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

            def call(message, backtrace, options = {}, env = nil, original_exception = nil)
              message = present(message, env)
    
              result = message.is_a?(Hash) ? ::Grape::Json.dump(message) : message
              rescue_options = options[:rescue_options] || {}
    Severity: Minor
    Found in lib/grape/error_formatter/txt.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 compose_message has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def compose_message(key, **attributes)
            short_message = translate_message(key, **attributes)
            if short_message.is_a? Hash
              @problem = problem(key, **attributes)
              @summary = summary(key, **attributes)
    Severity: Minor
    Found in lib/grape/exceptions/base.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 rescue_handler_for_grape_exception has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def rescue_handler_for_grape_exception(klass)
            return unless klass <= Grape::Exceptions::Base
            return method(:error_response) if klass == Grape::Exceptions::InvalidVersionHeader
            return unless options[:rescue_grape_exceptions] || !options[:rescue_all]
    
    
    Severity: Minor
    Found in lib/grape/middleware/error.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 validate_param! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

            def validate_param!(attr_name, params)
              raise validation_exception(attr_name) unless params.is_a? Hash
    
              new_value = coerce_value(params[attr_name])
    
    
    Severity: Minor
    Found in lib/grape/validations/validators/coerce_validator.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 before has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

            def before
              potential_version = (env[Grape::Http::Headers::HTTP_ACCEPT_VERSION] || '').strip
    
              if strict? && potential_version.empty?
                # If no Accept-Version header:
    Severity: Minor
    Found in lib/grape/middleware/versioner/accept_version_header.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 infer_type_check has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

            def infer_type_check(type)
              # First check for special class methods
              if type.respond_to? :coerced?
                type.method :coerced?
              elsif type.respond_to? :parsed?
    Severity: Minor
    Found in lib/grape/validations/types/custom_type_coercer.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