daddyz/phonelib

View on GitHub

Showing 280 of 280 total issues

Line is too long. [101/80]
Open

      match = phone.match full_regex_for_data(data, Core::VALID_PATTERN, !original_starts_with_plus?)
Severity: Minor
Found in lib/phonelib/phone_analyzer.rb by rubocop

Use safe navigation (&.) instead of checking if an object exists before calling the method.
Open

      format_data && format_data.find do |format|
        (format[Core::LEADING_DIGITS].nil? || \
            national.match(cr("^(#{format[Core::LEADING_DIGITS]})"))) && \
          national.match(cr("^(#{format[Core::PATTERN]})$"))
      end || Core::DEFAULT_NUMBER_FORMAT
Severity: Minor
Found in lib/phonelib/phone_analyzer.rb by rubocop

This cop transforms usages of a method call safeguarded by a non nil check for the variable whose method is being called to safe navigation (&.).

Configuration option: ConvertCodeThatCanStartToReturnNil The default for this is false. When configured to true, this will check for code in the format !foo.nil? && foo.bar. As it is written, the return of this code is limited to false and whatever the return of the method is. If this is converted to safe navigation, foo&.bar can start returning nil as well as what the method returns.

Example:

# bad
foo.bar if foo
foo.bar(param1, param2) if foo
foo.bar { |e| e.something } if foo
foo.bar(param) { |e| e.something } if foo

foo.bar if !foo.nil?
foo.bar unless !foo
foo.bar unless foo.nil?

foo && foo.bar
foo && foo.bar(param1, param2)
foo && foo.bar { |e| e.something }
foo && foo.bar(param) { |e| e.something }

# good
foo&.bar
foo&.bar(param1, param2)
foo&.bar { |e| e.something }
foo&.bar(param) { |e| e.something }

foo.nil? || foo.bar
!foo || foo.bar

# Methods that `nil` will `respond_to?` should not be converted to
# use safe navigation
foo.to_i if foo

Indent the first line of the right-hand-side of a multi-line assignment.
Open

                str_clean(f.children.first, not_format?(f.name))
Severity: Minor
Found in lib/phonelib/data_importer.rb by rubocop

This cop checks the indentation of the first line of the right-hand-side of a multi-line assignment.

Example:

# bad
value =
if foo
  'bar'
end

# good
value =
  if foo
    'bar'
  end

The indentation of the remaining lines can be corrected with other cops such as IndentationConsistency and EndAlignment.

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

require "pathname"
Severity: Minor
Found in bin/rspec 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

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Severity: Minor
Found in bin/rspec 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"

Use (phone_types & types).size.positive? instead of (phone_types & types).size > 0.
Open

    (phone_types & types).size > 0
Severity: Minor
Found in lib/validators/phone_validator.rb 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

Replace class var @@phone_data with a class instance var.
Open

      @@phone_data ||= load_data.freeze
Severity: Minor
Found in lib/phonelib/core.rb by rubocop

This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

Replace class var @@phone_regexp_cache with a class instance var.
Open

    @@phone_regexp_cache = {}
Severity: Minor
Found in lib/phonelib/core.rb by rubocop

This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

Replace class var @@additional_regexes with a class instance var.
Open

      @@additional_regexes = {}
Severity: Minor
Found in lib/phonelib/core.rb by rubocop

This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

Avoid using Marshal.load.
Open

      default_data = Marshal.load(File.binread(data_file))
Severity: Minor
Found in lib/phonelib/core.rb by rubocop

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

Example:

# bad
Marshal.load("{}")
Marshal.restore("{}")

# good
Marshal.dump("{}")

# okish - deep copy hack
Marshal.load(Marshal.dump({}))

Avoid using Marshal.load.
Open

      Marshal.load(File.binread(data_file))
Severity: Minor
Found in lib/phonelib/core.rb by rubocop

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

Example:

# bad
Marshal.load("{}")
Marshal.restore("{}")

# good
Marshal.dump("{}")

# okish - deep copy hack
Marshal.load(Marshal.dump({}))

Use safe navigation (&.) instead of checking if an object exists before calling the method.
Open

                 when result && result.values.find { |e| e[:valid].any? }
Severity: Minor
Found in lib/phonelib/phone_analyzer.rb by rubocop

This cop transforms usages of a method call safeguarded by a non nil check for the variable whose method is being called to safe navigation (&.).

Configuration option: ConvertCodeThatCanStartToReturnNil The default for this is false. When configured to true, this will check for code in the format !foo.nil? && foo.bar. As it is written, the return of this code is limited to false and whatever the return of the method is. If this is converted to safe navigation, foo&.bar can start returning nil as well as what the method returns.

Example:

# bad
foo.bar if foo
foo.bar(param1, param2) if foo
foo.bar { |e| e.something } if foo
foo.bar(param) { |e| e.something } if foo

foo.bar if !foo.nil?
foo.bar unless !foo
foo.bar unless foo.nil?

foo && foo.bar
foo && foo.bar(param1, param2)
foo && foo.bar { |e| e.something }
foo && foo.bar(param) { |e| e.something }

# good
foo&.bar
foo&.bar(param1, param2)
foo&.bar { |e| e.something }
foo&.bar(param) { |e| e.something }

foo.nil? || foo.bar
!foo || foo.bar

# Methods that `nil` will `respond_to?` should not be converted to
# use safe navigation
foo.to_i if foo

Use safe navigation (&.) instead of checking if an object exists before calling the method.
Open

          if country[Core::NATIONAL_PREFIX_TRANSFORM_RULE]
            country[Core::NATIONAL_PREFIX_TRANSFORM_RULE].gsub!('$', '\\')
          end
Severity: Minor
Found in lib/phonelib/data_importer.rb by rubocop

This cop transforms usages of a method call safeguarded by a non nil check for the variable whose method is being called to safe navigation (&.).

Configuration option: ConvertCodeThatCanStartToReturnNil The default for this is false. When configured to true, this will check for code in the format !foo.nil? && foo.bar. As it is written, the return of this code is limited to false and whatever the return of the method is. If this is converted to safe navigation, foo&.bar can start returning nil as well as what the method returns.

Example:

# bad
foo.bar if foo
foo.bar(param1, param2) if foo
foo.bar { |e| e.something } if foo
foo.bar(param) { |e| e.something } if foo

foo.bar if !foo.nil?
foo.bar unless !foo
foo.bar unless foo.nil?

foo && foo.bar
foo && foo.bar(param1, param2)
foo && foo.bar { |e| e.something }
foo && foo.bar(param) { |e| e.something }

# good
foo&.bar
foo&.bar(param1, param2)
foo&.bar { |e| e.something }
foo&.bar(param) { |e| e.something }

foo.nil? || foo.bar
!foo || foo.bar

# Methods that `nil` will `respond_to?` should not be converted to
# use safe navigation
foo.to_i if foo

Indent the first line of the right-hand-side of a multi-line assignment.
Open

          [@national_number.match(/#{format[Core::PATTERN]}/), format_string]
Severity: Minor
Found in lib/phonelib/phone_formatter.rb by rubocop

This cop checks the indentation of the first line of the right-hand-side of a multi-line assignment.

Example:

# bad
value =
if foo
  'bar'
end

# good
value =
  if foo
    'bar'
  end

The indentation of the remaining lines can be corrected with other cops such as IndentationConsistency and EndAlignment.

Line is too long. [90/80]
Open

      match = e164.match(/\A\+(1(#{Phonelib.phone_data[country][Core::LEADING_DIGITS]}))/)
Severity: Minor
Found in lib/phonelib/phone_formatter.rb by rubocop

When using method_missing, define respond_to_missing?.
Open

    def method_missing(method, *args)
      prefix_methods = %w(international_ full_international_ e164_ full_e164_)
      method_s = method.to_s
      prefix_methods.each do |key|
        return send(key[0..-2], method_s.gsub(key, '')) if method_s.start_with?(key)
Severity: Minor
Found in lib/phonelib/phone_formatter.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

Missing top-level module documentation comment.
Open

module TempFixForRakeLastComment
Severity: Minor
Found in Rakefile by rubocop

This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

Example:

# bad
class Person
  # ...
end

# good
# Description/Explanation of Person class
class Person
  # ...
end

Line is too long. [86/80]
Open

    abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Severity: Minor
Found in bin/rspec by rubocop

Use !empty? instead of size > 0.
Open

    (phone_types & types).size > 0
Severity: Minor
Found in lib/validators/phone_validator.rb 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?

Line is too long. [115/80]
Open

    # @return [Boolean] Flag defines whether to reset country in case number has + and country prefix doesn't match
Severity: Minor
Found in lib/phonelib/core.rb by rubocop
Severity
Category
Status
Source
Language