sitepress/sitepress

View on GitHub

Showing 22 of 22 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
      status "Building #{site.root_path.expand_path} to #{root_path.expand_path}"
      resources.each do |resource, path|
        if resource.renderable?
          status "Rendering #{path}"
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
      private_layout_method = self.method(:_layout)
      layout =
        if Rails.version >= "6"
          private_layout_method.call lookup_context, current_resource_rails_formats
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 error (Using Ruby 2.2 parser; configure using TargetRubyVersion parameter, under AllCops)
Open

      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

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

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

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

        format_extension = path.format&.to_s

Unused method argument - site.
Open

    def sitepress_root(site: Sitepress.site, controller: DEFAULT_CONTROLLER, action: DEFAULT_ACTION)

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 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

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

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

TODO found
Open

    # TODO: When `type: :all` is scoped, some queries will mistakenly return single resources.

TODO found
Open

    # TODO: Put a better extension/mime_type handler into resource tree, then instead of faltening

TODO found
Open

  # TODO: Redo this to use File readline and pos to

TODO found
Open

      # TODO: I don't want to look this up everytime I try to figure out the
Severity: Minor
Found in sitepress-core/lib/sitepress/path.rb by fixme
Severity
Category
Status
Source
Language