Skip to content

Update rubocop to 1.24.1 #309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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 @@ -6,7 +6,7 @@ gem "activesupport", require: false
gem "mry", require: false
gem "parser"
gem "pry", require: false
gem "rubocop", "1.23.0", require: false
gem "rubocop", "1.24.1", require: false
gem "rubocop-i18n", require: false
gem "rubocop-graphql", require: false
gem "rubocop-minitest", require: false
Expand Down
31 changes: 16 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (6.1.4.1)
activesupport (7.0.0)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
ast (2.4.2)
coderay (1.1.3)
concurrent-ruby (1.1.9)
diff-lcs (1.4.4)
diff-lcs (1.5.0)
i18n (1.8.11)
concurrent-ruby (~> 1.0)
method_source (1.0.0)
minitest (5.14.4)
minitest (5.15.0)
mry (0.78.0.0)
rubocop (>= 0.41.0)
parallel (1.21.0)
parser (3.0.3.1)
parser (3.1.0.0)
ast (~> 2.4.1)
pry (0.14.1)
coderay (~> 1.1)
Expand All @@ -41,37 +40,39 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.3)
rubocop (1.23.0)
rubocop (1.24.1)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.12.0, < 2.0)
rubocop-ast (>= 1.15.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.14.0)
rubocop-ast (1.15.1)
parser (>= 3.0.1.1)
rubocop-graphql (0.11.2)
rubocop-graphql (0.12.0)
rubocop (>= 0.87, < 2)
rubocop-i18n (3.0.0)
rubocop (~> 1.0)
rubocop-minitest (0.17.0)
rubocop (>= 0.90, < 2.0)
rubocop-performance (1.12.0)
rubocop-performance (1.13.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.12.4)
rubocop-rails (2.13.0)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (2.6.0)
rubocop-rspec (2.7.0)
rubocop (~> 1.19)
rubocop-sequel (0.3.3)
rubocop (~> 1.0)
rubocop-sorbet (0.6.3)
rubocop-shopify (2.3.0)
rubocop (~> 1.22)
rubocop-sorbet (0.6.5)
rubocop (>= 0.90.0)
rubocop-thread_safety (0.4.4)
rubocop (>= 0.53.0)
Expand All @@ -81,7 +82,6 @@ GEM
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (2.1.0)
zeitwerk (2.5.1)

PLATFORMS
ruby
Expand All @@ -93,7 +93,7 @@ DEPENDENCIES
pry
rake
rspec
rubocop (= 1.23.0)
rubocop (= 1.24.1)
rubocop-graphql
rubocop-i18n
rubocop-minitest
Expand All @@ -102,6 +102,7 @@ DEPENDENCIES
rubocop-rake
rubocop-rspec
rubocop-sequel
rubocop-shopify
rubocop-sorbet
rubocop-thread_safety
safe_yaml
Expand Down
10 changes: 5 additions & 5 deletions config/contents/gemspec/require_mfa.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Requires a gemspec to have `rubygems_mfa_required` metadata set.

This setting tells RubyGems that MFA is required for accounts to
be able perform any of these privileged operations:
be able perform privileged operations, such as (see
RubyGems' documentation for the full list of privileged operations):

* gem push
* gem yank
* gem owner --add/remove
* `gem push`
* `gem yank`
* `gem owner --add/remove`
* adding or removing owners using gem ownership page

This helps make your gem more secure, as users can be more
confident that gem updates were pushed by maintainers.

### Example:

# bad
Gem::Specification.new do |spec|
# no `rubygems_mfa_required` metadata specified
Expand Down
14 changes: 14 additions & 0 deletions config/contents/layout/comment_indentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,17 @@ This cop checks the indentation of comments.
if true
true
end

### Example: AllowForAlignment: false (default)
# bad
a = 1 # A really long comment
# spanning two lines.

# good
# A really long comment spanning one line.
a = 1

### Example: AllowForAlignment: true
# good
a = 1 # A really long comment
# spanning two lines.
2 changes: 2 additions & 0 deletions config/contents/lint/deprecated_class_methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This cop checks for uses of the deprecated class method usages.
File.exists?(some_path)
Dir.exists?(some_path)
iterator?
ENV.freeze # Calling `Env.freeze` raises `TypeError` since Ruby 2.7.
Socket.gethostbyname(host)
Socket.gethostbyaddr(host)

Expand All @@ -17,5 +18,6 @@ This cop checks for uses of the deprecated class method usages.
File.exist?(some_path)
Dir.exist?(some_path)
block_given?
ENV # `ENV.freeze` cannot prohibit changes to environment variables.
Addrinfo.getaddrinfo(nodename, service)
Addrinfo.tcp(host, port).getnameinfo
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ This cop checks for `IO.select` that is incompatible with Fiber Scheduler since

# good
io.wait_writable(timeout)

### Safety:

This cop's autocorrection is unsafe because `NoMethodError` occurs
if `require 'io/wait'` is not called.
30 changes: 30 additions & 0 deletions config/contents/naming/block_forwarding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
In Ruby 3.1, anonymous block forwarding has been added.

This cop identifies places where `do_something(&block)` can be replaced
by `do_something(&)`.

It also supports the opposite style by alternative `explicit` option.

### Example: EnforcedStyle: anonymous (default)

# bad
def foo(&block)
bar(&block)
end

# good
def foo(&)
bar(&)
end

### Example: EnforcedStyle: explicit

# bad
def foo(&)
bar(&)
end

# good
def foo(&block)
bar(&block)
end
14 changes: 12 additions & 2 deletions config/contents/security/open.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
This cop checks for the use of `Kernel#open` and `URI.open`.
This cop checks for the use of `Kernel#open` and `URI.open` with dynamic
data.

`Kernel#open` and `URI.open` enable not only file access but also process
invocation by prefixing a pipe symbol (e.g., `open("| ls")`).
So, it may lead to a serious security risk by using variable input to
the argument of `Kernel#open` and `URI.open`. It would be better to use
`File.open`, `IO.popen` or `URI.parse#open` explicitly.

NOTE: `open` and `URI.open` with literal strings are not flagged by this
cop.

### Safety:

This cop could register false positives if `open` is redefined
Expand All @@ -14,9 +18,15 @@ in a class and then used without a receiver in that class.
### Example:
# bad
open(something)
open("| #{something}")
URI.open(something)

# good
File.open(something)
IO.popen(something)
URI.parse(something).open
URI.parse(something).open

# good (literal strings)
open("foo.text")
open("| foo")
URI.open("http://example.com")
11 changes: 9 additions & 2 deletions config/contents/style/character_literal.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
Checks for uses of the character literal ?x.
Starting with Ruby 1.9 character literals are
essentially one-character strings, so this syntax
is mostly redundant at this point.

? character literal can be used to express meta and control character.
That's a good use case of ? literal so it doesn't count it as an offense.

### Example:
# bad
Expand All @@ -7,5 +13,6 @@ Checks for uses of the character literal ?x.
# good
'x'

# good
?\C-\M-d
# good - control & meta escapes
?\C-\M-d
"\C-\M-d" # same as above
2 changes: 2 additions & 0 deletions config/contents/style/collection_compact.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ when the receiver is a hash object.

### Example:
# bad
array.reject(&:nil?)
array.reject { |e| e.nil? }
array.select { |e| !e.nil? }

# good
array.compact

# bad
hash.reject!(&:nil?)
hash.reject! { |k, v| v.nil? }
hash.select! { |k, v| !v.nil? }

Expand Down
31 changes: 31 additions & 0 deletions config/contents/style/file_read.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Favor `File.(bin)read` convenience methods.

### Example:
## text mode
# bad
File.open(filename).read
File.open(filename, &:read)
File.open(filename) { |f| f.read }
File.open(filename) do |f|
f.read
end
File.open(filename, 'r').read
File.open(filename, 'r', &:read)
File.open(filename, 'r') do |f|
f.read
end

# good
File.read(filename)

### Example:
## binary mode
# bad
File.open(filename, 'rb').read
File.open(filename, 'rb', &:read)
File.open(filename, 'rb') do |f|
f.read
end

# good
File.binread(filename)
23 changes: 23 additions & 0 deletions config/contents/style/file_write.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Favor `File.(bin)write` convenience methods.

### Example:
## text mode
# bad
File.open(filename, 'w').write(content)
File.open(filename, 'w') do |f|
f.write(content)
end

# good
File.write(filename, content)

### Example:
## binary mode
# bad
File.open(filename, 'wb').write(content)
File.open(filename, 'wb') do |f|
f.write(content)
end

# good
File.binwrite(filename, content)
22 changes: 21 additions & 1 deletion config/contents/style/hash_syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ all symbols for keys
* ruby19_no_mixed_keys - forces use of ruby 1.9 syntax and forbids mixed
syntax hashes

This cop has `EnforcedShorthandSyntax` option.
It can enforce either the use of the explicit hash value syntax or
the use of Ruby 3.1's hash value shorthand syntax.

### Example: EnforcedStyle: ruby19 (default)
# bad
{:a => 2}
Expand Down Expand Up @@ -48,4 +52,20 @@ syntax hashes

# good
{a: 1, b: 2}
{:c => 3, 'd' => 4}
{:c => 3, 'd' => 4}

### Example: EnforcedShorthandSyntax: always (default)

# bad
{foo: foo, bar: bar}

# good
{foo:, bar:}

### Example: EnforcedShorthandSyntax: never

# bad
{foo:, bar:}

# good
{foo: foo, bar: bar}
24 changes: 24 additions & 0 deletions config/contents/style/map_to_hash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This cop looks for uses of `map.to_h` or `collect.to_h` that could be
written with just `to_h` in Ruby >= 2.6.

NOTE: `Style/HashTransformKeys` and `Style/HashTransformValues` will
also change this pattern if only hash keys or hash values are being
transformed.

### Safety:

This cop is unsafe, as it can produce false positives if the receiver
is not an `Enumerable`.

### Example:
# bad
something.map { |v| [v, v * 2] }.to_h

# good
something.to_h { |v| [v, v * 2] }

# bad
{foo: bar}.collect { |k, v| [k.to_s, v.do_something] }.to_h

# good
{foo: bar}.to_h { |k, v| [k.to_s, v.do_something] }
Loading