sapristi-tool/sapristi

View on GitHub
lib/sapristi/definition.rb

Summary

Maintainability
A
0 mins
Test Coverage

Sapristi::Definition#validate_raw calls 'definition['Monitor']' 2 times
Open

      raise Error, "Invalid monitor=#{definition['Monitor']}" if definition['Monitor']&.to_i&.negative?
Severity: Minor
Found in lib/sapristi/definition.rb by reek

Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

Reek implements a check for Duplicate Method Call.

Example

Here's a very much simplified and contrived example. The following method will report a warning:

def double_thing()
  @other.thing + @other.thing
end

One quick approach to silence Reek would be to refactor the code thus:

def double_thing()
  thing = @other.thing
  thing + thing
end

A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

class Other
  def double_thing()
    thing + thing
  end
end

The approach you take will depend on balancing other factors in your code.

Sapristi::Definition#validate_geometry performs a nil-check
Open

      geometry_field_nil = %w[Width Height X Y].find { |key| definition[key].nil? }
Severity: Minor
Found in lib/sapristi/definition.rb by reek

A NilCheck is a type check. Failures of NilCheck violate the "tell, don't ask" principle.

Additionally, type checks often mask bigger problems in your source code like not using OOP and / or polymorphism when you should.

Example

Given

class Klass
  def nil_checker(argument)
    if argument.nil?
      puts "argument isn't nil!"
    end
  end
end

Reek would emit the following warning:

test.rb -- 1 warning:
  [3]:Klass#nil_checker performs a nil-check. (NilCheck)

Use tr instead of gsub.
Open

        name = key.downcase.gsub(/-/, '_')
Severity: Minor
Found in lib/sapristi/definition.rb by rubocop

This cop identifies places where gsub can be replaced by tr or delete.

Example:

# bad
'abc'.gsub('b', 'd')
'abc'.gsub('a', '')
'abc'.gsub(/a/, 'd')
'abc'.gsub!('a', 'd')

# good
'abc'.gsub(/.*/, 'a')
'abc'.gsub(/a+/, 'd')
'abc'.tr('b', 'd')
'a b c'.delete(' ')

Line is too long. [83/80]
Open

      geometry_field_nil = %w[Width Height X Y].find { |key| definition[key].nil? }
Severity: Minor
Found in lib/sapristi/definition.rb by rubocop

Line is too long. [109/80]
Open

      raise Error, "Invalid configuration file: invalid headers=#{actual_headers}, valid=#{expected_headers}"
Severity: Minor
Found in lib/sapristi/definition.rb by rubocop

Line is too long. [82/80]
Open

      @monitor = MonitorManager.new.get_monitor_or_main definition_hash['Monitor']
Severity: Minor
Found in lib/sapristi/definition.rb by rubocop

Line is too long. [103/80]
Open

      raise Error, "Invalid monitor=#{definition['Monitor']}" if definition['Monitor']&.to_i&.negative?
Severity: Minor
Found in lib/sapristi/definition.rb by rubocop

Line is too long. [97/80]
Open

      @workspace = WindowManager.new.find_workspace_or_current definition_hash['Workspace']&.to_i
Severity: Minor
Found in lib/sapristi/definition.rb by rubocop

Line is too long. [86/80]
Open

        value = AttributeNormalizer.new(key, @raw_definition[key], @monitor).normalize
Severity: Minor
Found in lib/sapristi/definition.rb by rubocop

Line is too long. [109/80]
Open

      raise Error, 'No command or window title specified' unless definition['Command'] || definition['Title']
Severity: Minor
Found in lib/sapristi/definition.rb by rubocop

There are no issues that match your filters.

Category
Status