lib/old_tasks/tools.rake

Summary

Maintainability
Test Coverage

Block has too many lines. [404/25]
Open

namespace :kete do
  namespace :tools do
    desc 'Restart application (Passenger specific)'
    task :restart do
      restart_result = system("touch #{RAILS_ROOT}/tmp/restart.txt")
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Block has too many lines. [402/25]
Open

  namespace :tools do
    desc 'Restart application (Passenger specific)'
    task :restart do
      restart_result = system("touch #{RAILS_ROOT}/tmp/restart.txt")
      if restart_result
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Block has too many lines. [111/25]
Open

    namespace :topics do
      desc "Given a passed in CONDITIONS string (conditions in sql form), move topics that fit CONDITIONS to TARGET (as specified by passed in id) and also USER for id that should be attributed with the move actions. E.g. 'rake kete:tools:topics:move_to_basket TARGET=6 CONDITIONS=\"topic_type_id = 4\" USER=1'. You can optionally specify whether zoom records should be built progressively with ZOOM=true (false by default). If you have a large number of topics that match CONDITIONS, you may want to alter this task to handle batches (otherwise you risk memory issues). Other thing to keep in mind is that this doesn't currently leave any sort of redirect behind for a moved item. Best done before you have a public site. Also Comments are not currently dealt with here."
      task move_to_basket: :environment do
        to_basket = Basket.find(ENV['TARGET'])
        target_basket_path = to_basket.urlified_name
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Block has too many lines. [108/25]
Open

      task move_to_basket: :environment do
        to_basket = Basket.find(ENV['TARGET'])
        target_basket_path = to_basket.urlified_name

        # gather topics
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Block has too many lines. [85/25]
Open

        topics.each do |topic|
          @logger.info('Topic: ' + topic.id.to_s)

          show_path_stub = '/topics/show/' + topic.id.to_s + '-'
          old_basket = topic.basket
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Block has too many lines. [68/25]
Open

    namespace :tiny_mce do
      desc 'Do everything that we need done, like adding data to the db, for an upgrade.'
      task configure_imageselector: [
        'kete:tools:tiny_mce:write_default_imageselector_providers_json',
        'kete:tools:tiny_mce:write_default_imageselector_sizes_json']
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Block has too many lines. [61/25]
Open

            kinds_to_process.each do |kind|
              kind_count = topic.send(kind.to_sym).count
              @logger.info("number of related #{kind}: " + kind_count.to_s)
              next if kind_count == 0

Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Assignment Branch Condition size for image_file_match_image_size? is too high. [26.65/15]
Open

    def image_file_match_image_size?(image_file)
      # get what the imags sizes should be
      size_string = SystemSetting.image_sizes[image_file.thumbnail.to_sym]

      # in the case that SystemSetting.image_sizes no longer has the sizes for existing image, skip it
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

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. [15/10]
Open

    def image_file_match_image_size?(image_file)
      # get what the imags sizes should be
      size_string = SystemSetting.image_sizes[image_file.thumbnail.to_sym]

      # in the case that SystemSetting.image_sizes no longer has the sizes for existing image, skip it
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

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.

Block has too many lines. [46/25]
Open

    task resize_images: :environment do
      @logger = Logger.new(RAILS_ROOT + "/log/resize_images_#{Time.now.strftime('%Y-%m-%d_%H:%M:%S')}.log")

      puts 'Resizing/created images based on SystemSetting.image_sizes...'
      @logger.info 'Starting image file resizing.'
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Assignment Branch Condition size for resize_image_from_original is too high. [18/15]
Open

    def resize_image_from_original(image_file, original_file)
      @logger.info "      Resizing child image #{image_file.id} based on #{original_file}"
      ImageFile.with_image original_file do |img|
        image_file.resize_image(img, SystemSetting.image_sizes[image_file.thumbnail.to_sym])
        image_file.send :destroy_file, image_file.full_filename
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

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 resize_image_from_original(image_file, original_file)
      @logger.info "      Resizing child image #{image_file.id} based on #{original_file}"
      ImageFile.with_image original_file do |img|
        image_file.resize_image(img, SystemSetting.image_sizes[image_file.thumbnail.to_sym])
        image_file.send :destroy_file, image_file.full_filename
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

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.

Perceived complexity for image_file_match_image_size? is too high. [8/7]
Open

    def image_file_match_image_size?(image_file)
      # get what the imags sizes should be
      size_string = SystemSetting.image_sizes[image_file.thumbnail.to_sym]

      # in the case that SystemSetting.image_sizes no longer has the sizes for existing image, skip it
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Block has too many lines. [37/25]
Open

      task write_default_imageselector_providers_json: :environment do
        return unless Kete.is_configured?

        this_site_config = {
          title: SystemSetting.pretty_site_name,
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Block has too many lines. [30/25]
Open

      ImageFile.all(conditions: ['parent_id IS NULL']).each do |parent_image_file|
        @logger.info "  Fetched parent image #{parent_image_file.id}"

        # start an array with all thumbnail keys and remove ones as we go through
        missing_image_size_keys = image_size_keys.dup
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Block has too many lines. [27/25]
Open

    namespace :locales do
      desc 'Make a timestamped copy of specified locale if there are changes from last backup. THIS=[language_code] e.g. rake kete:tools:locales:backup_for THIS=zh'
      task :backup_for do
        locale = ENV['THIS']
        path_stub = "#{Rails.root}/config/locales/"
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Avoid more than 3 levels of block nesting.
Open

                    if item_successful
                      item.reload
                      item.add_as_contributor(user, item.version)

                      # update search record for related item
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

TODO found
Open

      # TODO: in the future, we want to allow users to specify if image files and db
Severity: Minor
Found in lib/old_tasks/tools.rake by fixme

Use kind_count_so_far.positive? instead of kind_count_so_far > 0.
Open

                if kind_count_so_far > 0
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop checks for usage of comparison operators (==, >, <) to test numbers as zero, positive, or negative. These can be replaced by their respective predicate methods. The cop can also be configured to do the reverse.

The cop disregards #nonzero? as it its value is truthy or falsey, but not true and false, and thus not always interchangeable with != 0.

The cop ignores comparisons to global variables, since they are often populated with objects which can be compared with integers, but are not themselves Interger polymorphic.

Example: EnforcedStyle: predicate (default)

# bad

foo == 0
0 > foo
bar.baz > 0

# good

foo.zero?
foo.negative?
bar.baz.positive?

Example: EnforcedStyle: comparison

# bad

foo.zero?
foo.negative?
bar.baz.positive?

# good

foo == 0
0 > foo
bar.baz > 0

%w-literals should be delimited by [ and ].
Open

          %w{inset below sidebar}.each do |setting|
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop enforces the consistent usage of %-literal delimiters.

Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

Example:

# Style/PercentLiteralDelimiters:
#   PreferredDelimiters:
#     default: '[]'
#     '%i':    '()'

# good
%w[alpha beta] + %i(gamma delta)

# bad
%W(alpha #{beta})

# bad
%I(alpha beta)

Unused method argument - block. If it's necessary, use _ or _block as an argument name to indicate that it won't be used.
Open

    def each_item_with_private_version(item_class, &block)
Severity: Minor
Found in lib/old_tasks/tools.rake 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

Prefer using YAML.safe_load over YAML.load.
Open

        current_data = YAML.load(item.private_version_serialized)
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop checks for the use of YAML class methods which have potential security issues leading to remote code execution when loading from an untrusted source.

Example:

# bad
YAML.load("--- foo")

# good
YAML.safe_load("--- foo")
YAML.dump("foo")

Use kind_count.zero? instead of kind_count == 0.
Open

              next if kind_count == 0
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop checks for usage of comparison operators (==, >, <) to test numbers as zero, positive, or negative. These can be replaced by their respective predicate methods. The cop can also be configured to do the reverse.

The cop disregards #nonzero? as it its value is truthy or falsey, but not true and false, and thus not always interchangeable with != 0.

The cop ignores comparisons to global variables, since they are often populated with objects which can be compared with integers, but are not themselves Interger polymorphic.

Example: EnforcedStyle: predicate (default)

# bad

foo == 0
0 > foo
bar.baz > 0

# good

foo.zero?
foo.negative?
bar.baz.positive?

Example: EnforcedStyle: comparison

# bad

foo.zero?
foo.negative?
bar.baz.positive?

# good

foo == 0
0 > foo
bar.baz > 0

Useless assignment to variable - width.
Open

          width = nil
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

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

Redundant curly braces around a hash parameter.
Open

        item_class.constantize.update_all({ private_version_serialized: private_data }, { id: item.id })
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop checks for braces around the last parameter in a method call if the last parameter is a hash. It supports braces, no_braces and context_dependent styles.

Example: EnforcedStyle: braces

# The `braces` style enforces braces around all method
# parameters that are hashes.

# bad
some_method(x, y, a: 1, b: 2)

# good
some_method(x, y, {a: 1, b: 2})

Example: EnforcedStyle: no_braces (default)

# The `no_braces` style checks that the last parameter doesn't
# have braces around it.

# bad
some_method(x, y, {a: 1, b: 2})

# good
some_method(x, y, a: 1, b: 2)

Example: EnforcedStyle: context_dependent

# The `context_dependent` style checks that the last parameter
# doesn't have braces around it, but requires braces if the
# second to last parameter is also a hash literal.

# bad
some_method(x, y, {a: 1, b: 2})
some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)

# good
some_method(x, y, a: 1, b: 2)
some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})

Use topics.size.positive? instead of topics.size > 0.
Open

        raise 'No matching topics.' unless topics.size > 0
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop checks for usage of comparison operators (==, >, <) to test numbers as zero, positive, or negative. These can be replaced by their respective predicate methods. The cop can also be configured to do the reverse.

The cop disregards #nonzero? as it its value is truthy or falsey, but not true and false, and thus not always interchangeable with != 0.

The cop ignores comparisons to global variables, since they are often populated with objects which can be compared with integers, but are not themselves Interger polymorphic.

Example: EnforcedStyle: predicate (default)

# bad

foo == 0
0 > foo
bar.baz > 0

# good

foo.zero?
foo.negative?
bar.baz.positive?

Example: EnforcedStyle: comparison

# bad

foo.zero?
foo.negative?
bar.baz.positive?

# good

foo == 0
0 > foo
bar.baz > 0

Use !empty? instead of size > 0.
Open

        raise 'No matching topics.' unless topics.size > 0
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop checks for numeric comparisons that can be replaced by a predicate method, such as receiver.length == 0, receiver.length > 0, receiver.length != 0, receiver.length < 1 and receiver.size == 0 that can be replaced by receiver.empty? and !receiver.empty.

Example:

# bad
[1, 2, 3].length == 0
0 == "foobar".length
array.length < 1
{a: 1, b: 2}.length != 0
string.length > 0
hash.size > 0

# good
[1, 2, 3].empty?
"foobar".empty?
array.empty?
!{a: 1, b: 2}.empty?
!string.empty?
!hash.empty?

%w-literals should be delimited by [ and ].
Open

      %w(Topic StillImage AudioRecording Video WebLink Document).each do |item_class|
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop enforces the consistent usage of %-literal delimiters.

Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

Example:

# Style/PercentLiteralDelimiters:
#   PreferredDelimiters:
#     default: '[]'
#     '%i':    '()'

# good
%w[alpha beta] + %i(gamma delta)

# bad
%W(alpha #{beta})

# bad
%I(alpha beta)

Use the return of the conditional for variable assignment and comparison.
Open

          if specs.size == 1
            height = 3 * width
          else
            height = specs[1].to_i
          end
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

%w-literals should be delimited by [ and ].
Open

        %w{inset below sidebar}.each do |setting|
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop enforces the consistent usage of %-literal delimiters.

Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

Example:

# Style/PercentLiteralDelimiters:
#   PreferredDelimiters:
#     default: '[]'
#     '%i':    '()'

# good
%w[alpha beta] + %i(gamma delta)

# bad
%W(alpha #{beta})

# bad
%I(alpha beta)

Unused block argument - value. If it's necessary, use _ or _value as an argument name to indicate that it won't be used.
Open

        private_data.each_with_index do |(key, value), index|
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop checks for unused block arguments.

Example:

# bad

do_something do |used, unused|
  puts used
end

do_something do |bar|
  puts :foo
end

define_method(:foo) do |bar|
  puts :baz
end

Example:

#good

do_something do |used, _unused|
  puts used
end

do_something do
  puts :foo
end

define_method(:foo) do |_bar|
  puts :baz
end

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

          if successful
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

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

Use self-assignment shorthand -=.
Open

          missing_image_size_keys = missing_image_size_keys - [child_image_file.thumbnail.to_sym]
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop enforces the use the shorthand for self-assignment.

Example:

# bad
x = x + 1

# good
x += 1

Closing array brace must be on the line after the last array element when opening brace is on a separate line from the first array element.
Open

        'kete:tools:tiny_mce:write_default_imageselector_sizes_json']
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop checks that the closing brace in an array literal is either on the same line as the last array element, or a new line.

When using the symmetrical (default) style:

If an array's opening brace is on the same line as the first element of the array, then the closing brace should be on the same line as the last element of the array.

If an array's opening brace is on the line above the first element of the array, then the closing brace should be on the line below the last element of the array.

When using the new_line style:

The closing brace of a multi-line array literal must be on the line after the last element of the array.

When using the same_line style:

The closing brace of a multi-line array literal must be on the same line as the last element of the array.

Example: EnforcedStyle: symmetrical (default)

# bad
  [ :a,
    :b
  ]

  # bad
  [
    :a,
    :b ]

  # good
  [ :a,
    :b ]

  # good
  [
    :a,
    :b
  ]

Example: EnforcedStyle: new_line

# bad
  [
    :a,
    :b ]

  # bad
  [ :a,
    :b ]

  # good
  [ :a,
    :b
  ]

  # good
  [
    :a,
    :b
  ]

Example: EnforcedStyle: same_line

# bad
  [ :a,
    :b
  ]

  # bad
  [
    :a,
    :b
  ]

  # good
  [
    :a,
    :b ]

  # good
  [ :a,
    :b ]

Pass &:to_s as an argument to collect instead of a block.
Open

        @logger.info "    Image sizes keys not yet used: #{missing_image_size_keys.collect { |s| s.to_s }.join(',')}"
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

Use symbols as procs when possible.

Example:

# bad
something.map { |s| s.upcase }

# good
something.map(&:upcase)

Pass &:tableize as an argument to collect instead of a block.
Open

            kinds_to_process = ['child_related_topics'] + ['parent_related_topics'] + class_names.collect { |n| n.tableize }
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

Use symbols as procs when possible.

Example:

# bad
something.map { |s| s.upcase }

# good
something.map(&:upcase)

%w-literals should be delimited by [ and ].
Open

            %w(Topic StillImage AudioRecording Video WebLink Document).each do |item_class|
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

This cop enforces the consistent usage of %-literal delimiters.

Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

Example:

# Style/PercentLiteralDelimiters:
#   PreferredDelimiters:
#     default: '[]'
#     '%i':    '()'

# good
%w[alpha beta] + %i(gamma delta)

# bad
%W(alpha #{beta})

# bad
%I(alpha beta)

Pass &:to_i as an argument to collect instead of a block.
Open

      sizes = size_string.split('x').collect { |s| s.to_i }
Severity: Minor
Found in lib/old_tasks/tools.rake by rubocop

Use symbols as procs when possible.

Example:

# bad
something.map { |s| s.upcase }

# good
something.map(&:upcase)

There are no issues that match your filters.

Category
Status