sitepress/sitepress

View on GitHub

Showing 23 of 23 total issues

Cyclomatic complexity for request_filename is too high. [8/6]
Open

    def request_filename
      if node.root? and node.default_format == format
        ""
      elsif node.root? and format
        "#{node.default_name}.#{format}"

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 resolve_layout is too high. [7/6]
Open

        def resolve_layout
          return resource.data.fetch("layout") if resource.data.key? "layout"
          return layout unless has_layout_conditions?

          clause, formats = layout_conditions.first

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 compile has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

      def compile
        before_compile
        each do |resource, *args, **kwargs|
          if resource.renderable?
            render_resource(resource, *args, **kwargs)
Severity: Minor
Found in sitepress-rails/lib/sitepress/compiler.rb - About 55 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 resolve_layout has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

        def resolve_layout
          return resource.data.fetch("layout") if resource.data.key? "layout"
          return layout unless has_layout_conditions?

          clause, formats = layout_conditions.first
Severity: Minor
Found in sitepress-rails/lib/sitepress/renderers/controller.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 request_filename has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def request_filename
      if node.root? and node.default_format == format
        ""
      elsif node.root? and format
        "#{node.default_name}.#{format}"
Severity: Minor
Found in sitepress-core/lib/sitepress/resource.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 controller_layout has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def controller_layout(resource)
      private_layout_method = self.method(:_layout)
      layout =
        if Rails.version >= "6"
          private_layout_method.call lookup_context, resource_rails_formats(resource)
Severity: Minor
Found in sitepress-rails/rails/app/controllers/concerns/sitepress/site_pages.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 parse_basename has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def parse_basename
        base = basename
        filename, extname = split_filename(base)

        # This is a root path, so we have to treat it a little differently
Severity: Minor
Found in sitepress-core/lib/sitepress/path.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

unexpected token kRESCUE (Using Ruby 2.2 parser; configure using TargetRubyVersion parameter, under AllCops)
Open

        rescue

Unused method argument - glob. If it's necessary, use _ or _glob as an argument name to indicate that it won't be used. You can also write as all(*) if you want the method to accept any arguments but don't care about them.
Open

    def self.all(glob = "**/*.gemspec")
Severity: Minor
Found in support/project.rb by rubocop

This cop checks for unused method arguments.

Example:

# bad

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Example:

# good

def some_method(used, _unused, _unused_but_allowed)
  puts used
end

unexpected token error (Using Ruby 2.2 parser; configure using TargetRubyVersion parameter, under AllCops)
Open

        format_extension = path.format&.to_s

Useless assignment to variable - code. Use _ or _code as a variable name to indicate that it won't be used.
Open

        code, headers, response = rails_app.routes.call env

This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Method Sitepress::Rendition#layout is defined at both sitepress-rails/lib/sitepress/rendition.rb:6 and sitepress-rails/lib/sitepress/rendition.rb:24.
Open

    def layout

This cop checks for duplicated instance (or singleton) method definitions.

Example:

# bad

def duplicated
  1
end

def duplicated
  2
end

Example:

# bad

def duplicated
  1
end

alias duplicated other_duplicated

Example:

# good

def duplicated
  1
end

def other_duplicated
  2
end

Unused method argument - title_key.
Open

  def link_to_page(page, *args, title_key: DEFAULT_TITLE_KEY, **kwargs, &block)

This cop checks for unused method arguments.

Example:

# bad

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Example:

# good

def some_method(used, _unused, _unused_but_allowed)
  puts used
end

Unused method argument - layout.
Open

    def initialize(resource, layout: nil)

This cop checks for unused method arguments.

Example:

# bad

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Example:

# good

def some_method(used, _unused, _unused_but_allowed)
  puts used
end

unexpected token error (Using Ruby 2.2 parser; configure using TargetRubyVersion parameter, under AllCops)
Open

      (handler_is_format? ? handler : @format)&.to_sym

Useless assignment to variable - headers. Use _ or _headers as a variable name to indicate that it won't be used.
Open

        code, headers, response = rails_app.routes.call env

This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

end at 55, 6 is not aligned with if at 49, 48.
Open

      end

This cop checks whether the end keywords are aligned properly.

Three modes are supported through the EnforcedStyleAlignWith configuration parameter:

If it's set to keyword (which is the default), the end shall be aligned with the start of the keyword (if, class, etc.).

If it's set to variable the end shall be aligned with the left-hand-side of the variable assignment, if there is one.

If it's set to start_of_line, the end shall be aligned with the start of the line where the matching keyword appears.

Example: EnforcedStyleAlignWith: keyword (default)

# bad

variable = if true
    end

# good

variable = if true
           end

Example: EnforcedStyleAlignWith: variable

# bad

variable = if true
    end

# good

variable = if true
end

Example: EnforcedStyleAlignWith: startofline

# bad

variable = if true
    end

# good

puts(if true
end)

Method Sitepress::Resource.path_suffix_hack_that_you_should_not_use is defined at both sitepress-core/lib/sitepress/resource.rb:107 and sitepress-core/lib/sitepress/resource.rb:109.
Open

      def path_suffix_hack_that_you_should_not_use

This cop checks for duplicated instance (or singleton) method definitions.

Example:

# bad

def duplicated
  1
end

def duplicated
  2
end

Example:

# bad

def duplicated
  1
end

alias duplicated other_duplicated

Example:

# good

def duplicated
  1
end

def other_duplicated
  2
end

unexpected token error (Using Ruby 2.2 parser; configure using TargetRubyVersion parameter, under AllCops)
Open

      format&.to_sym

TODO found
Open

    # TODO: When `type: :all` is scoped, some queries will mistakenly return single resources.
Severity
Category
Status
Source
Language