NullVoxPopuli/skinny_controllers

View on GitHub

Showing 55 of 55 total issues

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

      def initialize(current_user,
        controller_params, params_for_action = nil,
        action = nil,
        lookup = nil,
        options = {})
Severity: Minor
Found in lib/skinny_controllers/operation/base.rb - About 45 mins to fix

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

          def find_model
            if params[:scope]
              model_from_scope
            elsif (key = params.keys.grep(/\_id$/)).present?
              # hopefully there is only ever one of these passed
    Severity: Minor
    Found in lib/skinny_controllers/operation/model_helpers.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 define_policy_class has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

          def define_policy_class(name)
            default_policy = SkinnyControllers::Policy::Default
            namespace_klass = Object
            # if we are namespaced, we need to get / create the namespace if it doesn't exist already
            if name.include?('::')
    Severity: Minor
    Found in lib/skinny_controllers/lookup/policy.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 model_params has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def model_params
            # for mass-assignment, rails doesn't accept
            # stringified keys.
            # TODO: why did the params hash lose its indifferent access
            unless @model_params
    Severity: Minor
    Found in lib/skinny_controllers/operation/model_helpers.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 namespace_lookup has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def namespace_lookup(qualified_name)
          klass = class_for_qualified_name(qualified_name)
          # Return if the constant exists, or if we can't travel
          # up any higher.
          return klass if klass
    Severity: Minor
    Found in lib/skinny_controllers/lookup/ensure_existence.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

    Avoid parameter lists longer than 5 parameters. [6/5] (https://github.com/bbatsov/ruby-style-guide#too-many-params)
    Open

          def initialize(current_user,
            controller_params, params_for_action = nil,
            action = nil,
            lookup = nil,
            options = {})

    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.

    Add an empty line after magic comments. (https://github.com/bbatsov/ruby-style-guide#separate-magic-comments-from-code)
    Open

    module SkinnyControllers

    Checks for a newline after the final magic comment.

    Example:

    # good
    # frozen_string_literal: true
    
    # Some documentation for Person
    class Person
      # Some code
    end
    
    # bad
    # frozen_string_literal: true
    # Some documentation for Person
    class Person
      # Some code
    end

    Missing magic comment # frozen_string_literal: true.
    Open

    module SkinnyControllers

    This cop is designed to help upgrade to Ruby 3.0. It will add the comment # frozen_string_literal: true to the top of files to enable frozen string literals. Frozen string literals may be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

    Example: EnforcedStyle: when_needed (default)

    # The `when_needed` style will add the frozen string literal comment
    # to files only when the `TargetRubyVersion` is set to 2.3+.
    # bad
    module Foo
      # ...
    end
    
    # good
    # frozen_string_literal: true
    
    module Foo
      # ...
    end

    Example: EnforcedStyle: always

    # The `always` style will always add the frozen string literal comment
    # to a file, regardless of the Ruby version or if `freeze` or `<<` are
    # called on a string literal.
    # bad
    module Bar
      # ...
    end
    
    # good
    # frozen_string_literal: true
    
    module Bar
      # ...
    end

    Example: EnforcedStyle: never

    # The `never` will enforce that the frozen string literal comment does
    # not exist in a file.
    # bad
    # frozen_string_literal: true
    
    module Baz
      # ...
    end
    
    # good
    module Baz
      # ...
    end

    Add an empty line after magic comments. (https://github.com/bbatsov/ruby-style-guide#separate-magic-comments-from-code)
    Open

    module SkinnyControllers

    Checks for a newline after the final magic comment.

    Example:

    # good
    # frozen_string_literal: true
    
    # Some documentation for Person
    class Person
      # Some code
    end
    
    # bad
    # frozen_string_literal: true
    # Some documentation for Person
    class Person
      # Some code
    end

    Use SCREAMING_SNAKE_CASE for constants. (https://github.com/bbatsov/ruby-style-guide#screaming-snake-case)
    Open

        Delete = 'Delete'.freeze

    This cop checks whether constant names are written using SCREAMINGSNAKECASE.

    To avoid false positives, it ignores cases in which we cannot know for certain the type of value that would be assigned to a constant.

    Example:

    # bad
    InchInCm = 2.54
    INCHinCM = 2.54
    Inch_In_Cm = 2.54
    
    # good
    INCH_IN_CM = 2.54

    Use a guard clause instead of wrapping the code inside a conditional expression. (https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals)
    Open

            if scoped = scoped_model(scope)

    Use a guard clause instead of wrapping the code inside a conditional expression

    Example:

    # bad
    def test
      if something
        work
      end
    end
    
    # good
    def test
      return unless something
      work
    end
    
    # also good
    def test
      work if something
    end
    
    # bad
    if something
      raise 'exception'
    else
      ok
    end
    
    # good
    raise 'exception' if something
    ok

    Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||. (https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier)
    Open

              if namespace.presence && namespace != name

    Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?

    Add an empty line after magic comments. (https://github.com/bbatsov/ruby-style-guide#separate-magic-comments-from-code)
    Open

    module SkinnyControllers

    Checks for a newline after the final magic comment.

    Example:

    # good
    # frozen_string_literal: true
    
    # Some documentation for Person
    class Person
      # Some code
    end
    
    # bad
    # frozen_string_literal: true
    # Some documentation for Person
    class Person
      # Some code
    end

    Favor modifier unless usage when having a single-line body. Another good alternative is the usage of control flow &&/||. (https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier)
    Open

            unless default

    Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?

    Add an empty line after magic comments. (https://github.com/bbatsov/ruby-style-guide#separate-magic-comments-from-code)
    Open

    class SkinnyControllerGenerator < Rails::Generators::NamedBase

    Checks for a newline after the final magic comment.

    Example:

    # good
    # frozen_string_literal: true
    
    # Some documentation for Person
    class Person
      # Some code
    end
    
    # bad
    # frozen_string_literal: true
    # Some documentation for Person
    class Person
      # Some code
    end

    Use SCREAMING_SNAKE_CASE for constants. (https://github.com/bbatsov/ruby-style-guide#screaming-snake-case)
    Open

        Read = 'Read'.freeze

    This cop checks whether constant names are written using SCREAMINGSNAKECASE.

    To avoid false positives, it ignores cases in which we cannot know for certain the type of value that would be assigned to a constant.

    Example:

    # bad
    InchInCm = 2.54
    INCHinCM = 2.54
    Inch_In_Cm = 2.54
    
    # good
    INCH_IN_CM = 2.54

    Do not freeze immutable objects, as freezing them has no effect.
    Open

        Create = 'Create'.freeze

    This cop check for uses of Object#freeze on immutable objects.

    Example:

    # bad
    CONST = 1.freeze
    
    # good
    CONST = 1

    Add an empty line after magic comments. (https://github.com/bbatsov/ruby-style-guide#separate-magic-comments-from-code)
    Open

    module SkinnyControllers
    Severity: Minor
    Found in lib/skinny_controllers/version.rb by rubocop

    Checks for a newline after the final magic comment.

    Example:

    # good
    # frozen_string_literal: true
    
    # Some documentation for Person
    class Person
      # Some code
    end
    
    # bad
    # frozen_string_literal: true
    # Some documentation for Person
    class Person
      # Some code
    end

    Add an empty line after magic comments. (https://github.com/bbatsov/ruby-style-guide#separate-magic-comments-from-code)
    Open

    require 'bundler/gem_tasks'
    Severity: Minor
    Found in Rakefile by rubocop

    Checks for a newline after the final magic comment.

    Example:

    # good
    # frozen_string_literal: true
    
    # Some documentation for Person
    class Person
      # Some code
    end
    
    # bad
    # frozen_string_literal: true
    # Some documentation for Person
    class Person
      # Some code
    end

    Do not freeze immutable objects, as freezing them has no effect.
    Open

        Delete = 'Delete'.freeze

    This cop check for uses of Object#freeze on immutable objects.

    Example:

    # bad
    CONST = 1.freeze
    
    # good
    CONST = 1
    Severity
    Category
    Status
    Source
    Language