ddd-ruby/contracts.ruby

View on GitHub

Showing 23 of 23 total issues

File builtin_contracts.rb has 358 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Contracts
  module Builtin
    # Check that an argument is +Numeric+.
    class Num
      def self.valid?(val)
Severity: Minor
Found in lib/contracts/builtin_contracts.rb - About 4 hrs to fix

    Class MethodHandler has 21 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class MethodHandler
        METHOD_REFERENCE_FACTORY = {
          :class_methods    => SingletonMethodReference,
          :instance_methods => MethodReference
        }.freeze
    Severity: Minor
    Found in lib/contracts/method_handler.rb - About 2 hrs to fix

      Assignment Branch Condition size for handle is too high. [15.13/15]
      Open

          def handle
            return unless engine?
            return if decorators.empty?
      
            validate_decorators!
      Severity: Minor
      Found in lib/contracts/method_handler.rb by rubocop

      This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

      Method execute_on_target has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def execute_on_target(obj, name, method_type, current_engine, *args, &blk)
      Severity: Minor
      Found in lib/contracts/method_handler.rb - About 45 mins to fix

        Method fail_if_invalid has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def fail_if_invalid(validator, arg, arg_pos, args_size, contract)
        Severity: Minor
        Found in lib/contracts/args_validator.rb - About 35 mins to fix

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

              def message
                s = []
                s << header.to_s
                s << "        Expected: #{expected}"
                s << "        Actual: #{data[:arg].inspect}"
          Severity: Minor
          Found in lib/contracts/error_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

          Empty line detected around arguments.
          Open

          
          Contract String => String
          Severity: Minor
          Found in lib/contracts/method_handler.rb by rubocop

          This cops checks if empty lines exist around the arguments of a method invocation.

          Example:

          # bad
          do_something(
            foo
          
          )
          
          process(bar,
          
                  baz: qux,
                  thud: fred)
          
          some_method(
          
            [1,2,3],
            x: y
          )
          
          # good
          do_something(
            foo
          )
          
          process(bar,
                  baz: qux,
                  thud: fred)
          
          some_method(
            [1,2,3],
            x: y
          )

          Empty line detected around arguments.
          Open

          
          #{(matched + [decorator]).map(&:to_s).join("\n")}
          Severity: Minor
          Found in lib/contracts/method_handler.rb by rubocop

          This cops checks if empty lines exist around the arguments of a method invocation.

          Example:

          # bad
          do_something(
            foo
          
          )
          
          process(bar,
          
                  baz: qux,
                  thud: fred)
          
          some_method(
          
            [1,2,3],
            x: y
          )
          
          # good
          do_something(
            foo
          )
          
          process(bar,
                  baz: qux,
                  thud: fred)
          
          some_method(
            [1,2,3],
            x: y
          )

          Extra blank line detected.
          Open

          
          group :test do
          Severity: Minor
          Found in Gemfile by rubocop

          This cops checks for two or more consecutive blank lines.

          Example:

          # bad - It has two empty lines.
          some_method
          # one empty line
          # two empty lines
          some_method
          
          # good
          some_method
          # one empty line
          some_method

          Empty line detected around arguments.
          Open

          
          Did you accidentally put more than one contract on a single function, like so?
          Severity: Minor
          Found in lib/contracts/method_handler.rb by rubocop

          This cops checks if empty lines exist around the arguments of a method invocation.

          Example:

          # bad
          do_something(
            foo
          
          )
          
          process(bar,
          
                  baz: qux,
                  thud: fred)
          
          some_method(
          
            [1,2,3],
            x: y
          )
          
          # good
          do_something(
            foo
          )
          
          process(bar,
                  baz: qux,
                  thud: fred)
          
          some_method(
            [1,2,3],
            x: y
          )

          Do not place comments on the same line as the end keyword.
          Open

            end # end CallWith
          Severity: Minor
          Found in lib/contracts/contract/call_with.rb by rubocop

          This cop checks for comments put on the same line as some keywords. These keywords are: begin, class, def, end, module.

          Note that some comments (such as :nodoc: and rubocop:disable) are allowed.

          Example:

          # bad
          if condition
            statement
          end # end if
          
          # bad
          class X # comment
            statement
          end
          
          # bad
          def x; end # comment
          
          # good
          if condition
            statement
          end
          
          # good
          class X # :nodoc:
            y
          end

          Empty line detected around arguments.
          Open

          
          If you did NOT, then you have probably discovered a bug in this library.
          Severity: Minor
          Found in lib/contracts/method_handler.rb by rubocop

          This cops checks if empty lines exist around the arguments of a method invocation.

          Example:

          # bad
          do_something(
            foo
          
          )
          
          process(bar,
          
                  baz: qux,
                  thud: fred)
          
          some_method(
          
            [1,2,3],
            x: y
          )
          
          # good
          do_something(
            foo
          )
          
          process(bar,
                  baz: qux,
                  thud: fred)
          
          some_method(
            [1,2,3],
            x: y
          )

          Avoid rescuing without specifying an error class.
          Open

              rescue
          Severity: Minor
          Found in lib/contracts/error_formatter.rb by rubocop

          This cop checks for rescuing StandardError. There are two supported styles implicit and explicit. This cop will not register an offense if any error other than StandardError is specified.

          Example: EnforcedStyle: implicit

          # `implicit` will enforce using `rescue` instead of
          # `rescue StandardError`.
          
          # bad
          begin
            foo
          rescue StandardError
            bar
          end
          
          # good
          begin
            foo
          rescue
            bar
          end
          
          # good
          begin
            foo
          rescue OtherError
            bar
          end
          
          # good
          begin
            foo
          rescue StandardError, SecurityError
            bar
          end

          Example: EnforcedStyle: explicit (default)

          # `explicit` will enforce using `rescue StandardError`
          # instead of `rescue`.
          
          # bad
          begin
            foo
          rescue
            bar
          end
          
          # good
          begin
            foo
          rescue StandardError
            bar
          end
          
          # good
          begin
            foo
          rescue OtherError
            bar
          end
          
          # good
          begin
            foo
          rescue StandardError, SecurityError
            bar
          end

          Empty line detected around arguments.
          Open

          
          Each definition needs to have a different contract for the parameters.
          Severity: Minor
          Found in lib/contracts/method_handler.rb by rubocop

          This cops checks if empty lines exist around the arguments of a method invocation.

          Example:

          # bad
          do_something(
            foo
          
          )
          
          process(bar,
          
                  baz: qux,
                  thud: fred)
          
          some_method(
          
            [1,2,3],
            x: y
          )
          
          # good
          do_something(
            foo
          )
          
          process(bar,
                  baz: qux,
                  thud: fred)
          
          some_method(
            [1,2,3],
            x: y
          )

          Gems should be sorted in an alphabetical order within their section of the Gemfile. Gem codecov should appear before rspec.
          Open

            gem "codecov"
          Severity: Minor
          Found in Gemfile by rubocop

          Gems should be alphabetically sorted within groups.

          Example:

          # bad
          gem 'rubocop'
          gem 'rspec'
          
          # good
          gem 'rspec'
          gem 'rubocop'
          
          # good
          gem 'rubocop'
          
          gem 'rspec'
          
          # good only if TreatCommentsAsGroupSeparators is true
          # For code quality
          gem 'rubocop'
          # For tests
          gem 'rspec'

          Use %i or %I for an array of symbols.
          Open

            gem "rubocop", "~> 0.46", :platform => [:ruby_20, :ruby_21, :ruby_22, :ruby_23]
          Severity: Minor
          Found in Gemfile by rubocop

          This cop can check for array literals made up of symbols that are not using the %i() syntax.

          Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.

          Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of3` will not enforce a style on an array of 2 or fewer elements.

          Example: EnforcedStyle: percent (default)

          # good
          %i[foo bar baz]
          
          # bad
          [:foo, :bar, :baz]

          Example: EnforcedStyle: brackets

          # good
          [:foo, :bar, :baz]
          
          # bad
          %i[foo bar baz]

          Use %i or %I for an array of symbols.
          Open

            gem "byebug", :platform => [:ruby_20, :ruby_21, :ruby_22, :ruby_23, :ruby_24, :ruby_25]
          Severity: Minor
          Found in Gemfile by rubocop

          This cop can check for array literals made up of symbols that are not using the %i() syntax.

          Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.

          Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of3` will not enforce a style on an array of 2 or fewer elements.

          Example: EnforcedStyle: percent (default)

          # good
          %i[foo bar baz]
          
          # bad
          [:foo, :bar, :baz]

          Example: EnforcedStyle: brackets

          # good
          [:foo, :bar, :baz]
          
          # bad
          %i[foo bar baz]

          Avoid comparing a variable with multiple items in a conditional, use Array#include? instead.
          Open

                return :class if klass == Class || klass == Module

          This cop checks against comparing a variable with multiple items, where Array#include? could be used instead to avoid code repetition.

          Example:

          # bad
          a = 'a'
          foo if a == 'a' || a == 'b' || a == 'c'
          
          # good
          a = 'a'
          foo if ['a', 'b', 'c'].include?(a)

          Use uppercase heredoc delimiters.
          Open

                ruby_eval
          Severity: Minor
          Found in lib/contracts/decorators.rb by rubocop

          This cop checks that your heredocs are using the configured case. By default it is configured to enforce uppercase heredocs.

          Example: EnforcedStyle: uppercase (default)

          # bad
          <<-sql
            SELECT * FROM foo
          sql
          
          # good
          <<-SQL
            SELECT * FROM foo
          SQL

          Example: EnforcedStyle: lowercase

          # bad
          <<-SQL
            SELECT * FROM foo
          SQL
          
          # good
          <<-sql
            SELECT * FROM foo
          sql

          FIXME found
          Open

              # FIXME : this looks like untested code (commenting it out doesn't make specs red)
          Severity: Minor
          Found in lib/contracts/method_handler.rb by fixme
          Severity
          Category
          Status
          Source
          Language