rambler-digital-solutions/Generamba

View on GitHub
lib/generamba/code_generation/content_generator.rb

Summary

Maintainability
A
0 mins
Test Coverage

Assignment Branch Condition size for create_file is too high. [18.03/15]
Open

        def self.create_file(file, scope, template)
            file_source = IO.read(template.template_path.join(file[TEMPLATE_FILE_PATH_KEY]))
            Liquid::Template.file_system = Liquid::LocalFileSystem.new(template.template_path.join('snippets'), '%s.liquid')

            template = Liquid::Template.parse(file_source)

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method has too many lines. [12/10]
Open

        def self.create_file(file, scope, template)
            file_source = IO.read(template.template_path.join(file[TEMPLATE_FILE_PATH_KEY]))
            Liquid::Template.file_system = Liquid::LocalFileSystem.new(template.template_path.join('snippets'), '%s.liquid')

            template = Liquid::Template.parse(file_source)

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.

Use 2 (not 1) spaces for indentation.
Open

            template_default_text = '{{ prefix }}{{ module_info.name }}{{ module_info.file_basename }}'

This cops checks for indentation that doesn't use the specified number of spaces.

See also the IndentationConsistency cop which is the companion to this one.

Example:

# bad
class A
 def test
  puts 'hello'
 end
end

# good
class A
  def test
    puts 'hello'
  end
end

Example: IgnoredPatterns: ['^\s*module']

# bad
module A
class B
  def test
  puts 'hello'
  end
end
end

# good
module A
class B
  def test
    puts 'hello'
  end
end
end

Tab detected.
Open

        def self.create_file(file, scope, template)

Redundant return detected. To return multiple values, use an array.
Open

            return file_name, content

This cop checks for redundant return expressions.

Example:

def test
  return something
end

def test
  one
  two
  three
  return something
end

It should be extended to handle methods whose body is if/else or a case expression with a default branch.

Tab detected.
Open

            template_default_text = '{{ prefix }}{{ module_info.name }}{{ module_info.file_basename }}'

Tab detected.
Open

        end

Trailing whitespace detected.
Open

    

Line is too long. [94/80]
Open

            template_default_text = '{{ prefix }}{{ module_info.name }}{{ module_info.file_basename }}'

Tab detected.
Open

            

Incorrect indentation detected (column 2 instead of 1).
Open

  # Responsible for generating code using provided liquid templates

This cops checks the indentation of comments.

Example:

# bad
  # comment here
def method_name
end

  # comment here
a = 'hello'

# yet another comment
  if true
    true
  end

# good
# comment here
def method_name
end

# comment here
a = 'hello'

# yet another comment
if true
  true
end

Use 2 (not 1) spaces for indentation.
Open

    class ContentGenerator

This cops checks for indentation that doesn't use the specified number of spaces.

See also the IndentationConsistency cop which is the companion to this one.

Example:

# bad
class A
 def test
  puts 'hello'
 end
end

# good
class A
  def test
    puts 'hello'
  end
end

Example: IgnoredPatterns: ['^\s*module']

# bad
module A
class B
  def test
  puts 'hello'
  end
end
end

# good
module A
class B
  def test
    puts 'hello'
  end
end
end

Tab detected.
Open

            module_info['file_basename'] = file_basename

Incorrect indentation detected (column 4 instead of 2).
Open

    # @return [String], [String] The generated file_name and body

This cops checks the indentation of comments.

Example:

# bad
  # comment here
def method_name
end

  # comment here
a = 'hello'

# yet another comment
  if true
    true
  end

# good
# comment here
def method_name
end

# comment here
a = 'hello'

# yet another comment
if true
  true
end

Line is too long. [115/80]
Open

            Liquid::Template.file_system = Liquid::LocalFileSystem.new(template.template_path.join('snippets'), '%s.liquid')

Line is too long. [87/80]
Open

    # @param file [Hash<String,String>] A hashmap with template's filename and filepath

Redundant self detected.
Open

            filename_template = self.file_name_template(file)

This cop checks for redundant uses of self.

The usage of self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

  • Calling an attribute writer to prevent an local variable assignment.

Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

Note we allow uses of self with operators because it would be awkward otherwise.

Example:

# bad
def foo(bar)
  self.baz
end

# good
def foo(bar)
  self.bar  # Resolves name clash with the argument.
end

def foo
  bar = 1
  self.bar  # Resolves name clash with the local variable.
end

def foo
  %w[x y z].select do |bar|
    self.bar == bar  # Resolves name clash with argument of the block.
  end
end

Tab detected.
Open

    end

Tab detected.
Open

            return Liquid::Template.parse(template_text)

Tab detected.
Open

            Liquid::Template.file_system = Liquid::LocalFileSystem.new(template.template_path.join('snippets'), '%s.liquid')

Tab detected.
Open

            file_name = filename_template.render(scope)

Tab detected.
Open

            return file_name, content

Trailing whitespace detected.
Open

      

Redundant return detected.
Open

            return Liquid::Template.parse(template_text)

This cop checks for redundant return expressions.

Example:

def test
  return something
end

def test
  one
  two
  three
  return something
end

It should be extended to handle methods whose body is if/else or a case expression with a default branch.

Use 2 (not 1) spaces for indentation.
Open

        def self.create_file(file, scope, template)

This cops checks for indentation that doesn't use the specified number of spaces.

See also the IndentationConsistency cop which is the companion to this one.

Example:

# bad
class A
 def test
  puts 'hello'
 end
end

# good
class A
  def test
    puts 'hello'
  end
end

Example: IgnoredPatterns: ['^\s*module']

# bad
module A
class B
  def test
  puts 'hello'
  end
end
end

# good
module A
class B
  def test
    puts 'hello'
  end
end
end

Tab detected.
Open

            filename_template = self.file_name_template(file)

Tab detected.
Open

            module_info = scope['module_info']

Tab detected.
Open

    class ContentGenerator

Tab detected.
Open

            file_source = IO.read(template.template_path.join(file[TEMPLATE_FILE_PATH_KEY]))

Tab detected.
Open

            module_info['file_name'] = file_name

Tab detected.
Open

            content = template.render(scope)

Line is too long. [105/80]
Open

    # @param template [ModuleTemplate] The model describing a Generamba template used for code generation

Tab detected.
Open

            file_basename = File.basename(file[TEMPLATE_FILE_NAME_KEY])

Tab detected.
Open

            module_info.delete('file_basename')

Tab detected.
Open

        def self.file_name_template(file)

Tab detected.
Open

            template_text = file[TEMPLATE_FILE_CUSTOM_NAME_KEY] || template_default_text

Extra empty line detected at class body beginning.
Open


    # Generates and returns a filename and a body of a specific code file.

This cops checks if empty lines around the bodies of classes match the configuration.

Example: EnforcedStyle: empty_lines

# good

class Foo

  def bar
    # ...
  end

end

Example: EnforcedStyle: emptylinesexcept_namespace

# good

class Foo
  class Bar

    # ...

  end
end

Example: EnforcedStyle: emptylinesspecial

# good
class Foo

  def bar; end

end

Example: EnforcedStyle: noemptylines (default)

# good

class Foo
  def bar
    # ...
  end
end

Tab detected.
Open

            template = Liquid::Template.parse(file_source)

Trailing whitespace detected.
Open

            

Line is too long. [83/80]
Open

            file_source = IO.read(template.template_path.join(file[TEMPLATE_FILE_PATH_KEY]))

Extra empty line detected at module body beginning.
Open


  # Responsible for generating code using provided liquid templates

This cops checks if empty lines around the bodies of modules match the configuration.

Example: EnforcedStyle: empty_lines

# good

module Foo

  def bar
    # ...
  end

end

Example: EnforcedStyle: emptylinesexcept_namespace

# good

module Foo
  module Bar

    # ...

  end
end

Example: EnforcedStyle: emptylinesspecial

# good
module Foo

  def bar; end

end

Example: EnforcedStyle: noemptylines (default)

# good

module Foo
  def bar
    # ...
  end
end

Use 2 (not 1) spaces for indentation.
Open

            file_source = IO.read(template.template_path.join(file[TEMPLATE_FILE_PATH_KEY]))

This cops checks for indentation that doesn't use the specified number of spaces.

See also the IndentationConsistency cop which is the companion to this one.

Example:

# bad
class A
 def test
  puts 'hello'
 end
end

# good
class A
  def test
    puts 'hello'
  end
end

Example: IgnoredPatterns: ['^\s*module']

# bad
module A
class B
  def test
  puts 'hello'
  end
end
end

# good
module A
class B
  def test
    puts 'hello'
  end
end
end

Tab detected.
Open

        end

There are no issues that match your filters.

Category
Status