daddyz/phonelib

View on GitHub

Showing 280 of 280 total issues

Line is too long. [105/80]
Open

      if !Phonelib.ignore_plus && Core::PLUS_SIGN == @original[0] && code && !sanitized.start_with?(code)

Line is too long. [93/80]
Open

      regex << "(#{type_regex(data[Core::TYPES][Core::GENERAL], type)})" if data[Core::TYPES]

Use match.captures.compact.size.positive? instead of match.captures.compact.size > 0.
Open

      if match && match.captures.compact.size > 0
Severity: Minor
Found in lib/phonelib/phone_analyzer.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

Use %i or %I for an array of symbols.
Open

    NOT_FOR_CHECK = [:general_desc, :fixed_line, :mobile, :fixed_or_mobile]
Severity: Minor
Found in lib/phonelib/phone_analyzer.rb by rubocop

This cop can check for array literals made up of symbols that are not using the %i() syntax.

Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.

Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of3` will not enforce a style on an array of 2 or fewer elements.

Example: EnforcedStyle: percent (default)

# good
%i[foo bar baz]

# bad
[:foo, :bar, :baz]

Example: EnforcedStyle: brackets

# good
[:foo, :bar, :baz]

# bad
%i[foo bar baz]

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

          vanity_converted(@original).gsub(
              Phonelib.strict_check ? cr('^\+') : cr(Phonelib.sanitize_regex),
              '')
Severity: Minor
Found in lib/phonelib/phone.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.

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

        data[prefix] = line_data && line_data.strip.split('&')

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

                hash_from_xml(phone_type, :element)
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.

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 to_s over string interpolation.
Open

        Dir["#{dir}"].each do |file|
Severity: Minor
Found in lib/phonelib/data_importer.rb by rubocop

This cop checks for strings that are just an interpolated expression.

Example:

# bad
"#{@var}"

# good
@var.to_s

# good if @var is already a String
@var

Tab detected.
Open

    format_string = rule.gsub('$1', '') + format_string
Severity: Minor
Found in lib/phonelib/phone_formatter.rb by rubocop

Line is too long. [84/80]
Open

        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

Line is too long. [82/80]
Open

      return false unless @data[country][Core::NATIONAL_PREFIX] || country == 'IT'
Severity: Minor
Found in lib/phonelib/phone_formatter.rb by rubocop

Indent the first parameter one step more than the start of the previous line.
Open

              Phonelib.strict_check ? cr('^\+') : cr(Phonelib.sanitize_regex),
Severity: Minor
Found in lib/phonelib/phone.rb by rubocop

This cop checks the indentation of the first parameter in a method call. Parameters after the first one are checked by Style/AlignParameters, not by this cop.

Example:

# bad
some_method(
first_param,
second_param)

# good
some_method(
  first_param,
second_param)

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

      [split.first || '', split[1..-1] && split[1..-1].join || '']
Severity: Minor
Found in lib/phonelib/phone.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

Missing magic comment # frozen_string_literal: true.
Open

module Phonelib
Severity: Minor
Found in lib/phonelib/phone_extended_data.rb by rubocop

This cop is designed to help upgrade to Ruby 3.0. It will add the comment # frozen_string_literal: true to the top of files to enable frozen string literals. Frozen string literals may be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

Example: EnforcedStyle: when_needed (default)

# The `when_needed` style will add the frozen string literal comment
# to files only when the `TargetRubyVersion` is set to 2.3+.
# bad
module Foo
  # ...
end

# good
# frozen_string_literal: true

module Foo
  # ...
end

Example: EnforcedStyle: always

# 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

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

Missing magic comment # frozen_string_literal: true.
Open

require 'phonelib/data_importer_helper'
Severity: Minor
Found in lib/phonelib/data_importer.rb by rubocop

This cop is designed to help upgrade to Ruby 3.0. It will add the comment # frozen_string_literal: true to the top of files to enable frozen string literals. Frozen string literals may be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

Example: EnforcedStyle: when_needed (default)

# The `when_needed` style will add the frozen string literal comment
# to files only when the `TargetRubyVersion` is set to 2.3+.
# bad
module Foo
  # ...
end

# good
# frozen_string_literal: true

module Foo
  # ...
end

Example: EnforcedStyle: always

# 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

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

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

      DOUBLE_COUNTRY_CODES_COUNTRIES = %w(IN DE BR IT NO PL CU VN)
Severity: Minor
Found in lib/phonelib/data_importer.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)

Line is too long. [83/80]
Open

        national = fmt.gsub(/\$\d/) { |el| matches[el[1].to_i] } unless fmt == 'NA'
Severity: Minor
Found in lib/phonelib/phone_formatter.rb by rubocop

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

      prefix_methods = %w(international_ full_international_ e164_ full_e164_)
Severity: Minor
Found in lib/phonelib/phone_formatter.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)

Prefer to_s over string interpolation.
Open

      country_code = "#{data[Core::COUNTRY_CODE]}"

This cop checks for strings that are just an interpolated expression.

Example:

# bad
"#{@var}"

# good
@var.to_s

# good if @var is already a String
@var
Severity
Category
Status
Source
Language