shioyama/mobility

View on GitHub

Showing 14 of 46 total issues

Method has too many lines. [41/30]
Open

      def self.included(base)
        base.class_eval do
          plugin :validation_helpers

          # Paraphased from sequel_polymorphic gem
Severity: Minor
Found in lib/mobility/sequel/translation.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method included has a Cognitive Complexity of 16 (exceeds 6 allowed). Consider refactoring.
Open

      def self.included(base)
        base.class_eval do
          plugin :validation_helpers

          # Paraphased from sequel_polymorphic gem
Severity: Minor
Found in lib/mobility/sequel/translation.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

Cyclomatic complexity for extended is too high. [7/6]
Open

    def extended(model_class)
      return if model_class.respond_to? :mobility_accessor

      model_class.extend Translates
      model_class.extend ClassMethods
Severity: Minor
Found in lib/mobility.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Cyclomatic complexity for define_fallthrough_accessors is too high. [7/6]
Open

      def define_fallthrough_accessors(*names)
        method_name_regex = /\A(#{names.join('|')})_([a-z]{2}(_[a-z]{2})?)(=?|\??)\z/.freeze

        define_method :method_missing do |method_name, *args, &block|
          if method_name =~ method_name_regex

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Cyclomatic complexity for included is too high. [7/6]
Open

      def self.included(base)
        base.class_eval do
          plugin :validation_helpers

          # Paraphased from sequel_polymorphic gem
Severity: Minor
Found in lib/mobility/sequel/translation.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Method validate_each has a Cognitive Complexity of 15 (exceeds 6 allowed). Consider refactoring.
Open

      def validate_each(record, attribute, value)
        klass = record.class

        if ([*options[:scope]] + [attribute]).any? { |name| klass.mobility_attribute?(name) }
          return unless value.present?
Severity: Minor
Found in lib/mobility/active_record/uniqueness_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 prepare_for_invocation has a Cognitive Complexity of 13 (exceeds 6 allowed). Consider refactoring.
Open

    def self.prepare_for_invocation(name, value)
      if name == :backend
        if SUPPORTED_BACKENDS.include?(value)
          require_relative "./backend_generators/#{value}_backend"
          Mobility::BackendGenerators.const_get("#{value}_backend".camelcase.freeze)
Severity: Minor
Found in lib/rails/generators/mobility/translations_generator.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 define_read has a Cognitive Complexity of 9 (exceeds 6 allowed). Consider refactoring.
Open

        def define_read(fallbacks)
          define_method :read do |locale, fallback: true, **options|
            return super(locale, options) if !fallback || options[:locale]

            locales = fallback == true ? fallbacks[locale] : [locale, *fallback]
Severity: Minor
Found in lib/mobility/plugins/fallbacks.rb - About 45 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 serializer_for has a Cognitive Complexity of 9 (exceeds 6 allowed). Consider refactoring.
Open

        def serializer_for(format)
          lambda do |obj|
            return if obj.nil?
            if obj.is_a? ::Hash
              obj = obj.inject({}) do |translations, (locale, value)|
Severity: Minor
Found in lib/mobility/backends/serialized.rb - About 45 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 save_translations has a Cognitive Complexity of 7 (exceeds 6 allowed). Consider refactoring.
Open

      def save_translations
        cache.each_value do |translation|
          next unless present?(translation.value)
          translation.id ? translation.save : model.send("add_#{singularize(association_name)}", translation)
        end
Severity: Minor
Found in lib/mobility/backends/sequel/key_value.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 configure has a Cognitive Complexity of 7 (exceeds 6 allowed). Consider refactoring.
Open

        def configure(options)
          raise CacheRequired, "Cache required for Sequel::Table backend" if options[:cache] == false
          table_name = Util.singularize(options[:model_class].table_name)
          options[:table_name]  ||= :"#{table_name}_translations"
          options[:foreign_key] ||= Util.foreign_key(Util.camelize(table_name.downcase))
Severity: Minor
Found in lib/mobility/backends/sequel/table.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

Shadowing outer local variable - id_map.
Open

              id_map.each do |klass_name, id_map|
Severity: Minor
Found in lib/mobility/sequel/translation.rb by rubocop

This cop looks for use of the same name as outer local variables for block arguments or block local variables. This is a mimic of the warning "shadowing outer local variable - foo" from ruby -cw.

Example:

# bad

def some_method
  foo = 1

  2.times do |foo| # shadowing outer `foo`
    do_something(foo)
  end
end

Example:

# good

def some_method
  foo = 1

  2.times do |bar|
    do_something(bar)
  end
end

Shadowing outer local variable - model.
Open

              eo[:rows].each do |model|
Severity: Minor
Found in lib/mobility/sequel/translation.rb by rubocop

This cop looks for use of the same name as outer local variables for block arguments or block local variables. This is a mimic of the warning "shadowing outer local variable - foo" from ruby -cw.

Example:

# bad

def some_method
  foo = 1

  2.times do |foo| # shadowing outer `foo`
    do_something(foo)
  end
end

Example:

# good

def some_method
  foo = 1

  2.times do |bar|
    do_something(bar)
  end
end

Shadowing outer local variable - model.
Open

                  id_map[related_obj.pk].each do |model|
Severity: Minor
Found in lib/mobility/sequel/translation.rb by rubocop

This cop looks for use of the same name as outer local variables for block arguments or block local variables. This is a mimic of the warning "shadowing outer local variable - foo" from ruby -cw.

Example:

# bad

def some_method
  foo = 1

  2.times do |foo| # shadowing outer `foo`
    do_something(foo)
  end
end

Example:

# good

def some_method
  foo = 1

  2.times do |bar|
    do_something(bar)
  end
end
Severity
Category
Status
Source
Language