Skip to content

Commit 21115dd

Browse files
committed
Rescrape docs, update spec exclusion list
1 parent 72445ff commit 21115dd

File tree

201 files changed

+1717
-293
lines changed

Some content is hidden

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

201 files changed

+1717
-293
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This cop checks for assignments in the conditions of
2+
if/while/until.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
11
This cop checks whether the end keywords are aligned properly for do
22
end blocks.
33

4+
Three modes are supported through the `AlignWith` configuration
5+
parameter:
6+
7+
`start_of_block` : the `end` shall be aligned with the
8+
start of the line where the `do` appeared.
9+
10+
`start_of_line` : the `end` shall be aligned with the
11+
start of the line where the expression started.
12+
13+
`either` (which is the default) : the `end` is allowed to be in either
14+
location. The autofixer will default to `start_of_line`.
15+
416
### Example:
517

18+
# either
619
variable = lambda do |i|
720
i
21+
end
22+
23+
# start_of_block
24+
foo.bar
25+
.each do
26+
baz
27+
end
28+
29+
# start_of_line
30+
foo.bar
31+
.each do
32+
baz
833
end

config/contents/lint/debugger.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This cop checks for calls to debugger or pry.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This cop checks for uses of the deprecated class method usages.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
This cop checks that there are no repeated conditions
2+
used in case 'when' expressions.
3+
4+
### Example:
5+
6+
# bad
7+
case x
8+
when 'first'
9+
do_something
10+
when 'first'
11+
do_something_else
12+
end

config/contents/lint/empty_ensure.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This cop checks for empty `ensure` blocks
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
This cop checks for the presence of empty expressions.
2+
3+
### Example:
4+
5+
# bad
6+
foo = ()
7+
if ()
8+
bar
9+
end

config/contents/lint/empty_when.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
This cop checks for the presence of `when` branches without a body.
2+
3+
### Example:
4+
5+
# bad
6+
case foo
7+
when bar then 1
8+
when baz then # nothing
9+
end

config/contents/lint/end_in_method.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This cop checks for END blocks in method definitions.

config/contents/lint/ensure_return.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This cop checks for *return* from an *ensure* block.

config/contents/lint/eval.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This cop checks for the use of *Kernel#eval*.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This cop checks for *rescue* blocks with no body.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
This cop looks for error classes inheriting from `Exception`
2+
and its standard library subclasses, excluding subclasses of
3+
`StandardError`. It is configurable to suggest using either
4+
`RuntimeError` (default) or `StandardError` instead.
5+
6+
### Example:
7+
8+
# bad
9+
10+
class C < Exception; end
11+
12+
### Example:
13+
14+
# EnforcedStyle: runtime_error (default)
15+
16+
# good
17+
18+
class C < RuntimeError; end
19+
20+
### Example:
21+
22+
# EnforcedStyle: standard_error
23+
24+
# good
25+
26+
class C < StandardError; end

config/contents/lint/loop.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This cop checks for uses of *begin...end while/until something*.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This cop checks for quotes and commas in %w, e.g.
2+
3+
`%w('foo', "bar")`
4+
5+
it is more likely that the additional characters are unintended (for
6+
example, mistranslating an array of literals to percent string notation)
7+
rather than meant to be part of the resulting strings.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This cop checks for colons and commas in %i, e.g.
2+
3+
`%i(:foo, :bar)`
4+
5+
it is more likely that the additional characters are unintended (for
6+
example, mistranslating an array of literals to percent string notation)
7+
rather than meant to be part of the resulting symbols.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This cop checks for *rescue* blocks targeting the Exception class.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
This cop checks for a rescued exception that get shadowed by a
2+
less specific exception being rescued before a more specific
3+
exception is rescued.
4+
5+
### Example:
6+
# bad
7+
begin
8+
something
9+
rescue Exception
10+
handle_exception
11+
rescue StandardError
12+
handle_standard_error
13+
end
14+
15+
# good
16+
begin
17+
something
18+
rescue StandardError
19+
handle_standard_error
20+
rescue Exception
21+
handle_exception
22+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This cop looks for use of the same name as outer local variables
2+
for block arguments or block local variables.
3+
This is a mimic of the warning
4+
"shadowing outer local variable - foo" from `ruby -cw`.

config/contents/lint/syntax.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This is actually not a cop and inspects nothing. It just provides
2+
methods to repack Parser's diagnostics/errors into RuboCop's offenses.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This cop checks for underscore-prefixed variables that are actually
2+
used.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
This cop checks for using Fixnum or Bignum constant.
2+
3+
### Example:
4+
# bad
5+
1.is_a?(Fixnum)
6+
1.is_a?(Bignum)
7+
8+
# good
9+
1.is_a?(Integer)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
This cop detects instances of rubocop:disable comments that can be
2+
removed without causing any offenses to be reported. It's implemented
3+
as a cop in that it inherits from the Cop base class and calls
4+
add_offense. The unusual part of its implementation is that it doesn't
5+
have any on_* methods or an investigate method. This means that it
6+
doesn't take part in the investigation phase when the other cops do
7+
their work. Instead, it waits until it's called in a later stage of the
8+
execution. The reason it can't be implemented as a normal cop is that
9+
it depends on the results of all other cops to do its work.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
This cop checks for unneeded usages of splat expansion
2+
3+
### Example:
4+
# bad
5+
a = *[1, 2, 3]
6+
a = *'a'
7+
a = *1
8+
9+
begin
10+
foo
11+
rescue *[StandardError, ApplicationError]
12+
bar
13+
end
14+
15+
case foo
16+
when *[1, 2, 3]
17+
bar
18+
else
19+
baz
20+
end
21+
22+
# good
23+
c = [1, 2, 3]
24+
a = *c
25+
a, b = *c
26+
a, *b = *c
27+
a = *1..10
28+
a = ['a']
29+
30+
begin
31+
foo
32+
rescue StandardError, ApplicationError
33+
bar
34+
end
35+
36+
case foo
37+
when *[1, 2, 3]
38+
bar
39+
else
40+
baz
41+
end
Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
This cop checks for code that will never run, because it follows a flow control
2-
statement such as `return` or `raise`.
3-
4-
### Example:
5-
6-
# bad
7-
def sad
8-
raise RuntimeError
9-
10-
puts "This line will never be reached, so why even include it?"
11-
end
12-
13-
# good
14-
def happy
15-
raise RuntimeError if problem?
16-
17-
puts "This line of code will sometimes be reached"
18-
end
1+
This cop checks for unreachable code.
2+
The check are based on the presence of flow of control
3+
statement in non-final position in *begin*(implicit) blocks.

config/contents/lint/unused_block_argument.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@ This cop checks for unused block arguments.
22

33
### Example:
44

5-
do_something do |used, unused, _unused_but_allowed|
5+
#good
6+
7+
do_something do |used, unused|
8+
puts used
9+
end
10+
11+
do_something do
12+
puts :foo
13+
end
14+
15+
define_method(:foo) do |_bar|
16+
puts :baz
17+
end
18+
19+
# bad
20+
21+
do_something do |used, _unused|
622
puts used
23+
end
24+
25+
do_something do |bar|
26+
puts :foo
27+
end
28+
29+
define_method(:foo) do |bar|
30+
puts :baz
731
end
Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,75 @@
1-
This cop checks for redundant access modifiers, including those with
2-
no code, those which are repeated, and leading `public` modifiers in
3-
a class or module body.
1+
This cop checks for redundant access modifiers, including those with no
2+
code, those which are repeated, and leading `public` modifiers in a
3+
class or module body. Conditionally-defined methods are considered as
4+
always being defined, and thus access modifiers guarding such methods
5+
are not redundant.
46

57
### Example:
68

79
class Foo
8-
public # this is redundant
10+
public # this is redundant (default access is public)
911

1012
def method
1113
end
1214

13-
private # this is not redundant
15+
private # this is not redundant (a method is defined)
1416
def method2
1517
end
1618

17-
private # this is redundant
19+
private # this is redundant (no following methods are defined)
20+
end
21+
22+
### Example:
23+
24+
class Foo
25+
# The following is not redundant (conditionally defined methods are
26+
# considered as always defining a method)
27+
private
28+
29+
if condition?
30+
def method
31+
end
32+
end
33+
34+
protected # this is not redundant (method is defined)
35+
36+
define_method(:method2) do
37+
end
38+
39+
protected # this is redundant (repeated from previous modifier)
40+
41+
[1,2,3].each do |i|
42+
define_method("foo#{i}") do
43+
end
44+
end
45+
46+
# The following is redundant (methods defined on the class'
47+
# singleton class are not affected by the public modifier)
48+
public
49+
50+
def self.method3
51+
end
52+
end
53+
54+
### Example:
55+
# Lint/UselessAccessModifier:
56+
# ContextCreatingMethods:
57+
# - concerning
58+
require 'active_support/concern'
59+
class Foo
60+
concerning :Bar do
61+
def some_public_method
62+
end
63+
64+
private
65+
66+
def some_private_method
67+
end
68+
end
69+
70+
# this is not redundant because `concerning` created its own context
71+
private
72+
73+
def some_other_private_method
74+
end
1875
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
This cop checks for every useless assignment to local variable in every
2+
scope.
3+
The basic idea for this cop was from the warning of `ruby -cw`:
4+
5+
assigned but unused variable - foo
6+
7+
Currently this cop has advanced logic that detects unreferenced
8+
reassignments and properly handles varied cases such as branch, loop,
9+
rescue, ensure, etc.

0 commit comments

Comments
 (0)