Skip to content

Commit 794d3ea

Browse files
authored
Update rubocop to 1.22.2 (#302)
- Update tests as well. - Update docs, including formatting for new safety sections. - Make rubocop pass on docs.rake. [Fixes #301]
1 parent 676e368 commit 794d3ea

File tree

92 files changed

+934
-231
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+934
-231
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", "1.20.0", require: false
9+
gem "rubocop", "1.22.2", require: false
1010
gem "rubocop-i18n", require: false
1111
gem "rubocop-graphql", require: false
1212
gem "rubocop-minitest", require: false

Gemfile.lock

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
activesupport (6.1.4)
4+
activesupport (6.1.4.1)
55
concurrent-ruby (~> 1.0, >= 1.0.2)
66
i18n (>= 1.6, < 2)
77
minitest (>= 5.1)
@@ -17,15 +17,15 @@ GEM
1717
minitest (5.14.4)
1818
mry (0.78.0.0)
1919
rubocop (>= 0.41.0)
20-
parallel (1.20.1)
20+
parallel (1.21.0)
2121
parser (3.0.2.0)
2222
ast (~> 2.4.1)
2323
pry (0.14.1)
2424
coderay (~> 1.1)
2525
method_source (~> 1.0)
2626
rack (2.2.3)
2727
rainbow (3.0.0)
28-
rake (13.0.4)
28+
rake (13.0.6)
2929
regexp_parser (2.1.1)
3030
rexml (3.2.5)
3131
rspec (3.10.0)
@@ -41,48 +41,47 @@ GEM
4141
diff-lcs (>= 1.2.0, < 2.0)
4242
rspec-support (~> 3.10.0)
4343
rspec-support (3.10.2)
44-
rubocop (1.20.0)
44+
rubocop (1.22.2)
4545
parallel (~> 1.10)
4646
parser (>= 3.0.0.0)
4747
rainbow (>= 2.2.2, < 4.0)
4848
regexp_parser (>= 1.8, < 3.0)
4949
rexml
50-
rubocop-ast (>= 1.9.1, < 2.0)
50+
rubocop-ast (>= 1.12.0, < 2.0)
5151
ruby-progressbar (~> 1.7)
5252
unicode-display_width (>= 1.4.0, < 3.0)
53-
rubocop-ast (1.11.0)
53+
rubocop-ast (1.12.0)
5454
parser (>= 3.0.1.1)
55-
rubocop-graphql (0.9.0)
55+
rubocop-graphql (0.10.2)
5656
rubocop (>= 0.87, < 2)
5757
rubocop-i18n (3.0.0)
5858
rubocop (~> 1.0)
59-
rubocop-minitest (0.14.0)
59+
rubocop-minitest (0.15.2)
6060
rubocop (>= 0.90, < 2.0)
61-
rubocop-performance (1.11.3)
61+
rubocop-performance (1.12.0)
6262
rubocop (>= 1.7.0, < 2.0)
6363
rubocop-ast (>= 0.4.0)
64-
rubocop-rails (2.11.2)
64+
rubocop-rails (2.12.4)
6565
activesupport (>= 4.2.0)
6666
rack (>= 1.1)
6767
rubocop (>= 1.7.0, < 2.0)
6868
rubocop-rake (0.6.0)
6969
rubocop (~> 1.0)
70-
rubocop-rspec (2.4.0)
71-
rubocop (~> 1.0)
72-
rubocop-ast (>= 1.1.0)
73-
rubocop-sequel (0.2.0)
70+
rubocop-rspec (2.5.0)
71+
rubocop (~> 1.19)
72+
rubocop-sequel (0.3.3)
7473
rubocop (~> 1.0)
7574
rubocop-sorbet (0.6.2)
7675
rubocop
77-
rubocop-thread_safety (0.4.2)
76+
rubocop-thread_safety (0.4.4)
7877
rubocop (>= 0.53.0)
7978
ruby-progressbar (1.11.0)
8079
safe_yaml (1.0.5)
81-
test-prof (1.0.6)
80+
test-prof (1.0.7)
8281
tzinfo (2.0.4)
8382
concurrent-ruby (~> 1.0)
84-
unicode-display_width (2.0.0)
85-
zeitwerk (2.4.2)
83+
unicode-display_width (2.1.0)
84+
zeitwerk (2.5.1)
8685

8786
PLATFORMS
8887
ruby
@@ -94,7 +93,7 @@ DEPENDENCIES
9493
pry
9594
rake
9695
rspec
97-
rubocop (= 1.20.0)
96+
rubocop (= 1.22.2)
9897
rubocop-graphql
9998
rubocop-i18n
10099
rubocop-minitest
Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
The symbol argument `:gemcutter`, `:rubygems`, and `:rubyforge`
2-
are deprecated. So please change your source to URL string that
3-
'https://rubygems.org' if possible, or 'http://rubygems.org' if not.
1+
Passing symbol arguments to `source` (e.g. `source :rubygems`) is
2+
deprecated because they default to using HTTP requests. Instead, specify
3+
`'https://rubygems.org'` if possible, or `'http://rubygems.org'` if not.
44

5-
This autocorrect will replace these symbols with 'https://rubygems.org'.
6-
Because it is secure, HTTPS request is strongly recommended. And in
7-
most use cases HTTPS will be fine.
5+
When autocorrecting, this cop will replace symbol arguments with
6+
`'https://rubygems.org'`.
87

9-
However, it don't replace all `sources` of `http://` with `https://`.
10-
For example, when specifying an internal gem server using HTTP on the
11-
intranet, a use case where HTTPS cannot be specified was considered.
12-
Consider using HTTP only if you cannot use HTTPS.
8+
This cop will not replace existing sources that use `http://`. This may
9+
be necessary where HTTPS is not available. For example, where using an
10+
internal gem server via an intranet, or where HTTPS is prohibited.
11+
However, you should strongly prefer `https://` where possible, as it is
12+
more secure.
13+
14+
If you don't allow `http://`, please set `false` to `AllowHttpProtocol`.
15+
This option is `true` by default for safe autocorrection.
1316

1417
### Example:
1518
# bad
@@ -19,4 +22,13 @@ Consider using HTTP only if you cannot use HTTPS.
1922

2023
# good
2124
source 'https://rubygems.org' # strongly recommended
22-
source 'http://rubygems.org'
25+
26+
### Example: AllowHttpProtocol: true (default)
27+
28+
# good
29+
source 'http://rubygems.org' # use only if HTTPS is unavailable
30+
31+
### Example: AllowHttpProtocol: false
32+
33+
# bad
34+
source 'http://rubygems.org'

config/contents/gemspec/required_ruby_version.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
Checks that `required_ruby_version` of gemspec is specified and
2-
equal to `TargetRubyVersion` of .rubocop.yml.
3-
Thereby, RuboCop to perform static analysis working on the version
4-
required by gemspec.
1+
Checks that `required_ruby_version` in a gemspec file is set to a valid
2+
value (non-blank) and matches `TargetRubyVersion` as set in RuboCop's
3+
configuration for the gem.
4+
5+
This ensures that RuboCop is using the same Ruby version as the gem.
56

67
### Example:
78
# When `TargetRubyVersion` of .rubocop.yml is `2.5`.
@@ -21,6 +22,11 @@ required by gemspec.
2122
spec.required_ruby_version = '>= 2.6.0'
2223
end
2324

25+
# bad
26+
Gem::Specification.new do |spec|
27+
spec.required_ruby_version = ''
28+
end
29+
2430
# good
2531
Gem::Specification.new do |spec|
2632
spec.required_ruby_version = '>= 2.5.0'
@@ -37,7 +43,7 @@ required by gemspec.
3743
end
3844

3945
# accepted but not recommended, since
40-
# Ruby does not really follow semantic versionning
46+
# Ruby does not really follow semantic versioning
4147
Gem::Specification.new do |spec|
4248
spec.required_ruby_version = '~> 2.5'
4349
end

config/contents/layout/class_structure.md

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,49 +19,47 @@ Consider an example of code style that covers the following order:
1919

2020
You can configure the following order:
2121

22-
[source,yaml]
23-
----
22+
```yaml
2423
Layout/ClassStructure:
25-
ExpectedOrder:
26-
- module_inclusion
27-
- constants
28-
- association
29-
- public_attribute_macros
30-
- public_delegate
31-
- macros
32-
- public_class_methods
33-
- initializer
34-
- public_methods
35-
- protected_attribute_macros
36-
- protected_methods
37-
- private_attribute_macros
38-
- private_delegate
39-
- private_methods
40-
----
24+
ExpectedOrder:
25+
- module_inclusion
26+
- constants
27+
- association
28+
- public_attribute_macros
29+
- public_delegate
30+
- macros
31+
- public_class_methods
32+
- initializer
33+
- public_methods
34+
- protected_attribute_macros
35+
- protected_methods
36+
- private_attribute_macros
37+
- private_delegate
38+
- private_methods
39+
```
4140
4241
Instead of putting all literals in the expected order, is also
4342
possible to group categories of macros. Visibility levels are handled
4443
automatically.
4544
46-
[source,yaml]
47-
----
45+
```yaml
4846
Layout/ClassStructure:
49-
Categories:
50-
association:
51-
- has_many
52-
- has_one
53-
attribute_macros:
54-
- attr_accessor
55-
- attr_reader
56-
- attr_writer
57-
macros:
58-
- validates
59-
- validate
60-
module_inclusion:
61-
- include
62-
- prepend
63-
- extend
64-
----
47+
Categories:
48+
association:
49+
- has_many
50+
- has_one
51+
attribute_macros:
52+
- attr_accessor
53+
- attr_reader
54+
- attr_writer
55+
macros:
56+
- validates
57+
- validate
58+
module_inclusion:
59+
- include
60+
- prepend
61+
- extend
62+
```
6563
6664
### Example:
6765
# bad

config/contents/layout/space_inside_parens.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,24 @@ Checks for spaces inside ordinary round parentheses.
2727
f( 3 )
2828
g = ( a + 3 )
2929
y()
30+
31+
### Example: EnforcedStyle: compact
32+
# The `compact` style enforces that parentheses have a space at the
33+
# beginning with the exception that successive parentheses are allowed.
34+
# Note: Empty parentheses should not have spaces.
35+
36+
# bad
37+
f(3)
38+
g = (a + 3)
39+
y( )
40+
g( f( x ) )
41+
g( f( x( 3 ) ), 5 )
42+
g( ( ( 3 + 5 ) * f) ** x, 5 )
43+
44+
# good
45+
f( 3 )
46+
g = ( a + 3 )
47+
y()
48+
g( f( x ))
49+
g( f( x( 3 )), 5 )
50+
g((( 3 + 5 ) * f ) ** x, 5 )
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This cop looks for expressions containing multiple binary operators
2+
where precedence is ambiguous due to lack of parentheses. For example,
3+
in `1 + 2 * 3`, the multiplication will happen before the addition, but
4+
lexically it appears that the addition will happen first.
5+
6+
The cop does not consider unary operators (ie. `!a` or `-b`) or comparison
7+
operators (ie. `a =~ b`) because those are not ambiguous.
8+
9+
NOTE: Ranges are handled by `Lint/AmbiguousRange`.
10+
11+
### Example:
12+
# bad
13+
a + b * c
14+
a || b && c
15+
a ** b + c
16+
17+
# good (different precedence)
18+
a + (b * c)
19+
a || (b && c)
20+
(a ** b) + c
21+
22+
# good (same precedence)
23+
a + b + c
24+
a * b / c % d

config/contents/lint/ambiguous_range.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@ using a range with other operators. This cop avoids that by making ranges
55
explicit by requiring parenthesis around complex range boundaries (anything
66
that is not a basic literal: numerics, strings, symbols, etc.).
77

8-
NOTE: The cop auto-corrects by wrapping the entire boundary in parentheses, which
9-
makes the outcome more explicit but is possible to not be the intention of the
10-
programmer. For this reason, this cop's auto-correct is marked as unsafe (it
11-
will not change the behaviour of the code, but will not necessarily match the
12-
intent of the program).
13-
148
This cop can be configured with `RequireParenthesesForMethodChains` in order to
159
specify whether method chains (including `self.foo`) should be wrapped in parens
1610
by this cop.
1711

1812
NOTE: Regardless of this configuration, if a method receiver is a basic literal
1913
value, it will be wrapped in order to prevent the ambiguity of `1..2.to_a`.
2014

15+
### Safety:
16+
17+
The cop auto-corrects by wrapping the entire boundary in parentheses, which
18+
makes the outcome more explicit but is possible to not be the intention of the
19+
programmer. For this reason, this cop's auto-correct is unsafe (it will not
20+
change the behaviour of the code, but will not necessarily match the
21+
intent of the program).
22+
2123
### Example:
2224
# bad
2325
x || 1..2
@@ -49,4 +51,4 @@ value, it will be wrapped in order to prevent the ambiguity of `1..2.to_a`.
4951
a.foo..b.bar
5052

5153
# good
52-
(a.foo)..(b.bar)
54+
(a.foo)..(b.bar)

config/contents/lint/binary_operator_with_identical_operands.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
This cop checks for places where binary operator has identical operands.
22

3-
It covers arithmetic operators: `+`, `-`, `*`, `/`, `%`, `**`;
3+
It covers arithmetic operators: `-`, `/`, `%`;
44
comparison operators: `==`, `===`, `=~`, `>`, `>=`, `<`, `<=`;
5-
bitwise operators: `|`, `^`, `&`, `<<`, `>>`;
5+
bitwise operators: `|`, `^`, `&`;
66
boolean operators: `&&`, `||`
77
and "spaceship" operator - `<=>`.
88

9-
This cop is marked as unsafe as it does not consider side effects when calling methods
10-
and thus can generate false positives:
11-
if wr.take_char == '\0' && wr.take_char == '\0'
9+
Simple arithmetic operations are allowed by this cop: `+`, `*`, `**`, `<<` and `>>`.
10+
Although these can be rewritten in a different way, it should not be necessary to
11+
do so. This does not include operations such as `-` or `/` where the result will
12+
always be the same (`x - x` will always be 0; `x / x` will always be 1), and
13+
thus are legitimate offenses.
14+
15+
### Safety:
16+
17+
This cop is unsafe as it does not consider side effects when calling methods
18+
and thus can generate false positives, for example:
19+
20+
```ruby
21+
if wr.take_char == '\0' && wr.take_char == '\0'
22+
# ...
23+
end
24+
```
1225

1326
### Example:
1427
# bad
@@ -19,7 +32,7 @@ and thus can generate false positives:
1932
do_something
2033
end
2134

22-
def childs?
35+
def child?
2336
left_child || left_child
2437
end
2538

0 commit comments

Comments
 (0)