Skip to content

Commit e7e1ebc

Browse files
authored
Updated channel and documentation to Rubocop v0.92.0 (#257)
Bumps the 'rubocop' dependency to v0.92.0, updates the scraped documentation, and fixes the config-upgrader spec by adding the new cops to the config-upgrader fixture.
1 parent cdf2b9c commit e7e1ebc

17 files changed

+193
-28
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ gem "activesupport", require: false
66
gem "mry", require: false
77
gem "parser"
88
gem "pry", require: false
9-
gem "rubocop", "0.90.0", require: false
9+
gem "rubocop", "0.92.0", require: false
1010
gem "rubocop-i18n", require: false
1111
gem "rubocop-migrations", require: false
1212
gem "rubocop-minitest", require: false

Gemfile.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ GEM
1818
mry (0.78.0.0)
1919
rubocop (>= 0.41.0)
2020
parallel (1.19.2)
21-
parser (2.7.1.4)
21+
parser (2.7.1.5)
2222
ast (~> 2.4.1)
2323
pry (0.13.1)
2424
coderay (~> 1.1)
2525
method_source (~> 1.0)
2626
rack (2.2.3)
2727
rainbow (3.0.0)
2828
rake (13.0.1)
29-
regexp_parser (1.7.1)
29+
regexp_parser (1.8.1)
3030
rexml (3.2.4)
3131
rspec (3.9.0)
3232
rspec-core (~> 3.9.0)
@@ -41,17 +41,17 @@ GEM
4141
diff-lcs (>= 1.2.0, < 2.0)
4242
rspec-support (~> 3.9.0)
4343
rspec-support (3.9.3)
44-
rubocop (0.90.0)
44+
rubocop (0.92.0)
4545
parallel (~> 1.10)
46-
parser (>= 2.7.1.1)
46+
parser (>= 2.7.1.5)
4747
rainbow (>= 2.2.2, < 4.0)
4848
regexp_parser (>= 1.7)
4949
rexml
50-
rubocop-ast (>= 0.3.0, < 1.0)
50+
rubocop-ast (>= 0.5.0)
5151
ruby-progressbar (~> 1.7)
5252
unicode-display_width (>= 1.4.0, < 2.0)
53-
rubocop-ast (0.3.0)
54-
parser (>= 2.7.1.4)
53+
rubocop-ast (0.7.1)
54+
parser (>= 2.7.1.5)
5555
rubocop-i18n (2.0.2)
5656
rubocop (~> 0.51)
5757
rubocop-migrations (0.1.2)
@@ -91,7 +91,7 @@ DEPENDENCIES
9191
pry
9292
rake
9393
rspec
94-
rubocop (= 0.90.0)
94+
rubocop (= 0.92.0)
9595
rubocop-i18n
9696
rubocop-migrations
9797
rubocop-minitest
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
This cop checks whether the end keyword of `begin` is aligned properly.
2+
3+
Two modes are supported through the `EnforcedStyleAlignWith` configuration
4+
parameter. If it's set to `start_of_line` (which is the default), the
5+
`end` shall be aligned with the start of the line where the `begin`
6+
keyword is. If it's set to `begin`, the `end` shall be aligned with the
7+
`begin` keyword.
8+
9+
`Layout/EndAlignment` cop aligns with keywords (e.g. `if`, `while`, `case`)
10+
by default. On the other hand, `||= begin` that this cop targets tends to
11+
align with the start of the line, it defaults to `EnforcedStyleAlignWith: start_of_line`.
12+
These style can be configured by each cop.
13+
14+
### Example: EnforcedStyleAlignWith: start_of_line (default)
15+
# bad
16+
foo ||= begin
17+
do_something
18+
end
19+
20+
# good
21+
foo ||= begin
22+
do_something
23+
end
24+
25+
### Example: EnforcedStyleAlignWith: begin
26+
# bad
27+
foo ||= begin
28+
do_something
29+
end
30+
31+
# good
32+
foo ||= begin
33+
do_something
34+
end

config/contents/layout/end_alignment.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ left-hand-side of the variable assignment, if there is one.
1212
If it's set to `start_of_line`, the `end` shall be aligned with the
1313
start of the line where the matching keyword appears.
1414

15+
This `Layout/EndAlignment` cop aligns with keywords (e.g. `if`, `while`, `case`)
16+
by default. On the other hand, `Layout/BeginEndAlignment` cop aligns with
17+
`EnforcedStyleAlignWith: start_of_line` by default due to `||= begin` tends
18+
to align with the start of the line. These style can be configured by each cop.
19+
1520
### Example: EnforcedStyleAlignWith: keyword (default)
1621
# bad
1722

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Do not define constants within a block, since the block's scope does not
2+
isolate or namespace the constant in any way.
3+
4+
If you are trying to define that constant once, define it outside of
5+
the block instead, or use a variable or method if defining the constant
6+
in the outer scope would be problematic.
7+
8+
For meta-programming, use `const_set`.
9+
10+
### Example:
11+
# bad
12+
task :lint do
13+
FILES_TO_LINT = Dir['lib/*.rb']
14+
end
15+
16+
# bad
17+
describe 'making a request' do
18+
class TestRequest; end
19+
end
20+
21+
# bad
22+
module M
23+
extend ActiveSupport::Concern
24+
included do
25+
LIST = []
26+
end
27+
end
28+
29+
# good
30+
task :lint do
31+
files_to_lint = Dir['lib/*.rb']
32+
end
33+
34+
# good
35+
describe 'making a request' do
36+
let(:test_request) { Class.new }
37+
# see also `stub_const` for RSpec
38+
end
39+
40+
# good
41+
module M
42+
extend ActiveSupport::Concern
43+
included do
44+
const_set(:LIST, [])
45+
end
46+
end

config/contents/lint/duplicate_require.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ This cop checks for duplicate `require`s and `require_relative`s.
99
# good
1010
require 'foo'
1111
require 'bar'
12+
13+
# good
14+
require 'foo'
15+
require_relative 'foo'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
Prefer `equal?` over `==` when comparing `object_id`.
3+
4+
`Object#equal?` is provided to compare objects for identity, and in contrast
5+
`Object#==` is provided for the purpose of doing value comparison.
6+
7+
### Example:
8+
# bad
9+
foo.object_id == bar.object_id
10+
11+
# good
12+
foo.equal?(bar)

config/contents/lint/to_json.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,21 @@ generation via `JSON.generate(your_obj)`. Since `JSON#generate` allows
44
for an optional argument, your method should too.
55

66
### Example:
7-
# bad
8-
def to_json
9-
end
7+
class Point
8+
attr_reader :x, :y
9+
10+
# bad, incorrect arity
11+
def to_json
12+
JSON.generate([x, y])
13+
end
14+
15+
# good, preserving args
16+
def to_json(*args)
17+
JSON.generate([x, y], *args)
18+
end
1019

11-
# good
12-
def to_json(*_args)
20+
# good, discarding args
21+
def to_json(*_args)
22+
JSON.generate([x, y])
23+
end
1324
end

config/contents/lint/useless_method_definition.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,24 @@ an empty constructor just overrides the parent constructor, which is bad anyway.
77
### Example:
88
# bad
99
def initialize
10+
super
1011
end
1112

1213
def method
1314
super
1415
end
1516

16-
# good
17-
def initialize
18-
initialize_internals
19-
end
20-
21-
def method
17+
# good - with default arguments
18+
def initialize(x = Object.new)
2219
super
23-
do_something_else
2420
end
2521

26-
### Example: AllowComments: true (default)
2722
# good
2823
def initialize
29-
# Comment.
24+
super
25+
initialize_internals
3026
end
3127

32-
### Example: AllowComments: false
33-
# bad
34-
def initialize
35-
# Comment.
28+
def method(*args)
29+
super(:extra_arg, *args)
3630
end

config/contents/lint/useless_times.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
This cop checks for uses of `Integer#times` that will never yield
2+
(when the integer <= 0) or that will only ever yield once
3+
(`1.times`).
4+
5+
This cop is marked as unsafe as `times` returns its receiver, which
6+
is *usually* OK, but might change behavior.
7+
8+
### Example:
9+
# bad
10+
-5.times { do_something }
11+
0.times { do_something }
12+
1.times { do_something }
13+
1.times { |i| do_something(i) }
14+
15+
# good
16+
do_something
17+
do_something(1)

0 commit comments

Comments
 (0)