hsgubert/rails-sharding

View on GitHub

Showing 354 of 354 total issues

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

shards_namespace = namespace :shards do
  task _make_activerecord_base_shardable: [:environment] do
    # Several resources used (like Migrator, SchemaDumper, schema methods)
    # implicitly use ActiveRecord::Base.connection, so we have to make it
    # shardable so we can call using_shard and switch the connection
Severity: Minor
Found in lib/tasks/rails-sharding.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 establish_connection is too high. [24.1/15]
Open

    def self.establish_connection(shard_group, shard_name, environment=nil)
      self.setup unless defined? @@connection_handler

      configurations = (environment.nil? ? Core.configurations : Core.configurations(environment))

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

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

  namespace :test do
    desc "Recreate the test shards from existent schema files (options: SHARD_GROUP=x, SHARD=x)"
    task load_schema: ['shards:test:purge'] do
      Rails::Sharding.test_configurations.each do |shard_group, shards_configurations|
        next if ENV["SHARD_GROUP"] && ENV["SHARD_GROUP"] != shard_group.to_s
Severity: Minor
Found in lib/tasks/rails-sharding.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.

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

    def self.establish_connection(shard_group, shard_name, environment=nil)
      self.setup unless defined? @@connection_handler

      configurations = (environment.nil? ? Core.configurations : Core.configurations(environment))

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.

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

    def self.add_shard_tag_to_connection_log(connection, shard_tag)
      # avoids modifing connection twice
      if connection.respond_to? :shard_tag
        connection.shard_tag = shard_tag
        return connection

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. [44/25]
Open

  namespace :migrate do
    desc 'Rollbacks the shards one migration and re migrate up (options: RAILS_ENV=x, VERSION=x, STEP=x, SHARD_GROUP=x, SHARD=x).'
    task redo: [:environment] do
      if ENV["VERSION"]
        shards_namespace["migrate:down"].invoke
Severity: Minor
Found in lib/tasks/rails-sharding.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 configurations is too high. [17.38/15]
Open

    def self.configurations(environment=Rails.env)
      @@db_configs ||= YAML.load(ERB.new(File.read(Config.shards_config_file)).result)
      environment_config = @@db_configs[environment]
      return environment_config if environment_config

Severity: Minor
Found in lib/rails/sharding/core.rb 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

Cyclomatic complexity for for_each_shard is too high. [7/6]
Open

    def self.for_each_shard(environment:Rails.env, shard_group_filter:nil, shard_name_filter:nil)
      shard_group_filter.to_s if shard_group_filter
      shard_name_filter.to_s if shard_name_filter

      configurations(environment).each do |shard_group, shards_configurations|
Severity: Minor
Found in lib/rails/sharding/core.rb by rubocop

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

    def self.for_each_shard(environment:Rails.env, shard_group_filter:nil, shard_name_filter:nil)
      shard_group_filter.to_s if shard_group_filter
      shard_name_filter.to_s if shard_name_filter

      configurations(environment).each do |shard_group, shards_configurations|
Severity: Minor
Found in lib/rails/sharding/core.rb - About 1 hr 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

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

  namespace :schema do
    desc "Creates a schema.rb for each shard that is portable against any DB supported by Active Record (options: RAILS_ENV=x, SHARD_GROUP=x, SHARD=x)"
    task dump: [:_make_activerecord_base_shardable] do
      require "active_record/schema_dumper"

Severity: Minor
Found in lib/tasks/rails-sharding.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.

Method establish_connection has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def self.establish_connection(shard_group, shard_name, environment=nil)
      self.setup unless defined? @@connection_handler

      configurations = (environment.nil? ? Core.configurations : Core.configurations(environment))

Severity: Minor
Found in lib/rails/sharding/connection_handler.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

Avoid parameter lists longer than 5 parameters. [6/5]
Open

        def log(sql, name="SQL", binds=[], type_casted_binds=[], statement_name=nil, &block)

This cop checks for methods with too many parameters. The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count.

Method sharded_remove_connection has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def sharded_remove_connection(klass=nil)
        if ShardThreadRegistry.connecting_to_master? || klass
          return klass ? original_remove_connection(klass) : original_remove_connection
        else
          return ConnectionHandler.remove_connection(*ShardThreadRegistry.current_shard_group_and_name)
Severity: Minor
Found in lib/rails/sharding/shardable_model.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

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

require "rspec/core/rake_task"
Severity: Minor
Found in Rakefile 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"

Line is too long. [88/80]
Open

      copy_file 'rails-sharding_initializer.rb', 'config/initializers/rails-sharding.rb'

Freeze mutable objects assigned to constants.
Open

    DEFAULT_CONFIGS = {
      # If true one connection will be established per shard (in every shard group)
      # on startup. This only establishes the connection with the database but
      # it does not retrieve a connection yet. This will be done by the ConnectionPool
      # when necessary.
Severity: Minor
Found in lib/rails/sharding/config.rb by rubocop

This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

Example:

# bad
CONST = [1, 2, 3]

# good
CONST = [1, 2, 3].freeze

Space missing after colon.
Open

    def self.for_each_shard(environment:Rails.env, shard_group_filter:nil, shard_name_filter:nil)
Severity: Minor
Found in lib/rails/sharding/core.rb by rubocop

Checks for colon (:) not followed by some kind of space. N.B. this cop does not handle spaces after a ternary operator, which are instead handled by Layout/SpaceAroundOperators.

Example:

# bad
def f(a:, b:2); {a:3}; end

# good
def f(a:, b: 2); {a: 3}; end

Line is too long. [95/80]
Open

      if Config.no_connection_retrieved_warning && !connection_used && !was_connected_to_master
Severity: Minor
Found in lib/rails/sharding/core.rb by rubocop

Line is too long. [112/80]
Open

      ConnectionHandler.connection_pool(shard_group, shard_name).release_connection if shard_group && shard_name
Severity: Minor
Found in lib/rails/sharding/core.rb by rubocop

Line is too long. [95/80]
Open

      raise Errors::ConfigNotFoundError, Config.shards_config_file.to_s + ' file was not found'
Severity: Minor
Found in lib/rails/sharding/core.rb by rubocop
Severity
Category
Status
Source
Language