steventwheeler/clli

View on GitHub

Showing 40 of 40 total issues

Module has too many lines. [102/100]
Open

    module ClassMethods
      DEFAULT_PATTERN_OPTIONS = {
        strict: true,
        place_group: 'place',
        region_group: 'region',
Severity: Minor
Found in lib/clli/pattern.rb by rubocop

This cop checks if the length a module exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Class CLLI has 22 methods (exceeds 20 allowed). Consider refactoring.
Open

class CLLI
  ##
  # This module provides the various patterns used for parsing +CLLI+ strings.
  module Pattern
    ##
Severity: Minor
Found in lib/clli/pattern.rb - About 2 hrs to fix

    Method validate_attribute has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def validate_attribute(error_prefix, value, length, regexp, **options)
            fail "#{error_prefix} cannot be nil." if value.nil?
            fail "#{error_prefix} cannot be empty." if value.to_s.empty?
            fail "#{error_prefix} must be #{length} #{pluralize(length, 'character')} long." unless value.to_s.size == length
            return unless options[:strict]
    Severity: Minor
    Found in lib/clli/validations.rb - About 45 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

    Method state_name has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def state_name(region_code)
            state_code = iso_state(region_code)
            return unless state_code
            country_code = iso_country(region_code)
            return unless country_code
    Severity: Minor
    Found in lib/clli/iso3166.rb - About 45 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

    Method validate_attribute has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

          def validate_attribute(error_prefix, value, length, regexp, **options)
    Severity: Minor
    Found in lib/clli/validations.rb - About 35 mins to fix

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

      namespace :generate do
        task :city_cache do
          data = {}
          CSV.foreach(input_file) do |row|
            prefix, city, state = row
      Severity: Minor
      Found in Rakefile 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. [26/25]
      Open

        task :city_cache do
          data = {}
          CSV.foreach(input_file) do |row|
            prefix, city, state = row
            prefix = prefix.strip
      Severity: Minor
      Found in Rakefile 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.

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

              @cities_data ||= YAMLData.new(%w(clli data cities.yml))
      Severity: Minor
      Found in lib/clli/cities.rb 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)

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

          output_file = CLLI::YAMLData.real_path(%w(clli data cities.yml))
      Severity: Minor
      Found in Rakefile 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)

      Freeze mutable objects assigned to constants.
      Open

        VERSION = '0.0.3'
      Severity: Minor
      Found in lib/clli/version.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

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

              "CG[#{x1}]" => %w(switching_types CGx),
      Severity: Minor
      Found in lib/clli/entity_type.rb 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)

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

              "[#{n}]{2}T" => %w(switching_types nnT),
      Severity: Minor
      Found in lib/clli/entity_type.rb 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)

      Always use raise to signal exceptions.
      Open

              fail "#{error_prefix} must be #{length} #{pluralize(length, 'character')} long." unless value.to_s.size == length
      Severity: Minor
      Found in lib/clli/validations.rb by rubocop

      This cop checks for uses of fail and raise.

      Example: EnforcedStyle: only_raise (default)

      # The `only_raise` style enforces the sole use of `raise`.
      # bad
      begin
        fail
      rescue Exception
        # handle it
      end
      
      def watch_out
        fail
      rescue Exception
        # handle it
      end
      
      Kernel.fail
      
      # good
      begin
        raise
      rescue Exception
        # handle it
      end
      
      def watch_out
        raise
      rescue Exception
        # handle it
      end
      
      Kernel.raise

      Example: EnforcedStyle: only_fail

      # The `only_fail` style enforces the sole use of `fail`.
      # bad
      begin
        raise
      rescue Exception
        # handle it
      end
      
      def watch_out
        raise
      rescue Exception
        # handle it
      end
      
      Kernel.raise
      
      # good
      begin
        fail
      rescue Exception
        # handle it
      end
      
      def watch_out
        fail
      rescue Exception
        # handle it
      end
      
      Kernel.fail

      Example: EnforcedStyle: semantic

      # The `semantic` style enforces the use of `fail` to signal an
      # exception, then will use `raise` to trigger an offense after
      # it has been rescued.
      # bad
      begin
        raise
      rescue Exception
        # handle it
      end
      
      def watch_out
        # Error thrown
      rescue Exception
        fail
      end
      
      Kernel.fail
      Kernel.raise
      
      # good
      begin
        fail
      rescue Exception
        # handle it
      end
      
      def watch_out
        fail
      rescue Exception
        raise 'Preferably with descriptive message'
      end
      
      explicit_receiver.fail
      explicit_receiver.raise

      When using method_missing, define respond_to_missing?.
      Open

        def method_missing(method, *args)
          return @attributes[method] if @attributes.key?(method)
          super
        end
      Severity: Minor
      Found in lib/clli.rb by rubocop

      This cop checks for the presence of method_missing without also defining respond_to_missing? and falling back on super.

      Example:

      #bad
      def method_missing(name, *args)
        # ...
      end
      
      #good
      def respond_to_missing?(name, include_private)
        # ...
      end
      
      def method_missing(name, *args)
        # ...
        super
      end

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

              "SG[#{x1}]" => %w(switching_types SGx),
      Severity: Minor
      Found in lib/clli/entity_type.rb 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)

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

              "RS[#{n}]" => %w(switching_types RSn),
      Severity: Minor
      Found in lib/clli/entity_type.rb 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)

      Always use raise to signal exceptions.
      Open

              fail "#{error_prefix} cannot be empty." if value.to_s.empty?
      Severity: Minor
      Found in lib/clli/validations.rb by rubocop

      This cop checks for uses of fail and raise.

      Example: EnforcedStyle: only_raise (default)

      # The `only_raise` style enforces the sole use of `raise`.
      # bad
      begin
        fail
      rescue Exception
        # handle it
      end
      
      def watch_out
        fail
      rescue Exception
        # handle it
      end
      
      Kernel.fail
      
      # good
      begin
        raise
      rescue Exception
        # handle it
      end
      
      def watch_out
        raise
      rescue Exception
        # handle it
      end
      
      Kernel.raise

      Example: EnforcedStyle: only_fail

      # The `only_fail` style enforces the sole use of `fail`.
      # bad
      begin
        raise
      rescue Exception
        # handle it
      end
      
      def watch_out
        raise
      rescue Exception
        # handle it
      end
      
      Kernel.raise
      
      # good
      begin
        fail
      rescue Exception
        # handle it
      end
      
      def watch_out
        fail
      rescue Exception
        # handle it
      end
      
      Kernel.fail

      Example: EnforcedStyle: semantic

      # The `semantic` style enforces the use of `fail` to signal an
      # exception, then will use `raise` to trigger an offense after
      # it has been rescued.
      # bad
      begin
        raise
      rescue Exception
        # handle it
      end
      
      def watch_out
        # Error thrown
      rescue Exception
        fail
      end
      
      Kernel.fail
      Kernel.raise
      
      # good
      begin
        fail
      rescue Exception
        # handle it
      end
      
      def watch_out
        fail
      rescue Exception
        raise 'Preferably with descriptive message'
      end
      
      explicit_receiver.fail
      explicit_receiver.raise

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

              @location_type_data ||= YAMLData.new(%w(clli data location_types.yml))
      Severity: Minor
      Found in lib/clli/location_type.rb 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)

      Dependencies should be sorted in an alphabetical order within their section of the gemspec. Dependency minitest should appear before rake.
      Open

        spec.add_development_dependency 'minitest', '~> 5.0'
      Severity: Minor
      Found in clli.gemspec by rubocop

      Dependencies in the gemspec should be alphabetically sorted.

      Example:

      # bad
      spec.add_dependency 'rubocop'
      spec.add_dependency 'rspec'
      
      # good
      spec.add_dependency 'rspec'
      spec.add_dependency 'rubocop'
      
      # good
      spec.add_dependency 'rubocop'
      
      spec.add_dependency 'rspec'
      
      # bad
      spec.add_development_dependency 'rubocop'
      spec.add_development_dependency 'rspec'
      
      # good
      spec.add_development_dependency 'rspec'
      spec.add_development_dependency 'rubocop'
      
      # good
      spec.add_development_dependency 'rubocop'
      
      spec.add_development_dependency 'rspec'
      
      # bad
      spec.add_runtime_dependency 'rubocop'
      spec.add_runtime_dependency 'rspec'
      
      # good
      spec.add_runtime_dependency 'rspec'
      spec.add_runtime_dependency 'rubocop'
      
      # good
      spec.add_runtime_dependency 'rubocop'
      
      spec.add_runtime_dependency 'rspec'
      
      # good only if TreatCommentsAsGroupSeparators is true
      # For code quality
      spec.add_dependency 'rubocop'
      # For tests
      spec.add_dependency 'rspec'

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

              "B[#{n}]T" => %w(switching_types BnT),
      Severity: Minor
      Found in lib/clli/entity_type.rb 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)
      Severity
      Category
      Status
      Source
      Language