Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source 'https://rubygems.org'
gem "activesupport", require: false
gem "parser"
gem "pry", require: false
gem "rubocop", "1.39.0", require: false
gem "rubocop", "1.40.0", require: false
gem "rubocop-i18n", require: false
gem "rubocop-graphql", require: false
gem "rubocop-minitest", require: false
Expand Down
26 changes: 13 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ GEM
diff-lcs (1.5.0)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
json (2.6.2)
json (2.6.3)
method_source (1.0.0)
minitest (5.16.3)
parallel (1.22.1)
parser (3.1.2.1)
parser (3.1.3.0)
ast (~> 2.4.1)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
rack (3.0.0)
rack (3.0.2)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.6.0)
regexp_parser (2.6.1)
rexml (3.2.5)
rspec (3.12.0)
rspec-core (~> 3.12.0)
Expand All @@ -35,11 +35,11 @@ GEM
rspec-expectations (3.12.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.0)
rspec-mocks (3.12.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.0)
rubocop (1.39.0)
rubocop (1.40.0)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.1.2.1)
Expand All @@ -49,24 +49,24 @@ GEM
rubocop-ast (>= 1.23.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.23.0)
rubocop-ast (1.24.0)
parser (>= 3.1.1.0)
rubocop-graphql (0.18.0)
rubocop (>= 0.87, < 2)
rubocop-i18n (3.0.0)
rubocop (~> 1.0)
rubocop-minitest (0.23.2)
rubocop-minitest (0.25.0)
rubocop (>= 0.90, < 2.0)
rubocop-performance (1.15.0)
rubocop-performance (1.15.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.17.2)
rubocop-rails (2.17.3)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (2.15.0)
rubocop-rspec (2.16.0)
rubocop (~> 1.33)
rubocop-sequel (0.3.4)
rubocop (~> 1.0)
Expand All @@ -77,7 +77,7 @@ GEM
rubocop-thread_safety (0.4.4)
rubocop (>= 0.53.0)
ruby-progressbar (1.11.0)
test-prof (1.0.11)
test-prof (1.1.0)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
unicode-display_width (2.3.0)
Expand All @@ -91,7 +91,7 @@ DEPENDENCIES
pry
rake
rspec
rubocop (= 1.39.0)
rubocop (= 1.40.0)
rubocop-graphql
rubocop-i18n
rubocop-minitest
Expand Down
5 changes: 5 additions & 0 deletions config/contents/lint/assignment_in_condition.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ By safe assignment we mean putting parentheses around
an assignment to indicate "I know I'm using an assignment
as a condition. It's not a mistake."

### Safety:

This cop's autocorrection is unsafe because it assumes that
the author meant to use an assignment result as a condition.

### Example:
# bad
if some_var = true
Expand Down
9 changes: 8 additions & 1 deletion config/contents/lint/deprecated_constants.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@ alternative value as `Alternative`. And you can set the deprecated version as
Alternative: 'alternative_value'
DeprecatedVersion: 'deprecated_version'

By default, `NIL`, `TRUE`, `FALSE` and `Random::DEFAULT` are configured.
By default, `NIL`, `TRUE`, `FALSE`, `Net::HTTPServerException, `Random::DEFAULT`,
`Struct::Group`, and `Struct::Passwd` are configured.

### Example:

# bad
NIL
TRUE
FALSE
Net::HTTPServerException
Random::DEFAULT # Return value of Ruby 2 is `Random` instance, Ruby 3.0 is `Random` class.
Struct::Group
Struct::Passwd

# good
nil
true
false
Net::HTTPClientException
Random.new # `::DEFAULT` has been deprecated in Ruby 3, `.new` is compatible with Ruby 2.
Etc::Group
Etc::Passwd
7 changes: 4 additions & 3 deletions config/contents/lint/interpolation_check.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ Checks for interpolation in a single quoted string.

### Safety:

This cop is generally safe, but is marked as unsafe because
it is possible to actually intentionally have text inside
`#{...}` in a single quoted string.
This cop's autocorrection is unsafe because although it always replaces single quotes as
if it were miswritten double quotes, it is not always the case. For example,
`'#{foo} bar'` would be replaced by `"#{foo} bar"`, so the replaced code would evaluate
the expression `foo`.

### Example:

Expand Down
2 changes: 1 addition & 1 deletion config/contents/lint/void.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Checks for operators, variables, literals, and nonmutating
Checks for operators, variables, literals, lambda, proc and nonmutating
methods used in void context.

### Example: CheckForMethodsWithNoSideEffects: false (default)
Expand Down
13 changes: 9 additions & 4 deletions config/contents/metrics/block_length.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ Comment lines can optionally be ignored.
The maximum allowed length is configurable.
The cop can be configured to ignore blocks passed to certain methods.

You can set literals you want to fold with `CountAsOne`.
Available are: 'array', 'hash', and 'heredoc'. Each literal
You can set constructs you want to fold with `CountAsOne`.
Available are: 'array', 'hash', 'heredoc', and 'method_call'. Each construct
will be counted as one line regardless of its actual size.


NOTE: The `ExcludedMethods` configuration is deprecated and only kept
for backwards compatibility. Please use `AllowedMethods` and `AllowedPatterns`
instead. By default, there are no methods to allowed.

### Example: CountAsOne: ['array', 'heredoc']
### Example: CountAsOne: ['array', 'heredoc', 'method_call']

something do
array = [ # +1
Expand All @@ -28,6 +28,11 @@ instead. By default, there are no methods to allowed.
Heredoc
content.
HEREDOC
end # 5 points

foo( # +1
1,
2
)
end # 6 points

NOTE: This cop does not apply for `Struct` definitions.
13 changes: 9 additions & 4 deletions config/contents/metrics/class_length.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ Checks if the length a class exceeds some maximum value.
Comment lines can optionally be ignored.
The maximum allowed length is configurable.

You can set literals you want to fold with `CountAsOne`.
Available are: 'array', 'hash', and 'heredoc'. Each literal
You can set constructs you want to fold with `CountAsOne`.
Available are: 'array', 'hash', 'heredoc', and 'method_call'. Each construct
will be counted as one line regardless of its actual size.

### Example: CountAsOne: ['array', 'heredoc']
### Example: CountAsOne: ['array', 'heredoc', 'method_call']

class Foo
ARRAY = [ # +1
Expand All @@ -22,7 +22,12 @@ will be counted as one line regardless of its actual size.
Heredoc
content.
HEREDOC
end # 5 points

foo( # +1
1,
2
)
end # 6 points


NOTE: This cop also applies for `Struct` definitions.
13 changes: 9 additions & 4 deletions config/contents/metrics/method_length.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ Checks if the length of a method exceeds some maximum value.
Comment lines can optionally be allowed.
The maximum allowed length is configurable.

You can set literals you want to fold with `CountAsOne`.
Available are: 'array', 'hash', and 'heredoc'. Each literal
You can set constructs you want to fold with `CountAsOne`.
Available are: 'array', 'hash', 'heredoc', and 'method_call'. Each construct
will be counted as one line regardless of its actual size.

NOTE: The `ExcludedMethods` and `IgnoredMethods` configuration is
deprecated and only kept for backwards compatibility.
Please use `AllowedMethods` and `AllowedPatterns` instead.
By default, there are no methods to allowed.

### Example: CountAsOne: ['array', 'heredoc']
### Example: CountAsOne: ['array', 'heredoc', 'method_call']

def m
array = [ # +1
Expand All @@ -27,4 +27,9 @@ By default, there are no methods to allowed.
Heredoc
content.
HEREDOC
end # 5 points

foo( # +1
1,
2
)
end # 6 points
13 changes: 9 additions & 4 deletions config/contents/metrics/module_length.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ Checks if the length a module exceeds some maximum value.
Comment lines can optionally be ignored.
The maximum allowed length is configurable.

You can set literals you want to fold with `CountAsOne`.
Available are: 'array', 'hash', and 'heredoc'. Each literal
You can set constructs you want to fold with `CountAsOne`.
Available are: 'array', 'hash', 'heredoc', and 'method_call'. Each construct
will be counted as one line regardless of its actual size.

### Example: CountAsOne: ['array', 'heredoc']
### Example: CountAsOne: ['array', 'heredoc', 'method_call']

module M
ARRAY = [ # +1
Expand All @@ -22,4 +22,9 @@ will be counted as one line regardless of its actual size.
Heredoc
content.
HEREDOC
end # 5 points

foo( # +1
1,
2
)
end # 6 points
35 changes: 35 additions & 0 deletions config/contents/style/array_intersect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
In Ruby 3.1, `Array#intersect?` has been added.

This cop identifies places where `(array1 & array2).any?`
can be replaced by `array1.intersect?(array2)`.

The `array1.intersect?(array2)` method is faster than
`(array1 & array2).any?` and is more readable.

### Safety:

This cop cannot guarantee that array1 and array2 are
actually arrays while method `intersect?` is for arrays only.

### Example:
# bad
(array1 & array2).any?
(array1 & array2).empty?

# good
array1.intersect?(array2)
!array1.intersect?(array2)

### Example: AllCops:ActiveSupportExtensionsEnabled: false (default)
# good
(array1 & array2).present?
(array1 & array2).blank?

### Example: AllCops:ActiveSupportExtensionsEnabled: true
# bad
(array1 & array2).present?
(array1 & array2).blank?

# good
array1.intersect?(array2)
!array1.intersect?(array2)
3 changes: 3 additions & 0 deletions config/contents/style/redundant_argument.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Method names and their redundant arguments can be configured like this:
```yaml
Methods:
join: ''
sum: 0
split: ' '
chomp: "\n"
chomp!: "\n"
Expand All @@ -28,6 +29,7 @@ This cop is unsafe because of the following limitations:
# bad
array.join('')
[1, 2, 3].join("")
array.sum(0)
string.split(" ")
"first\nsecond".split(" ")
string.chomp("\n")
Expand All @@ -37,6 +39,7 @@ This cop is unsafe because of the following limitations:
# good
array.join
[1, 2, 3].join
array.sum
string.split
"first second".split
string.chomp
Expand Down
33 changes: 33 additions & 0 deletions config/contents/style/redundant_constant_base.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Avoid redundant `::` prefix on constant.

How Ruby searches constant is a bit complicated, and it can often be difficult to
understand from the code whether the `::` is intended or not. Where `Module.nesting`
is empty, there is no need to prepend `::`, so it would be nice to consistently
avoid such meaningless `::` prefix to avoid confusion.

### Example:
# bad
::Const

# good
Const

# bad
class << self
::Const
end

# good
class << self
Const
end

# good
class A
::Const
end

# good
module A
::Const
end
Loading