lib/tasks/i14y.rake

Summary

Maintainability
Test Coverage

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

namespace :i14y do
  desc "Creates templates, indexes, and reader/writer aliases for all i14y models"
  task setup: :environment do
    Dir[Rails.root.join('app', 'templates', '*.rb')].each do |template_generator|
      entity_name = File.basename(template_generator, '.rb')
Severity: Minor
Found in lib/tasks/i14y.rake by rubocop

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.

You can set constructs you want to fold with CountAsOne. Available are: 'array', 'hash', 'heredoc', and 'method_call'. Each construct will be counted as one line regardless of its actual size.

NOTE: The ExcludedMethods configuration is deprecated and only kept for backwards compatibility. Please use AllowedMethods and AllowedPatterns instead. By default, there are no methods to allowed.

Example: CountAsOne: ['array', 'heredoc', 'method_call']

something do
  array = [         # +1
    1,
    2
  ]

  hash = {          # +3
    key: 'value'
  }

  msg = <<~HEREDOC  # +1
    Heredoc
    content.
  HEREDOC

  foo(              # +1
    1,
    2
  )
end                 # 6 points

NOTE: This cop does not apply for Struct definitions.

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

  task :reindex, [:entity_name] => [:environment] do |_t, args|
    entity_name = args.entity_name
    persistence_model_klass = entity_name.singularize.camelize.constantize
    klass = entity_name.camelize.constantize
    template_generator = klass.new
Severity: Minor
Found in lib/tasks/i14y.rake by rubocop

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.

You can set constructs you want to fold with CountAsOne. Available are: 'array', 'hash', 'heredoc', and 'method_call'. Each construct will be counted as one line regardless of its actual size.

NOTE: The ExcludedMethods configuration is deprecated and only kept for backwards compatibility. Please use AllowedMethods and AllowedPatterns instead. By default, there are no methods to allowed.

Example: CountAsOne: ['array', 'heredoc', 'method_call']

something do
  array = [         # +1
    1,
    2
  ]

  hash = {          # +3
    key: 'value'
  }

  msg = <<~HEREDOC  # +1
    Heredoc
    content.
  HEREDOC

  foo(              # +1
    1,
    2
  )
end                 # 6 points

NOTE: This cop does not apply for Struct definitions.

Prefer Rails.root.join('path/to').
Open

    result = `#{Rails.root.join('vendor', 'stream2es')} es #{options.join(' ')}`
Severity: Minor
Found in lib/tasks/i14y.rake by rubocop

This cop is used to identify usages of file path joining process to use Rails.root.join clause. It is used to add uniformity when joining paths.

Example: EnforcedStyle: arguments (default)

# bad
Rails.root.join('app/models/goober')
File.join(Rails.root, 'app/models/goober')
"#{Rails.root}/app/models/goober"

# good
Rails.root.join('app', 'models', 'goober')

Example: EnforcedStyle: slashes

# bad
Rails.root.join('app', 'models', 'goober')
File.join(Rails.root, 'app/models/goober')
"#{Rails.root}/app/models/goober"

# good
Rails.root.join('app/models/goober')

Prefer Rails.root.join('path/to').
Open

    Dir[Rails.root.join('app', 'templates', '*.rb')].each do |template_generator|
Severity: Minor
Found in lib/tasks/i14y.rake by rubocop

This cop is used to identify usages of file path joining process to use Rails.root.join clause. It is used to add uniformity when joining paths.

Example: EnforcedStyle: arguments (default)

# bad
Rails.root.join('app/models/goober')
File.join(Rails.root, 'app/models/goober')
"#{Rails.root}/app/models/goober"

# good
Rails.root.join('app', 'models', 'goober')

Example: EnforcedStyle: slashes

# bad
Rails.root.join('app', 'models', 'goober')
File.join(Rails.root, 'app/models/goober')
"#{Rails.root}/app/models/goober"

# good
Rails.root.join('app/models/goober')

Prefer Rails.root.join('path/to').
Open

    Dir[Rails.root.join('app', 'templates', '*.rb')].each do |template_generator|
Severity: Minor
Found in lib/tasks/i14y.rake by rubocop

This cop is used to identify usages of file path joining process to use Rails.root.join clause. It is used to add uniformity when joining paths.

Example: EnforcedStyle: arguments (default)

# bad
Rails.root.join('app/models/goober')
File.join(Rails.root, 'app/models/goober')
"#{Rails.root}/app/models/goober"

# good
Rails.root.join('app', 'models', 'goober')

Example: EnforcedStyle: slashes

# bad
Rails.root.join('app', 'models', 'goober')
File.join(Rails.root, 'app/models/goober')
"#{Rails.root}/app/models/goober"

# good
Rails.root.join('app/models/goober')

Avoid using rescue in its modifier form.
Open

      ES.client.indices.delete_template(name: entity_name) rescue Elasticsearch::Transport::Transport::Errors::NotFound
Severity: Minor
Found in lib/tasks/i14y.rake by rubocop

Checks for uses of rescue in its modifier form.

The cop to check rescue in its modifier form is added for following reasons:

  • The syntax of modifier form rescue can be misleading because it might lead us to believe that rescue handles the given exception but it actually rescue all exceptions to return the given rescue block. In this case, value returned by handle_error or SomeException.

  • Modifier form rescue would rescue all the exceptions. It would silently skip all exception or errors and handle the error. Example: If NoMethodError is raised, modifier form rescue would handle the exception.

Example:

# bad
some_method rescue handle_error

# bad
some_method rescue SomeException

# good
begin
  some_method
rescue
  handle_error
end

# good
begin
  some_method
rescue SomeException
  handle_error
end

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

  desc "Creates templates, indexes, and reader/writer aliases for all i14y models"
Severity: Minor
Found in lib/tasks/i14y.rake by rubocop

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Extra empty line detected at block body end.
Open


end
Severity: Minor
Found in lib/tasks/i14y.rake by rubocop

Checks if empty lines around the bodies of blocks match the configuration.

Example: EnforcedStyle: noemptylines (default)

# good

foo do |bar|
  # ...
end

Example: EnforcedStyle: empty_lines

# good

foo do |bar|

  # ...

end

Do not define a method in rake task, because it will be defined to the top level.
Open

  def move_alias(alias_name, old_index_name, new_index_name)
    update_aliases_hash = { body:
                              { actions: [
                                { remove: { index: old_index_name, alias: alias_name } },
                                { add: { index: new_index_name, alias: alias_name } }
Severity: Minor
Found in lib/tasks/i14y.rake by rubocop

Use parentheses for method calls with arguments.
Open

    puts "Stream2es completed", result
Severity: Minor
Found in lib/tasks/i14y.rake by rubocop

Enforces the presence (default) or absence of parentheses in method calls containing parameters.

In the default style (require_parentheses), macro methods are allowed. Additional methods can be added to the AllowedMethods or AllowedPatterns list. These options are valid only in the default style. Macros can be included by either setting IgnoreMacros to false or adding specific macros to the IncludedMacros list.

Precedence of options is all follows:

  1. AllowedMethods
  2. AllowedPatterns
  3. IncludedMacros

eg. If a method is listed in both IncludedMacros and AllowedMethods, then the latter takes precedence (that is, the method is allowed).

In the alternative style (omit_parentheses), there are three additional options.

  1. AllowParenthesesInChaining is false by default. Setting it to true allows the presence of parentheses in the last call during method chaining.

  2. AllowParenthesesInMultilineCall is false by default. Setting it to true allows the presence of parentheses in multi-line method calls.

  3. AllowParenthesesInCamelCaseMethod is false by default. This allows the presence of parentheses when calling a method whose name begins with a capital letter and which has no arguments. Setting it to true allows the presence of parentheses in such a method call even with arguments.

NOTE: Parentheses are still allowed in cases where omitting them results in ambiguous or syntactically incorrect code. For example, parentheses are required around a method with arguments when inside an endless method definition introduced in Ruby 3.0. Parentheses are also allowed when forwarding arguments with the triple-dot syntax introduced in Ruby 2.7 as omitting them starts an endless range. And Ruby 3.1's hash omission syntax has a case that requires parentheses because of the following issue: https://bugs.ruby-lang.org/issues/18396.

Example: EnforcedStyle: require_parentheses (default)

# bad
array.delete e

# good
array.delete(e)

# good
# Operators don't need parens
foo == bar

# good
# Setter methods don't need parens
foo.bar = baz

# okay with `puts` listed in `AllowedMethods`
puts 'test'

# okay with `^assert` listed in `AllowedPatterns`
assert_equal 'test', x

Example: EnforcedStyle: omit_parentheses

# bad
array.delete(e)

# good
array.delete e

# bad
foo.enforce(strict: true)

# good
foo.enforce strict: true

# good
# Allows parens for calls that won't produce valid Ruby or be ambiguous.
model.validate strict(true)

# good
# Allows parens for calls that won't produce valid Ruby or be ambiguous.
yield path, File.basename(path)

# good
# Operators methods calls with parens
array&.[](index)

# good
# Operators methods without parens, if you prefer
array.[] index

# good
# Operators methods calls with parens
array&.[](index)

# good
# Operators methods without parens, if you prefer
array.[] index

Example: IgnoreMacros: true (default)

# good
class Foo
  bar :baz
end

Example: IgnoreMacros: false

# bad
class Foo
  bar :baz
end

Example: AllowParenthesesInMultilineCall: false (default)

# bad
foo.enforce(
  strict: true
)

# good
foo.enforce \
  strict: true

Example: AllowParenthesesInMultilineCall: true

# good
foo.enforce(
  strict: true
)

# good
foo.enforce \
  strict: true

Example: AllowParenthesesInChaining: false (default)

# bad
foo().bar(1)

# good
foo().bar 1

Example: AllowParenthesesInChaining: true

# good
foo().bar(1)

# good
foo().bar 1

Example: AllowParenthesesInCamelCaseMethod: false (default)

# bad
Array(1)

# good
Array 1

Example: AllowParenthesesInCamelCaseMethod: true

# good
Array(1)

# good
Array 1

Example: AllowParenthesesInStringInterpolation: false (default)

# bad
"#{t('this.is.bad')}"

# good
"#{t 'this.is.better'}"

Example: AllowParenthesesInStringInterpolation: true

# good
"#{t('this.is.good')}"

# good
"#{t 'this.is.also.good'}"

Do not define a method in rake task, because it will be defined to the top level.
Open

  def stream2es(old_es_index_url, new_es_index_url, timestamp = nil)
    options = ["--source #{old_es_index_url}", "--target #{new_es_index_url}"]
    if timestamp.present?
      hash = { query: { filtered: { filter: { range: { updated_at: { gte: timestamp } } } } } }
      options << "--query '#{hash.to_json}'"
Severity: Minor
Found in lib/tasks/i14y.rake by rubocop

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

  desc "Deletes templates, indexes, and reader/writer aliases for all i14y models. Useful for development."
Severity: Minor
Found in lib/tasks/i14y.rake by rubocop

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

    puts "Stream2es completed", result
Severity: Minor
Found in lib/tasks/i14y.rake by rubocop

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Do not use Time.now without zone. Use one of Time.zone.now, Time.current, Time.now.in_time_zone, Time.now.utc, Time.now.getlocal, Time.now.xmlschema, Time.now.iso8601, Time.now.jisx0301, Time.now.rfc3339, Time.now.httpdate, Time.now.to_i, Time.now.to_f instead.
Open

      since_timestamp = Time.now
Severity: Minor
Found in lib/tasks/i14y.rake by rubocop

This cop checks for the use of Time methods without zone.

Built on top of Ruby on Rails style guide (https://github.com/rubocop-hq/rails-style-guide#time) and the article http://danilenko.org/2012/7/6/rails_timezones/

Two styles are supported for this cop. When EnforcedStyle is 'strict' then only use of Time.zone is allowed.

When EnforcedStyle is 'flexible' then it's also allowed to use Time.intimezone.

Example: EnforcedStyle: strict

# `strict` means that `Time` should be used with `zone`.

# bad
Time.now
Time.parse('2015-03-02 19:05:37')

# bad
Time.current
Time.at(timestamp).in_time_zone

# good
Time.zone.now
Time.zone.parse('2015-03-02 19:05:37')

Example: EnforcedStyle: flexible (default)

# `flexible` allows usage of `in_time_zone` instead of `zone`.

# bad
Time.now
Time.parse('2015-03-02 19:05:37')

# good
Time.zone.now
Time.zone.parse('2015-03-02 19:05:37')

# good
Time.current
Time.at(timestamp).in_time_zone

Missing frozen string literal comment.
Open

namespace :i14y do
Severity: Minor
Found in lib/tasks/i14y.rake by rubocop

Helps you transition from mutable string literals to frozen string literals. It will add the # frozen_string_literal: true magic comment to the top of files to enable frozen string literals. Frozen string literals may be default in future Ruby. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

Note that the cop will accept files where the comment exists but is set to false instead of true.

To require a blank line after this comment, please see Layout/EmptyLineAfterMagicComment cop.

Safety:

This cop's autocorrection is unsafe since any strings mutations will change from being accepted to raising FrozenError, as all strings will become frozen by default, and will need to be manually refactored.

Example: EnforcedStyle: always (default)

# 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

# good
# frozen_string_literal: false

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

Example: EnforcedStyle: always_true

# The `always_true` style enforces that the frozen string literal
# comment is set to `true`. This is a stricter option than `always`
# and forces projects to use frozen string literals.
# bad
# frozen_string_literal: false

module Baz
  # ...
end

# bad
module Baz
  # ...
end

# good
# frozen_string_literal: true

module Bar
  # ...
end

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

  desc "Copies data from one version of the i14y index to the next (e.g., collections, documents) and updates the alias"
Severity: Minor
Found in lib/tasks/i14y.rake by rubocop

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Do not define a method in rake task, because it will be defined to the top level.
Open

  def next_version(index_name)
    matches = index_name.match(/(.*-v)(\d+)/)
    "#{matches[1]}#{matches[2].succ}"
  end
Severity: Minor
Found in lib/tasks/i14y.rake by rubocop

There are no issues that match your filters.

Category
Status