distil/jserializer

View on GitHub

Showing 21 of 21 total issues

Class has too many lines. [145/100]
Open

  class Base
    @_attributes = {}
    @_embed = :objects

    class << self
Severity: Minor
Found in lib/jserializer/base.rb by rubocop

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

Class Base has 23 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Base
    @_attributes = {}
    @_embed = :objects

    class << self
Severity: Minor
Found in lib/jserializer/base.rb - About 2 hrs to fix

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

          def _build_association(name, type, key, serializer, embed, embed_key)
    Severity: Minor
    Found in lib/jserializer/base.rb - About 45 mins to fix

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

            it 'sets scope through option[:scope]' do
              user = User.new(123, 'Sam', 'abc', 'top_secret', false)
              account = Account.new(1, 'New Account', 85)
              serializer = AccountSerializer.new(account, scope: user)
              result = serializer.serializable_hash
      Severity: Minor
      Found in test/options_test.rb and 1 other location - About 40 mins to fix
      test/options_test.rb on lines 56..62

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 38.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

            it 'sets scope through option[:current_user]' do
              user = User.new(123, 'Sam', 'abc', 'top_secret', false)
              account = Account.new(1, 'New Account', 85)
              serializer = AccountSerializer.new(account, current_user: user)
              result = serializer.serializable_hash
      Severity: Minor
      Found in test/options_test.rb and 1 other location - About 40 mins to fix
      test/options_test.rb on lines 47..53

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 38.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

            it 'renames attribute key with embed ids' do
              blog = build_a_blog(total_posts: 4, comments_per_post: 5)
              serializer = BlogEmbedKeyWithKeySerializer.new(blog)
              result = serializer.serializable_hash
              assert_equal([:article_ids, :account], result.keys)
      Severity: Minor
      Found in test/association_test.rb and 1 other location - About 30 mins to fix
      test/association_test.rb on lines 262..267

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 33.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

            it 'replaces _ids with embed_key option in has_many statement' do
              blog = build_a_blog(total_posts: 4, comments_per_post: 5)
              serializer = BlogEmbedKeyHasManySerializer.new(blog)
              result = serializer.serializable_hash
              assert_equal([:post_ids, :account], result.keys)
      Severity: Minor
      Found in test/association_test.rb and 1 other location - About 30 mins to fix
      test/association_test.rb on lines 278..283

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 33.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          it 'adds attributes through #attribute or #attributes class methods' do
            person = Person.new('Sam', 20, 'M')
            serializer = PersonSerializer.new(person)
            result = serializer.serializable_hash
            assert_equal([:name, :age, :gender], result.keys)
      Severity: Minor
      Found in test/attribute_test.rb and 1 other location - About 25 mins to fix
      test/attribute_test.rb on lines 52..57

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 31.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          it 'renames the attribute with the :key option' do
            person = Person.new('Sam', 20, 'M')
            serializer = PersonWithKeySerializer.new(person)
            result = serializer.serializable_hash
            assert_equal([:name, :age, :type], result.keys)
      Severity: Minor
      Found in test/attribute_test.rb and 1 other location - About 25 mins to fix
      test/attribute_test.rb on lines 44..49

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 31.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Avoid parameter lists longer than 5 parameters. [6/5]
      Open

            def _build_association(name, type, key, serializer, embed, embed_key)
      Severity: Minor
      Found in lib/jserializer/base.rb by rubocop

      This cop checks for methods with too many parameters. The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count.

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

          def as_json(options = {})
            root = options.key?(:root) ? options[:root] : true
            hash = if root && root_name
                     { root_name => serializable_hash }
                   else
      Severity: Minor
      Found in lib/jserializer/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

      Similar blocks of code found in 3 locations. Consider refactoring.
      Open

            result[:post_comments].each.with_index(1) do |comment, i|
              assert_equal([:id, :body, :who], comment.keys)
              assert_equal([i, "This is comment ##{i}", "User #{i}"], comment.values)
      Severity: Minor
      Found in test/association_test.rb and 2 other locations - About 20 mins to fix
      test/association_test.rb on lines 146..148
      test/association_test.rb on lines 210..212

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 27.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 3 locations. Consider refactoring.
      Open

            result[:comments].each.with_index(1) do |comment, i|
              assert_equal([:id, :body, :who], comment.keys)
              assert_equal([i, "This is comment ##{i}", "User #{i}"], comment.values)
      Severity: Minor
      Found in test/association_test.rb and 2 other locations - About 20 mins to fix
      test/association_test.rb on lines 146..148
      test/association_test.rb on lines 192..194

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 27.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 3 locations. Consider refactoring.
      Open

            result[:comments].each.with_index(1) do |comment, i|
              assert_equal([:id, :body, :who], comment.keys)
              assert_equal([i, "This is comment ##{i}", "User #{i}"], comment.values)
      Severity: Minor
      Found in test/association_test.rb and 2 other locations - About 20 mins to fix
      test/association_test.rb on lines 192..194
      test/association_test.rb on lines 210..212

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 27.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Rename has_many to many?.
      Open

            def has_many(name, serializer: nil, key: nil, embed: nil, embed_key: nil)
      Severity: Minor
      Found in lib/jserializer/base.rb by rubocop

      This cop makes sure that predicates are named properly.

      Example:

      # bad
      def is_even?(value)
      end
      
      # good
      def even?(value)
      end
      
      # bad
      def has_value?
      end
      
      # good
      def value?
      end

      Argument post was shadowed by a local variable before it was used.
      Open

              post = Post.new(i, "Post #{i}", "Text #{i}")
      Severity: Minor
      Found in test/association_test.rb by rubocop

      This cop checks for shadowed arguments.

      This cop has IgnoreImplicitReferences configuration option. It means argument shadowing is used in order to pass parameters to zero arity super when IgnoreImplicitReferences is true.

      Example:

      # bad
      do_something do |foo|
        foo = 42
        puts foo
      end
      
      def do_something(foo)
        foo = 42
        puts foo
      end
      
      # good
      do_something do |foo|
        foo = foo + 42
        puts foo
      end
      
      def do_something(foo)
        foo = foo + 42
        puts foo
      end
      
      def do_something(foo)
        puts foo
      end

      Example: IgnoreImplicitReferences: false (default)

      # bad
      def do_something(foo)
        foo = 42
        super
      end
      
      def do_something(foo)
        foo = super
        bar
      end

      Example: IgnoreImplicitReferences: true

      # good
      def do_something(foo)
        foo = 42
        super
      end
      
      def do_something(foo)
        foo = super
        bar
      end

      Missing top-level class documentation comment.
      Open

        class Base
      Severity: Minor
      Found in lib/jserializer/base.rb by rubocop

      This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

      The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

      Example:

      # bad
      class Person
        # ...
      end
      
      # good
      # Description/Explanation of Person class
      class Person
        # ...
      end

      Use alias current_user scope instead of alias :current_user :scope.
      Open

          alias :current_user :scope
      Severity: Minor
      Found in lib/jserializer/base.rb by rubocop

      This cop enforces the use of either #alias or #alias_method depending on configuration. It also flags uses of alias :symbol rather than alias bareword.

      Example: EnforcedStyle: prefer_alias (default)

      # bad
      alias_method :bar, :foo
      alias :bar :foo
      
      # good
      alias bar foo

      Example: EnforcedStyle: preferaliasmethod

      # bad
      alias :bar :foo
      alias bar foo
      
      # good
      alias_method :bar, :foo

      Rename has_one to one?.
      Open

            def has_one(name, serializer: nil, key: nil, embed: nil, embed_key: nil)
      Severity: Minor
      Found in lib/jserializer/base.rb by rubocop

      This cop makes sure that predicates are named properly.

      Example:

      # bad
      def is_even?(value)
      end
      
      # good
      def even?(value)
      end
      
      # bad
      def has_value?
      end
      
      # good
      def value?
      end

      Missing top-level class documentation comment.
      Open

        class Association
      Severity: Minor
      Found in lib/jserializer/association.rb by rubocop

      This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

      The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

      Example:

      # bad
      class Person
        # ...
      end
      
      # good
      # Description/Explanation of Person class
      class Person
        # ...
      end
      Severity
      Category
      Status
      Source
      Language