Skip to content

Commit f1300f1

Browse files
authored
Updated engine and docs for Rubocop v0.52.1. (#116)
* Updated engine and docs for Rubocop v0.52.1. * Remove newly-documented cops from undocumented list.
1 parent 35028b0 commit f1300f1

15 files changed

+320
-28
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ gem "activesupport", require: false
66
gem "mry", "~> 0.52.0", require: false
77
gem "parser", "~> 2.4.0"
88
gem "pry", require: false
9-
gem "rubocop", "~> 0.52.0", require: false
9+
gem "rubocop", "~> 0.52.1", require: false
1010
gem "rubocop-migrations", require: false
1111
gem "rubocop-rspec", require: false
1212
gem "safe_yaml"

Gemfile.lock

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ GEM
1616
minitest (5.10.3)
1717
mry (0.52.0.0)
1818
rubocop (>= 0.41.0)
19-
parallel (1.12.0)
19+
parallel (1.12.1)
2020
parser (2.4.0.2)
2121
ast (~> 2.3)
2222
powerpack (0.1.1)
@@ -38,7 +38,7 @@ GEM
3838
diff-lcs (>= 1.2.0, < 2.0)
3939
rspec-support (~> 3.7.0)
4040
rspec-support (3.7.0)
41-
rubocop (0.52.0)
41+
rubocop (0.52.1)
4242
parallel (~> 1.10)
4343
parser (>= 2.4.0.2, < 3.0)
4444
powerpack (~> 0.1)
@@ -47,8 +47,8 @@ GEM
4747
unicode-display_width (~> 1.0, >= 1.0.1)
4848
rubocop-migrations (0.1.2)
4949
rubocop (~> 0.41)
50-
rubocop-rspec (1.20.1)
51-
rubocop (>= 0.51.0)
50+
rubocop-rspec (1.21.0)
51+
rubocop (>= 0.52.0)
5252
ruby-progressbar (1.9.0)
5353
safe_yaml (1.0.4)
5454
thread_safe (0.3.6)
@@ -66,10 +66,10 @@ DEPENDENCIES
6666
pry
6767
rake
6868
rspec
69-
rubocop (~> 0.52.0)
69+
rubocop (~> 0.52.1)
7070
rubocop-migrations
7171
rubocop-rspec
7272
safe_yaml
7373

7474
BUNDLED WITH
75-
1.16.0
75+
1.16.1

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ docs: image
1313
--user root \
1414
--workdir /usr/src/app \
1515
--volume $(PWD):/usr/src/app \
16-
$(IMAGE_NAME) sh -c "apk --update add git && bundle exec rake docs:scrape"
16+
$(IMAGE_NAME) sh -c "apk --update add git && bundle install --with=test && bundle exec rake docs:scrape"

config/contents/layout/indent_array.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ more than the start of the line where the opening square bracket is.
1414
This default style is called 'special_inside_parentheses'. Alternative
1515
styles are 'consistent' and 'align_brackets'. Here are examples:
1616

17-
### Example: EnforcedStyle: special_inside_parentheses
17+
### Example: EnforcedStyle: special_inside_parentheses (default)
1818
# The `special_inside_parentheses` style enforces that the first
1919
# element in an array literal where the opening bracket and first
2020
# element are on seprate lines is indented one step (two spaces) more

config/contents/lint/uri_escape_unescape.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ depending on your specific use case.
1212

1313
# good
1414
CGI.escape('http://example.com')
15-
URI.encode_www_form('http://example.com')
15+
URI.encode_www_form([['example', 'param'], ['lang', 'en']])
16+
URI.encode_www_form(page: 10, locale: 'en')
1617
URI.encode_www_form_component('http://example.com')
1718

1819
# bad

config/contents/rails/date.md

+17-9
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,26 @@ and 'to_time_in_current_zone' is reported as warning.
1515
When EnforcedStyle is 'flexible' then only 'Date.today' is prohibited
1616
and only 'to_time' is reported as warning.
1717

18-
### Example:
19-
# no offense
20-
Time.zone.today
21-
Time.zone.today - 1.day
22-
23-
# flexible
18+
### Example: EnforcedStyle: strict
19+
# bad
2420
Date.current
2521
Date.yesterday
22+
Date.today
23+
date.to_time
24+
date.to_time_in_current_zone
25+
26+
# good
27+
Time.zone.today
28+
Time.zone.today - 1.day
2629

27-
# always reports offense
30+
### Example: EnforcedStyle: flexible (default)
31+
# bad
2832
Date.today
2933
date.to_time
3034

31-
# reports offense only when style is 'strict'
32-
date.to_time_in_current_zone
35+
# good
36+
Time.zone.today
37+
Time.zone.today - 1.day
38+
Date.current
39+
Date.yesterday
40+
date.to_time_in_current_zone

config/contents/rails/inverse_of.md

+92-2
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,109 @@ because of a scope or the options used. This can result in unnecessary
44
queries in some circumstances. `:inverse_of` must be manually specified
55
for associations to work in both ways, or set to `false` to opt-out.
66

7+
### Example:
8+
# good
9+
class Blog < ApplicationRecord
10+
has_many :posts
11+
end
12+
13+
class Post < ApplicationRecord
14+
belongs_to :blog
15+
end
16+
717
### Example:
818
# bad
919
class Blog < ApplicationRecord
10-
has_many :recent_posts, -> { order(published_at: :desc) }
20+
has_many :posts, -> { order(published_at: :desc) }
21+
end
22+
23+
class Post < ApplicationRecord
24+
belongs_to :blog
1125
end
1226

1327
# good
1428
class Blog < ApplicationRecord
15-
has_many(:recent_posts,
29+
has_many(:posts,
1630
-> { order(published_at: :desc) },
1731
inverse_of: :blog
1832
)
1933
end
2034

35+
class Post < ApplicationRecord
36+
belongs_to :blog
37+
end
38+
39+
# good
40+
class Blog < ApplicationRecord
41+
with_options inverse_of: :blog do
42+
has_many :posts, -> { order(published_at: :desc) }
43+
end
44+
end
45+
46+
class Post < ApplicationRecord
47+
belongs_to :blog
48+
end
49+
50+
### Example:
51+
# bad
52+
class Picture < ApplicationRecord
53+
belongs_to :imageable, polymorphic: true
54+
end
55+
56+
class Employee < ApplicationRecord
57+
has_many :pictures, as: :imageable
58+
end
59+
60+
class Product < ApplicationRecord
61+
has_many :pictures, as: :imageable
62+
end
63+
64+
# good
65+
class Picture < ApplicationRecord
66+
belongs_to :imageable, polymorphic: true
67+
end
68+
69+
class Employee < ApplicationRecord
70+
has_many :pictures, as: :imageable, inverse_of: :imageable
71+
end
72+
73+
class Product < ApplicationRecord
74+
has_many :pictures, as: :imageable, inverse_of: :imageable
75+
end
76+
77+
### Example:
78+
# bad
79+
# However, RuboCop can not detect this pattern...
80+
class Physician < ApplicationRecord
81+
has_many :appointments
82+
has_many :patients, through: :appointments
83+
end
84+
85+
class Appointment < ApplicationRecord
86+
belongs_to :physician
87+
belongs_to :patient
88+
end
89+
90+
class Patient < ApplicationRecord
91+
has_many :appointments
92+
has_many :physicians, through: :appointments
93+
end
94+
95+
# good
96+
class Physician < ApplicationRecord
97+
has_many :appointments
98+
has_many :patients, through: :appointments
99+
end
100+
101+
class Appointment < ApplicationRecord
102+
belongs_to :physician, inverse_of: :appointments
103+
belongs_to :patient, inverse_of: :appointments
104+
end
105+
106+
class Patient < ApplicationRecord
107+
has_many :appointments
108+
has_many :physicians, through: :appointments
109+
end
110+
21111
@see http://guides.rubyonrails.org/association_basics.html#bi-directional-associations
22112
@see http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

config/contents/rails/redundant_receiver_in_with_options.md

+28
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,32 @@ Receiver is implicit from Rails 4.2 or higher.
2020
has_many :invoices
2121
has_many :expenses
2222
end
23+
end
24+
25+
### Example:
26+
# bad
27+
with_options options: false do |merger|
28+
merger.invoke(merger.something)
29+
end
30+
31+
# good
32+
with_options options: false do
33+
invoke(something)
34+
end
35+
36+
# good
37+
client = Client.new
38+
with_options options: false do |merger|
39+
client.invoke(merger.something, something)
40+
end
41+
42+
# ok
43+
# When `with_options` includes a block, all scoping scenarios
44+
# cannot be evaluated. Thus, it is ok to include the explicit
45+
# receiver.
46+
with_options options: false do |merger|
47+
merger.invoke
48+
with_another_method do |another_receiver|
49+
merger.invoke(another_receiver)
50+
end
2351
end

config/contents/rails/request_referer.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
This cop checks for consistent uses of `request.referer` or
22
`request.referrer`, depending on the cop's configuration.
33

4-
### Example:
5-
# EnforcedStyle: referer
4+
### Example: EnforcedStyle: referer (default)
65
# bad
76
request.referrer
87

98
# good
109
request.referer
1110

12-
# EnforcedStyle: referrer
11+
### Example: EnforcedStyle: referrer
1312
# bad
1413
request.referer
1514

config/contents/style/format_string_token.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
Use a consistent style for named format string tokens.
22

3+
**Note:**
4+
`unannotated` style cop only works for strings
5+
which are passed as arguments to those methods:
6+
`sprintf`, `format`, `%`.
7+
The reason is that *unannotated* format is very similar
8+
to encoded URLs or Date/Time formatting strings.
9+
310
### Example: EnforcedStyle: annotated (default)
411

512
# bad

config/contents/style/frozen_string_literal_comment.md

+47-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,50 @@ This cop is designed to help upgrade to Ruby 3.0. It will add the
22
comment `# frozen_string_literal: true` to the top of files to
33
enable frozen string literals. Frozen string literals may be default
44
in Ruby 3.0. The comment will be added below a shebang and encoding
5-
comment. The frozen string literal comment is only valid in Ruby 2.3+.
5+
comment. The frozen string literal comment is only valid in Ruby 2.3+.
6+
7+
### Example: EnforcedStyle: when_needed (default)
8+
# The `when_needed` style will add the frozen string literal comment
9+
# to files only when the `TargetRubyVersion` is set to 2.3+.
10+
# bad
11+
module Foo
12+
# ...
13+
end
14+
15+
# good
16+
# frozen_string_literal: true
17+
18+
module Foo
19+
# ...
20+
end
21+
22+
### Example: EnforcedStyle: always
23+
# The `always` style will always add the frozen string literal comment
24+
# to a file, regardless of the Ruby version or if `freeze` or `<<` are
25+
# called on a string literal.
26+
# bad
27+
module Bar
28+
# ...
29+
end
30+
31+
# good
32+
# frozen_string_literal: true
33+
34+
module Bar
35+
# ...
36+
end
37+
38+
### Example: EnforcedStyle: never
39+
# The `never` will enforce that the frozen string literal comment does
40+
# not exist in a file.
41+
# bad
42+
# frozen_string_literal: true
43+
44+
module Baz
45+
# ...
46+
end
47+
48+
# good
49+
module Baz
50+
# ...
51+
end
+15-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
Checks for if and unless statements that would fit on one line
22
if written as a modifier if/unless. The maximum line length is
3-
configured in the `Metrics/LineLength` cop.
3+
configured in the `Metrics/LineLength` cop.
4+
5+
### Example:
6+
# bad
7+
if condition
8+
do_stuff(bar)
9+
end
10+
11+
unless qux.empty?
12+
Foo.do_something
13+
end
14+
15+
# good
16+
do_stuff(bar) if condition
17+
Foo.do_something unless qux.empty?

0 commit comments

Comments
 (0)