codeclimate/codeclimate-duplication

View on GitHub

Showing 107 of 107 total issues

Missing magic comment # frozen_string_literal: true.
Open

module CC
Severity: Minor
Found in lib/cc/engine/parse_metrics.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

Avoid comma after the last item of a hash.
Open

              },

This cop checks for trailing comma in array and hash literals.

Example: EnforcedStyleForMultiline: consistent_comma

# bad
a = [1, 2,]

# good
a = [
  1, 2,
  3,
]

# good
a = [
  1,
  2,
]

Example: EnforcedStyleForMultiline: comma

# bad
a = [1, 2,]

# good
a = [
  1,
  2,
]

Example: EnforcedStyleForMultiline: no_comma (default)

# bad
a = [1, 2,]

# good
a = [
  1,
  2
]

Freeze mutable objects assigned to constants.
Open

          DEFAULT_FILTERS = [
            "(ImportDeclaration ___)".freeze,
          ]

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

Align else with if.
Open

            else

This cops checks the alignment of else keywords. Normally they should be aligned with an if/unless/while/until/begin/def keyword, but there are special cases when they should follow the same rules as the alignment of end.

Example:

# bad
if something
  code
 else
  code
end

# bad
if something
  code
 elsif something
  code
end

# good
if something
  code
else
  code
end

Avoid rescuing without specifying an error class.
Open

        rescue => ex

This cop checks for rescuing StandardError. There are two supported styles implicit and explicit. This cop will not register an offense if any error other than StandardError is specified.

Example: EnforcedStyle: implicit

# `implicit` will enforce using `rescue` instead of
# `rescue StandardError`.

# bad
begin
  foo
rescue StandardError
  bar
end

# good
begin
  foo
rescue
  bar
end

# good
begin
  foo
rescue OtherError
  bar
end

# good
begin
  foo
rescue StandardError, SecurityError
  bar
end

Example: EnforcedStyle: explicit (default)

# `explicit` will enforce using `rescue StandardError`
# instead of `rescue`.

# bad
begin
  foo
rescue
  bar
end

# good
begin
  foo
rescue StandardError
  bar
end

# good
begin
  foo
rescue OtherError
  bar
end

# good
begin
  foo
rescue StandardError, SecurityError
  bar
end

Avoid comma after the last item of an array.
Open

            "**/*.jsx",

This cop checks for trailing comma in array and hash literals.

Example: EnforcedStyleForMultiline: consistent_comma

# bad
a = [1, 2,]

# good
a = [
  1, 2,
  3,
]

# good
a = [
  1,
  2,
]

Example: EnforcedStyleForMultiline: comma

# bad
a = [1, 2,]

# good
a = [
  1,
  2,
]

Example: EnforcedStyleForMultiline: no_comma (default)

# bad
a = [1, 2,]

# good
a = [
  1,
  2
]

Avoid comma after the last item of an array.
Open

            "**/*.rb",

This cop checks for trailing comma in array and hash literals.

Example: EnforcedStyleForMultiline: consistent_comma

# bad
a = [1, 2,]

# good
a = [
  1, 2,
  3,
]

# good
a = [
  1,
  2,
]

Example: EnforcedStyleForMultiline: comma

# bad
a = [1, 2,]

# good
a = [
  1,
  2,
]

Example: EnforcedStyleForMultiline: no_comma (default)

# bad
a = [1, 2,]

# good
a = [
  1,
  2
]

Do not freeze immutable objects, as freezing them has no effect.
Open

          REQUEST_PATH = "/java".freeze

This cop check for uses of Object#freeze on immutable objects.

Example:

# bad
CONST = 1.freeze

# good
CONST = 1

Do not freeze immutable objects, as freezing them has no effect.
Open

          LANGUAGE = "kotlin".freeze

This cop check for uses of Object#freeze on immutable objects.

Example:

# bad
CONST = 1.freeze

# good
CONST = 1

Do not freeze immutable objects, as freezing them has no effect.
Open

          REQUEST_PATH = "/typescript".freeze

This cop check for uses of Object#freeze on immutable objects.

Example:

# bad
CONST = 1.freeze

# good
CONST = 1

Do not freeze immutable objects, as freezing them has no effect.
Open

            "(KDoc ___)".freeze,

This cop check for uses of Object#freeze on immutable objects.

Example:

# bad
CONST = 1.freeze

# good
CONST = 1

Use 2 (not 11) spaces for indenting an expression in an assignment spanning multiple lines.
Open

                     fetch(language, {})

This cop checks the indentation of the method name part in method calls that span more than one line.

Example: EnforcedStyle: aligned

# bad
while myvariable
.b
  # do something
end

# good
while myvariable
      .b
  # do something
end

# good
Thing.a
     .b
     .c

Example: EnforcedStyle: indented

# good
while myvariable
  .b

  # do something
end

Example: EnforcedStyle: indentedrelativeto_receiver

# good
while myvariable
        .a
        .b

  # do something
end

# good
myvariable = Thing
               .a
               .b
               .c

Avoid comma after the last item of an array.
Open

            "(EOL_COMMENT ___)".freeze,

This cop checks for trailing comma in array and hash literals.

Example: EnforcedStyleForMultiline: consistent_comma

# bad
a = [1, 2,]

# good
a = [
  1, 2,
  3,
]

# good
a = [
  1,
  2,
]

Example: EnforcedStyleForMultiline: comma

# bad
a = [1, 2,]

# good
a = [
  1,
  2,
]

Example: EnforcedStyleForMultiline: no_comma (default)

# bad
a = [1, 2,]

# good
a = [
  1,
  2
]

Prefer {...} over do...end for functional blocks.
Open

          tuples = Duplication::LANGUAGES.map do |language, _|

Check for uses of braces or do/end around single line or multi-line blocks.

Example: EnforcedStyle: linecountbased (default)

# bad - single line block
items.each do |item| item / 5 end

# good - single line block
items.each { |item| item / 5 }

# bad - multi-line block
things.map { |thing|
  something = thing.some_method
  process(something)
}

# good - multi-line block
things.map do |thing|
  something = thing.some_method
  process(something)
end

Example: EnforcedStyle: semantic

# Prefer `do...end` over `{...}` for procedural blocks.

# return value is used/assigned
# bad
foo = map do |x|
  x
end
puts (map do |x|
  x
end)

# return value is not used out of scope
# good
map do |x|
  x
end

# Prefer `{...}` over `do...end` for functional blocks.

# return value is not used out of scope
# bad
each { |x|
  x
}

# return value is used/assigned
# good
foo = map { |x|
  x
}
map { |x|
  x
}.inspect

Example: EnforcedStyle: bracesforchaining

# bad
words.each do |word|
  word.flip.flop
end.join("-")

# good
words.each { |word|
  word.flip.flop
}.join("-")

Use 2 (not 4) spaces for indentation.
Open

              Object.const_get $1

This cops checks for indentation that doesn't use the specified number of spaces.

See also the IndentationConsistency cop which is the companion to this one.

Example:

# bad
class A
 def test
  puts 'hello'
 end
end

# good
class A
  def test
    puts 'hello'
  end
end

Example: IgnoredPatterns: ['^\s*module']

# bad
module A
class B
  def test
  puts 'hello'
  end
end
end

# good
module A
class B
  def test
    puts 'hello'
  end
end
end

Favor format over String#%.
Open

          raise SyntaxError, "unhandled token: %p" % [token]

This cop enforces the use of a single string formatting utility. Valid options include Kernel#format, Kernel#sprintf and String#%.

The detection of String#% cannot be implemented in a reliable manner for all cases, so only two scenarios are considered - if the first argument is a string literal and if the second argument is an array literal.

Example: EnforcedStyle: format(default)

# bad
puts sprintf('%10s', 'hoge')
puts '%10s' % 'hoge'

# good
puts format('%10s', 'hoge')

Example: EnforcedStyle: sprintf

# bad
puts format('%10s', 'hoge')
puts '%10s' % 'hoge'

# good
puts sprintf('%10s', 'hoge')

Example: EnforcedStyle: percent

# bad
puts format('%10s', 'hoge')
puts sprintf('%10s', 'hoge')

# good
puts '%10s' % 'hoge'

Do not freeze immutable objects, as freezing them has no effect.
Open

          LANGUAGE = "java".freeze

This cop check for uses of Object#freeze on immutable objects.

Example:

# bad
CONST = 1.freeze

# good
CONST = 1

Add an empty line after magic comments.
Open

begin
Severity: Minor
Found in Rakefile by rubocop

Checks for a newline after the final magic comment.

Example:

# good
# frozen_string_literal: true

# Some documentation for Person
class Person
  # Some code
end

# bad
# frozen_string_literal: true
# Some documentation for Person
class Person
  # Some code
end

Avoid comma after the last item of a hash.
Open

          value: count,
Severity: Minor
Found in lib/cc/engine/parse_metrics.rb by rubocop

This cop checks for trailing comma in array and hash literals.

Example: EnforcedStyleForMultiline: consistent_comma

# bad
a = [1, 2,]

# good
a = [
  1, 2,
  3,
]

# good
a = [
  1,
  2,
]

Example: EnforcedStyleForMultiline: comma

# bad
a = [1, 2,]

# good
a = [
  1,
  2,
]

Example: EnforcedStyleForMultiline: no_comma (default)

# bad
a = [1, 2,]

# good
a = [
  1,
  2
]

Do not freeze immutable objects, as freezing them has no effect.
Open

          REQUEST_PATH = "/javascript".freeze

This cop check for uses of Object#freeze on immutable objects.

Example:

# bad
CONST = 1.freeze

# good
CONST = 1
Severity
Category
Status
Source
Language